Skip to content

Commit

Permalink
feat: migrate ethers from v5 to v6 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiendan authored Jan 9, 2024
1 parent 40e2772 commit 91170ad
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 61 deletions.
163 changes: 157 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"@opentelemetry/exporter-trace-otlp-proto": "^0.45.0",
"@opentelemetry/sdk-metrics": "^1.17.1",
"@opentelemetry/sdk-trace-web": "^1.17.1",
"@topos-protocol/topos-smart-contracts": "^2.0.0",
"@topos-protocol/topos-smart-contracts": "^3.1.0",
"antd": "^5.4.0",
"axios": "^1.4.0",
"ethers": "^5.7.2",
"ethers": "^6.9.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-google-recaptcha": "^3.1.0",
Expand Down
17 changes: 9 additions & 8 deletions packages/frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ThemeProvider } from '@emotion/react'
import styled from '@emotion/styled'
import { ToposCore__factory } from '@topos-protocol/topos-smart-contracts/typechain-types/factories/contracts/topos-core/ToposCore__factory'
import { Alert, Layout as AntdLayout } from 'antd'
import { getDefaultProvider } from 'ethers'
import { useEffect, useState } from 'react'

import { ErrorsContext } from './contexts/errors'
Expand All @@ -13,9 +15,7 @@ import FaucetForm from './components/FaucetForm'
import Content from './components/Content'
import { SubnetWithId } from './types'
import useRegisteredSubnets from './hooks/useRegisteredSubnets'
import { BigNumber, ethers } from 'ethers'
import { SubnetsContext } from './contexts/subnets'
import { toposCoreContract } from './contracts'
import { SuccessesContext } from './contexts/successes'

const Errors = styled.div`
Expand Down Expand Up @@ -54,17 +54,18 @@ const App = () => {
let toposSubnet: SubnetWithId | undefined

if (toposSubnetEndpointHttp && toposSubnetEndpointWs) {
const provider = new ethers.providers.JsonRpcProvider(
toposSubnetEndpointHttp
)
const provider = getDefaultProvider(toposSubnetEndpointHttp)
const network = await provider.getNetwork()
const chainId = network.chainId

const contract = toposCoreContract.connect(provider)
const subnetId = await contract.networkSubnetId()
const toposCore = ToposCore__factory.connect(
import.meta.env.VITE_TOPOS_CORE_PROXY_CONTRACT_ADDRESS,
provider
)
const subnetId = await toposCore.networkSubnetId()

toposSubnet = {
chainId: BigNumber.from(chainId.toString()),
chainId: BigInt(chainId.toString()),
endpointHttp: toposSubnetEndpointHttp,
endpointWs: toposSubnetEndpointWs,
currencySymbol: 'TOPOS',
Expand Down
3 changes: 1 addition & 2 deletions packages/frontend/src/components/SubnetSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { describe, it, expect, vi } from 'vitest'

import SubnetSelect from './SubnetSelect'
import { SubnetWithId } from '../types'
import { BigNumber } from 'ethers'
import { userEvent } from '../utils/tests'

const subnetsMock: SubnetWithId[] = [
{
chainId: BigNumber.from(1),
chainId: BigInt(1),
currencySymbol: 'TST',
endpointHttp: '',
endpointWs: '',
Expand Down
17 changes: 0 additions & 17 deletions packages/frontend/src/contracts.ts

This file was deleted.

15 changes: 7 additions & 8 deletions packages/frontend/src/hooks/useRegisteredSubnets.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { SubnetRegistrator__factory } from '@topos-protocol/topos-smart-contracts/typechain-types/factories/contracts/topos-core/SubnetRegistrator__factory'
import { renderHook, waitFor } from '@testing-library/react'
import { BigNumber } from 'ethers'
import { vi } from 'vitest'

import useRegisteredSubnets from './useRegisteredSubnets'
import * as contractExports from '../contracts'
import { Subnet } from '../types'

const registeredSubnets: { [x: string]: Subnet } = {
subnet1: {
chainId: BigNumber.from(1),
chainId: BigInt(1),
currencySymbol: 'TST',
endpointHttp: '',
endpointWs: '',
logoURL: '',
name: 'subnetMock',
},
subnet2: {
chainId: BigNumber.from(2),
chainId: BigInt(2),
currencySymbol: 'TST2',
endpointHttp: '',
endpointWs: '',
Expand All @@ -34,7 +33,7 @@ const expectedSubnets = subnetIdsByIndexes.map((id) => ({

const getSubnetCountMock = vi
.fn()
.mockResolvedValue(BigNumber.from(subnetIdsByIndexes.length))
.mockResolvedValue(BigInt(subnetIdsByIndexes.length))

const getSubnetIdAtIndexMock = vi
.fn()
Expand All @@ -54,9 +53,9 @@ const contractConnectMock = vi.fn().mockReturnValue({
subnets: subnetsMock,
})

vi.spyOn(contractExports, 'subnetRegistratorContract', 'get').mockReturnValue({
connect: contractConnectMock,
} as any)
vi.spyOn(SubnetRegistrator__factory, 'connect').mockReturnValue(
contractConnectMock
)

vi.mock('./useEthers', () => ({
default: vi.fn().mockReturnValue({ provider: {} }),
Expand Down
Loading

0 comments on commit 91170ad

Please sign in to comment.