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:
parent
7f82ea231c
commit
84d22e122c
@ -158,57 +158,23 @@ describe('NetworkController', () => {
|
|||||||
describe('constructor', () => {
|
describe('constructor', () => {
|
||||||
const invalidInfuraProjectIds = [undefined, null, {}, 1];
|
const invalidInfuraProjectIds = [undefined, null, {}, 1];
|
||||||
invalidInfuraProjectIds.forEach((invalidProjectId) => {
|
invalidInfuraProjectIds.forEach((invalidProjectId) => {
|
||||||
it(`throws if an invalid Infura ID of "${inspect(
|
it(`throws given an invalid Infura ID of "${inspect(
|
||||||
invalidProjectId,
|
invalidProjectId,
|
||||||
)}" is provided`, () => {
|
)}"`, () => {
|
||||||
|
const messenger = buildMessenger();
|
||||||
|
const restrictedMessenger = buildNetworkControllerMessenger(messenger);
|
||||||
expect(
|
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');
|
).toThrow('Invalid Infura project ID');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts initial state', async () => {
|
it('initializes the state with some defaults', 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 () => {
|
|
||||||
await withController(({ controller }) => {
|
await withController(({ controller }) => {
|
||||||
expect(controller.store.getState()).toMatchInlineSnapshot(`
|
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', () => {
|
describe('destroy', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user