1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Sync NetworkController constructor tests with core (#19311)

This makes it easier to compare the NetworkController unit tests between
extension and core.
This commit is contained in:
Elliot Winkler 2023-05-31 09:29:29 -06:00 committed by GitHub
parent 7f82ea231c
commit 84d22e122c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -158,57 +158,23 @@ describe('NetworkController', () => {
describe('constructor', () => {
const invalidInfuraProjectIds = [undefined, null, {}, 1];
invalidInfuraProjectIds.forEach((invalidProjectId) => {
it(`throws if an invalid Infura ID of "${inspect(
it(`throws given an invalid Infura ID of "${inspect(
invalidProjectId,
)}" is provided`, () => {
)}"`, () => {
const messenger = buildMessenger();
const restrictedMessenger = buildNetworkControllerMessenger(messenger);
expect(
// @ts-expect-error We are intentionally passing bad input.
() => new NetworkController({ infuraProjectId: invalidProjectId }),
() =>
new NetworkController({
messenger: restrictedMessenger,
// @ts-expect-error We are intentionally passing bad input.
infuraProjectId: invalidProjectId,
}),
).toThrow('Invalid Infura project ID');
});
});
it('accepts initial state', async () => {
await withController(
{
state: {
providerConfig: {
type: 'rpc',
rpcUrl: 'http://example-custom-rpc.metamask.io',
chainId: '0x9999' as const,
nickname: 'Test initial state',
},
networkDetails: {
EIPS: {
1559: false,
},
},
},
},
({ controller }) => {
expect(controller.store.getState()).toMatchInlineSnapshot(`
{
"networkConfigurations": {},
"networkDetails": {
"EIPS": {
"1559": false,
},
},
"networkId": null,
"networkStatus": "unknown",
"providerConfig": {
"chainId": "0x9999",
"nickname": "Test initial state",
"rpcUrl": "http://example-custom-rpc.metamask.io",
"type": "rpc",
},
}
`);
},
);
});
it('sets default state without initial state', async () => {
it('initializes the state with some defaults', async () => {
await withController(({ controller }) => {
expect(controller.store.getState()).toMatchInlineSnapshot(`
{
@ -231,6 +197,46 @@ describe('NetworkController', () => {
`);
});
});
it('merges the given state into the default state', async () => {
await withController(
{
state: {
providerConfig: {
type: 'rpc',
rpcUrl: 'http://example-custom-rpc.metamask.io',
chainId: '0x9999' as const,
nickname: 'Test initial state',
},
networkDetails: {
EIPS: {
1559: true,
},
},
},
},
({ controller }) => {
expect(controller.store.getState()).toMatchInlineSnapshot(`
{
"networkConfigurations": {},
"networkDetails": {
"EIPS": {
"1559": true,
},
},
"networkId": null,
"networkStatus": "unknown",
"providerConfig": {
"chainId": "0x9999",
"nickname": "Test initial state",
"rpcUrl": "http://example-custom-rpc.metamask.io",
"type": "rpc",
},
}
`);
},
);
});
});
describe('destroy', () => {