-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28973 from MetaMask/Version-v12.8.1
Version v12.8.1 RC
- Loading branch information
Showing
10 changed files
with
1,013 additions
and
422 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
import { cloneDeep } from 'lodash'; | ||
import { NetworkState } from '@metamask/network-controller'; | ||
import { infuraProjectId } from '../../../shared/constants/network'; | ||
import { migrate, version } from './131.1'; | ||
|
||
const oldVersion = 131; | ||
const BASE_CHAIN_ID = '0x2105'; | ||
|
||
describe('migration #131.1', () => { | ||
it('updates the version metadata', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: {}, | ||
}; | ||
|
||
const newStorage = await migrate(cloneDeep(oldStorage)); | ||
|
||
expect(newStorage.meta).toStrictEqual({ version }); | ||
}); | ||
|
||
describe('Base Network Migration', () => { | ||
it('does nothing if networkConfigurationsByChainId is not in state', async () => { | ||
const oldState = { | ||
OtherController: {}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: cloneDeep(oldState), | ||
}); | ||
|
||
expect(transformedState.data).toEqual(oldState); | ||
}); | ||
|
||
it('does nothing if no Infura RPC endpoints are used', async () => { | ||
const oldState = { | ||
NetworkController: { | ||
networkConfigurationsByChainId: { | ||
'0x1': { | ||
rpcEndpoints: [ | ||
{ | ||
url: 'https://custom.rpc', | ||
type: 'custom', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: cloneDeep(oldState), | ||
}); | ||
|
||
expect(transformedState.data).toEqual(oldState); | ||
}); | ||
|
||
it('does nothing if Base network configuration is missing', async () => { | ||
const oldState = { | ||
NetworkController: { | ||
networkConfigurationsByChainId: { | ||
'0x1': { | ||
rpcEndpoints: [ | ||
{ | ||
url: `https://mainnet.infura.io/v3/${infuraProjectId}`, | ||
type: 'infura', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: cloneDeep(oldState), | ||
}); | ||
|
||
expect(transformedState.data).toEqual(oldState); | ||
}); | ||
|
||
it('replaces "https://mainnet.base.org" if the default RPC endpoint is Infura', async () => { | ||
const oldState = { | ||
NetworkController: { | ||
networkConfigurationsByChainId: { | ||
[BASE_CHAIN_ID]: { | ||
rpcEndpoints: [ | ||
{ | ||
url: 'https://mainnet.base.org', | ||
type: 'custom', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
'0x1': { | ||
rpcEndpoints: [ | ||
{ | ||
url: `https://mainnet.infura.io/v3/${infuraProjectId}`, | ||
type: 'infura', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: cloneDeep(oldState), | ||
}); | ||
|
||
const updatedNetworkController = transformedState.data | ||
.NetworkController as NetworkState; | ||
|
||
expect( | ||
updatedNetworkController.networkConfigurationsByChainId[BASE_CHAIN_ID] | ||
.rpcEndpoints[0].url, | ||
).toEqual(`https://base-mainnet.infura.io/v3/${infuraProjectId}`); | ||
}); | ||
|
||
it('does not modify RPC endpoints if the default RPC endpoint is not Infura', async () => { | ||
const oldState = { | ||
NetworkController: { | ||
networkConfigurationsByChainId: { | ||
[BASE_CHAIN_ID]: { | ||
rpcEndpoints: [ | ||
{ | ||
url: 'https://other.rpc', | ||
type: 'custom', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
'0x1': { | ||
rpcEndpoints: [ | ||
{ | ||
url: 'https://custom.rpc', | ||
type: 'custom', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: cloneDeep(oldState), | ||
}); | ||
|
||
const updatedNetworkController = transformedState.data | ||
.NetworkController as NetworkState; | ||
|
||
expect( | ||
updatedNetworkController.networkConfigurationsByChainId[BASE_CHAIN_ID] | ||
.rpcEndpoints[0].url, | ||
).toEqual('https://other.rpc'); | ||
}); | ||
|
||
it('keeps defaultRpcEndpointIndex unchanged when replacing "https://mainnet.base.org"', async () => { | ||
const oldState = { | ||
NetworkController: { | ||
networkConfigurationsByChainId: { | ||
[BASE_CHAIN_ID]: { | ||
rpcEndpoints: [ | ||
{ | ||
url: 'https://mainnet.base.org', | ||
type: 'custom', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
'0x1': { | ||
rpcEndpoints: [ | ||
{ | ||
url: `https://mainnet.infura.io/v3/${infuraProjectId}`, | ||
type: 'infura', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: cloneDeep(oldState), | ||
}); | ||
|
||
const updatedNetworkController = transformedState.data | ||
.NetworkController as NetworkState; | ||
|
||
expect( | ||
updatedNetworkController.networkConfigurationsByChainId[BASE_CHAIN_ID] | ||
.defaultRpcEndpointIndex, | ||
).toEqual(0); | ||
}); | ||
|
||
it('does nothing if Linea mainnet is excluded', async () => { | ||
const oldState = { | ||
NetworkController: { | ||
networkConfigurationsByChainId: { | ||
[BASE_CHAIN_ID]: { | ||
rpcEndpoints: [ | ||
{ | ||
url: 'https://mainnet.base.org', | ||
type: 'custom', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
'0x1': { | ||
rpcEndpoints: [ | ||
{ | ||
url: `https://mainnet.infura.io/v3/${infuraProjectId}`, | ||
type: 'infura', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
'0x13881': { | ||
rpcEndpoints: [ | ||
{ | ||
url: 'https://rpc.goerli.linea.io', | ||
type: 'custom', | ||
}, | ||
], | ||
defaultRpcEndpointIndex: 0, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const transformedState = await migrate({ | ||
meta: { version: oldVersion }, | ||
data: cloneDeep(oldState), | ||
}); | ||
|
||
const updatedNetworkController = transformedState.data | ||
.NetworkController as NetworkState; | ||
|
||
expect( | ||
updatedNetworkController.networkConfigurationsByChainId['0x13881'] | ||
.rpcEndpoints[0].url, | ||
).toEqual('https://rpc.goerli.linea.io'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.