-
Notifications
You must be signed in to change notification settings - Fork 5.4k
chore: migrate testnet network MegaETH Testnet v1 to MegaETH Testnet v2 #38426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
84e1a9e
fa7901e
85bd0d9
c8affad
7961d94
0629091
c486923
1d49b92
150c484
3e0c461
3f58c56
b5a7cda
ecb75d9
2c27bf7
50d3631
ae2d694
ad052a5
3f7d139
24cd17c
fcd43df
433e702
58d9591
ad738ec
9d051fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,10 +28,7 @@ import { | |
| NetworkControllerMessenger, | ||
| } from './messengers'; | ||
|
|
||
| export const ADDITIONAL_DEFAULT_NETWORKS = [ | ||
| ChainId['megaeth-testnet'], | ||
| ChainId['monad-testnet'], | ||
| ]; | ||
| export const ADDITIONAL_DEFAULT_NETWORKS = [ChainId['monad-testnet']]; | ||
|
|
||
| function getInitialState(initialState?: Partial<NetworkController['state']>) { | ||
| let initialNetworkControllerState = initialState; | ||
|
|
@@ -44,6 +41,25 @@ function getInitialState(initialState?: Partial<NetworkController['state']>) { | |
| const networks = | ||
| initialNetworkControllerState.networkConfigurationsByChainId ?? {}; | ||
|
|
||
| // TODO: Remove this once the MegaETH Testnet v2 is released from the controller utils | ||
| networks['0x18c7'] = { | ||
| chainId: '0x18c7', // 6343 | ||
| name: 'MegaETH Testnet', | ||
| nativeCurrency: 'MegaETH', | ||
| blockExplorerUrls: ['https://megaeth-testnet-v2.blockscout.com'], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Isn't this information already available in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call, but this is for temp and removed soon once network controller bump up, i think we can keep it like that if u dont mind? |
||
| defaultRpcEndpointIndex: 0, | ||
| defaultBlockExplorerUrlIndex: 0, | ||
| rpcEndpoints: [ | ||
| { | ||
| // to align the same networkClientId from the controller utils | ||
| networkClientId: 'megaeth-testnet-v2', | ||
| url: 'https://timothy.megaeth.com/rpc', | ||
| type: RpcEndpointType.Custom, | ||
| failoverUrls: [], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| // TODO: Consider changing `getDefaultNetworkControllerState` on the | ||
| // controller side to include some of these tweaks. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,287 @@ | ||
| import { RpcEndpointType } from '@metamask/network-controller'; | ||
| import { cloneDeep } from 'lodash'; | ||
| import { jest } from '@jest/globals'; | ||
| import { KnownCaipNamespace } from '@metamask/utils'; | ||
| import { | ||
| migrate, | ||
| version, | ||
| MEGAETH_TESTNET_V2_CONFIG, | ||
| MEGAETH_TESTNET_V1_CHAIN_ID, | ||
| type VersionedData, | ||
| } from './184'; | ||
|
|
||
| const VERSION = version; | ||
| const oldVersion = VERSION - 1; | ||
|
|
||
| describe(`migration #${VERSION}`, () => { | ||
| let mockedCaptureException: jest.Mock; | ||
| beforeEach(() => { | ||
| mockedCaptureException = jest.fn(); | ||
| global.sentry = { captureException: mockedCaptureException }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| global.sentry = undefined; | ||
| }); | ||
|
|
||
| it('updates the version metadata', async () => { | ||
| const oldStorage = { | ||
| meta: { version: oldVersion }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: {}, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const newStorage = await migrate(oldStorage); | ||
|
|
||
| expect(newStorage.meta).toStrictEqual({ version: VERSION }); | ||
| }); | ||
|
|
||
| const invalidStates = [ | ||
| { | ||
| state: { | ||
| meta: { version: VERSION }, | ||
| data: {}, | ||
| }, | ||
| scenario: 'NetworkController not found', | ||
| }, | ||
| { | ||
| state: { | ||
| meta: { version: VERSION }, | ||
| data: { | ||
| NetworkController: 'invalid', | ||
| }, | ||
| }, | ||
| scenario: 'invalid NetworkController state', | ||
| }, | ||
| { | ||
| state: { | ||
| meta: { version: VERSION }, | ||
| data: { | ||
| NetworkController: {}, | ||
| }, | ||
| }, | ||
| scenario: 'missing networkConfigurationsByChainId property', | ||
| }, | ||
| { | ||
| state: { | ||
| meta: { version: VERSION }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: 'invalid', | ||
| }, | ||
| }, | ||
| }, | ||
| scenario: 'invalid networkConfigurationsByChainId state', | ||
| }, | ||
| { | ||
| state: { | ||
| meta: { version: VERSION }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: {}, | ||
| selectedNetworkClientId: 'megaeth-testnet', | ||
| }, | ||
| }, | ||
| }, | ||
| scenario: 'missing NetworkEnablementController', | ||
| }, | ||
| { | ||
| state: { | ||
| meta: { version: VERSION }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: {}, | ||
| selectedNetworkClientId: 'megaeth-testnet', | ||
| }, | ||
| NetworkEnablementController: 'invalid', | ||
| }, | ||
| }, | ||
| scenario: 'invalid NetworkEnablementController state', | ||
| }, | ||
| { | ||
| state: { | ||
| meta: { version: VERSION }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: {}, | ||
| selectedNetworkClientId: 'megaeth-testnet', | ||
| }, | ||
| NetworkEnablementController: { | ||
| enabledNetworkMap: 'invalid', | ||
| }, | ||
| }, | ||
| }, | ||
| scenario: 'invalid enabledNetworkMap state', | ||
| }, | ||
| { | ||
| state: { | ||
| meta: { version: VERSION }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: {}, | ||
| selectedNetworkClientId: 'megaeth-testnet', | ||
| }, | ||
| NetworkEnablementController: { | ||
| enabledNetworkMap: {}, | ||
| }, | ||
| }, | ||
| }, | ||
| scenario: 'missing enabledNetworkMap property', | ||
| }, | ||
| { | ||
| state: { | ||
| meta: { version: VERSION }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: {}, | ||
| selectedNetworkClientId: 'megaeth-testnet', | ||
| }, | ||
| NetworkEnablementController: { | ||
| enabledNetworkMap: { | ||
| eip155: 'invalid', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| scenario: 'invalid enabledNetworkMap[eip155] state', | ||
| }, | ||
| ]; | ||
|
|
||
| // @ts-expect-error 'each' function is not recognized by TypeScript types | ||
| it.each(invalidStates)( | ||
| 'should capture exception if $scenario', | ||
| async ({ state }: { errorMessage: string; state: VersionedData }) => { | ||
| const orgState = cloneDeep(state); | ||
|
|
||
| const migratedState = await migrate(state); | ||
|
|
||
| // State should be unchanged | ||
| expect(migratedState).toStrictEqual(orgState); | ||
| expect(mockedCaptureException).toHaveBeenCalledWith(expect.any(Error)); | ||
| }, | ||
| ); | ||
|
|
||
| it('removes the megaeth testnet v1 network configuration and adds the megaeth testnet v2 network configuration', async () => { | ||
| const oldStorage = { | ||
| meta: { version: oldVersion }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: { | ||
| [MEGAETH_TESTNET_V1_CHAIN_ID]: { | ||
| chainId: MEGAETH_TESTNET_V1_CHAIN_ID, | ||
| name: 'Mega Testnet', | ||
| nativeCurrency: 'MegaETH', | ||
| blockExplorerUrls: ['https://explorer.com'], | ||
| defaultRpcEndpointIndex: 0, | ||
| defaultBlockExplorerUrlIndex: 0, | ||
| rpcEndpoints: [ | ||
| { | ||
| networkClientId: 'megaeth-testnet', | ||
| type: RpcEndpointType.Custom, | ||
| url: 'https://rpc.com', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }, | ||
| NetworkEnablementController: { | ||
| enabledNetworkMap: { | ||
| [KnownCaipNamespace.Eip155]: { | ||
| [MEGAETH_TESTNET_V1_CHAIN_ID]: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const expectedStorage = { | ||
| meta: { version: VERSION }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: { | ||
| [MEGAETH_TESTNET_V2_CONFIG.chainId]: MEGAETH_TESTNET_V2_CONFIG, | ||
| }, | ||
| }, | ||
| NetworkEnablementController: { | ||
| enabledNetworkMap: { | ||
| [KnownCaipNamespace.Eip155]: { | ||
| [MEGAETH_TESTNET_V2_CONFIG.chainId]: false, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const newStorage = await migrate(oldStorage); | ||
|
|
||
| expect(newStorage).toStrictEqual(expectedStorage); | ||
| }); | ||
|
|
||
| // @ts-expect-error 'each' function is not recognized by TypeScript types | ||
| it.each(['megaeth-testnet', 'random-network-client-id'])( | ||
| 'switchs to mainnet when the selected network client id is in MegaETH Testnet v1 - %s', | ||
| async (selectedNetworkClientId: string) => { | ||
| const oldStorage = { | ||
| meta: { version: oldVersion }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: { | ||
| [MEGAETH_TESTNET_V1_CHAIN_ID]: { | ||
| chainId: MEGAETH_TESTNET_V1_CHAIN_ID, | ||
| name: 'Mega Testnet', | ||
| nativeCurrency: 'MegaETH', | ||
| blockExplorerUrls: ['https://explorer.com'], | ||
| defaultRpcEndpointIndex: 0, | ||
| defaultBlockExplorerUrlIndex: 0, | ||
| rpcEndpoints: [ | ||
| { | ||
| networkClientId: selectedNetworkClientId, | ||
| type: RpcEndpointType.Custom, | ||
| url: 'https://rpc.com', | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| selectedNetworkClientId, | ||
| }, | ||
| NetworkEnablementController: { | ||
| enabledNetworkMap: { | ||
| [KnownCaipNamespace.Eip155]: { | ||
| [MEGAETH_TESTNET_V1_CHAIN_ID]: false, | ||
| // to simulate the mainnet is not being enabled | ||
| '0x1': false, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const expectedStorage = { | ||
| meta: { version: VERSION }, | ||
| data: { | ||
| NetworkController: { | ||
| networkConfigurationsByChainId: { | ||
| [MEGAETH_TESTNET_V2_CONFIG.chainId]: MEGAETH_TESTNET_V2_CONFIG, | ||
| }, | ||
| selectedNetworkClientId: 'mainnet', | ||
| }, | ||
| NetworkEnablementController: { | ||
| enabledNetworkMap: { | ||
| [KnownCaipNamespace.Eip155]: { | ||
| [MEGAETH_TESTNET_V2_CONFIG.chainId]: false, | ||
| '0x1': true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const newStorage = await migrate(oldStorage); | ||
|
|
||
| expect(newStorage).toStrictEqual(expectedStorage); | ||
| }, | ||
| ); | ||
| }); | ||
stanleyyconsensys marked this conversation as resolved.
Show resolved
Hide resolved
stanleyyconsensys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if someone already has this chain added? Do we need to only add this if the chain is not present? (If the chain is already present, then the migration should take care of fixing it.) Is this something to be concerned about?