mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix test build network controller state (#19922)
The default network controller state is currently invalid on test builds. The initial state is set to localhost (Ganache) on test builds, but that network configuration is missing. The initial state for test builds has been updated to include the network configuration for localhost. Additionally, the initial state was updated to only be applied if persisted state is missing. This is to ensure the initial network configuration state doesn't override test fixtures in e2e tests.
This commit is contained in:
parent
6db241ab49
commit
e7144411c7
@ -315,31 +315,42 @@ export default class MetamaskController extends EventEmitter {
|
||||
],
|
||||
});
|
||||
|
||||
let initialProviderConfig;
|
||||
if (process.env.IN_TEST) {
|
||||
initialProviderConfig = {
|
||||
type: NETWORK_TYPES.RPC,
|
||||
rpcUrl: 'http://localhost:8545',
|
||||
chainId: '0x539',
|
||||
nickname: 'Localhost 8545',
|
||||
ticker: 'ETH',
|
||||
let initialNetworkControllerState = {};
|
||||
if (initState.NetworkController) {
|
||||
initialNetworkControllerState = initState.NetworkController;
|
||||
} else if (process.env.IN_TEST) {
|
||||
initialNetworkControllerState = {
|
||||
providerConfig: {
|
||||
chainId: CHAIN_IDS.LOCALHOST,
|
||||
nickname: 'Localhost 8545',
|
||||
rpcPrefs: {},
|
||||
rpcUrl: 'http://localhost:8545',
|
||||
ticker: 'ETH',
|
||||
type: 'rpc',
|
||||
},
|
||||
networkConfigurations: {
|
||||
networkConfigurationId: {
|
||||
chainId: CHAIN_IDS.LOCALHOST,
|
||||
nickname: 'Localhost 8545',
|
||||
rpcPrefs: {},
|
||||
rpcUrl: 'http://localhost:8545',
|
||||
ticker: 'ETH',
|
||||
networkConfigurationId: 'networkConfigurationId',
|
||||
},
|
||||
},
|
||||
};
|
||||
} else if (
|
||||
process.env.METAMASK_DEBUG ||
|
||||
process.env.METAMASK_ENVIRONMENT === 'test'
|
||||
) {
|
||||
initialProviderConfig = {
|
||||
type: NETWORK_TYPES.GOERLI,
|
||||
chainId: CHAIN_IDS.GOERLI,
|
||||
ticker: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.GOERLI],
|
||||
initialNetworkControllerState = {
|
||||
providerConfig: {
|
||||
type: NETWORK_TYPES.GOERLI,
|
||||
chainId: CHAIN_IDS.GOERLI,
|
||||
ticker: TEST_NETWORK_TICKER_MAP[NETWORK_TYPES.GOERLI],
|
||||
},
|
||||
};
|
||||
}
|
||||
const initialNetworkControllerState = initialProviderConfig
|
||||
? {
|
||||
providerConfig: initialProviderConfig,
|
||||
...initState.NetworkController,
|
||||
}
|
||||
: initState.NetworkController;
|
||||
this.networkController = new NetworkController({
|
||||
messenger: networkControllerMessenger,
|
||||
state: initialNetworkControllerState,
|
||||
|
Loading…
Reference in New Issue
Block a user