Skip to content

Commit

Permalink
Merge branch 'develop' into 17191/onboarding-unit-tests-create-new-vault
Browse files Browse the repository at this point in the history
  • Loading branch information
tmashuang authored Apr 18, 2023
2 parents 065160c + 39f6042 commit 6d8d5a8
Show file tree
Hide file tree
Showing 72 changed files with 1,755 additions and 658 deletions.
2 changes: 1 addition & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {
os: false,
path: false,
stream: require.resolve('stream-browserify'),
_stream_transform: false,
_stream_transform: require.resolve('readable-stream/lib/_stream_transform.js'),
};
config.module.strictExportPresence = true;
config.module.rules.push({
Expand Down
152 changes: 37 additions & 115 deletions app/scripts/controllers/network/network-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ describe('NetworkController', () => {
});
expect(oldChainIdResult).toBe('0x5');

controller.setActiveNetwork('testNetworkConfigurationId');
await controller.setActiveNetwork('testNetworkConfigurationId');
const promisifiedSendAsync2 = promisify(provider.sendAsync).bind(
provider,
);
Expand Down Expand Up @@ -2431,15 +2431,9 @@ describe('NetworkController', () => {
},
},
beforeCompleting: async () => {
await waitForStateChanges({
controller,
propertyPath: ['networkStatus'],
operation: () => {
controller.setActiveNetwork(
'testNetworkConfigurationId',
);
},
});
await controller.setActiveNetwork(
'testNetworkConfigurationId',
);
},
},
],
Expand Down Expand Up @@ -2506,15 +2500,9 @@ describe('NetworkController', () => {
network1.mockEssentialRpcCalls({
eth_getBlockByNumber: {
beforeCompleting: async () => {
await waitForStateChanges({
controller,
propertyPath: ['networkStatus'],
operation: () => {
controller.setActiveNetwork(
'testNetworkConfigurationId',
);
},
});
await controller.setActiveNetwork(
'testNetworkConfigurationId',
);
},
},
net_version: {
Expand Down Expand Up @@ -2578,15 +2566,9 @@ describe('NetworkController', () => {
latestBlock: POST_1559_BLOCK,
eth_getBlockByNumber: {
beforeCompleting: async () => {
await waitForStateChanges({
controller,
propertyPath: ['networkStatus'],
operation: () => {
controller.setActiveNetwork(
'testNetworkConfigurationId',
);
},
});
await controller.setActiveNetwork(
'testNetworkConfigurationId',
);
},
},
});
Expand Down Expand Up @@ -4032,9 +4014,9 @@ describe('NetworkController', () => {
async ({ controller, network }) => {
network.mockEssentialRpcCalls();

expect(() =>
await expect(() =>
controller.setActiveNetwork('invalid-network-configuration-id'),
).toThrow(
).rejects.toThrow(
new Error(
'networkConfigurationId invalid-network-configuration-id does not match a configured networkConfiguration',
),
Expand Down Expand Up @@ -4075,7 +4057,7 @@ describe('NetworkController', () => {
});
network.mockEssentialRpcCalls();

controller.setActiveNetwork('testNetworkConfigurationId1');
await controller.setActiveNetwork('testNetworkConfigurationId1');

expect(controller.store.getState().provider).toStrictEqual({
type: 'rpc',
Expand Down Expand Up @@ -4144,6 +4126,8 @@ describe('NetworkController', () => {
messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.NetworkWillChange,
operation: () => {
// Intentionally not awaited because we're checking state
// partway through the operation
controller.setActiveNetwork('testNetworkConfigurationId2');
},
beforeResolving: () => {
Expand Down Expand Up @@ -4208,6 +4192,8 @@ describe('NetworkController', () => {
// before networkDidChange
count: 1,
operation: () => {
// Intentionally not awaited because we're checking state
// partway through the operation.
controller.setActiveNetwork('testNetworkConfigurationId1');
},
});
Expand Down Expand Up @@ -4267,6 +4253,8 @@ describe('NetworkController', () => {
// before networkDidChange
count: 1,
operation: () => {
// Intentionally not awaited because we're checking state
// partway through the operation
controller.setActiveNetwork('testNetworkConfigurationId2');
},
});
Expand Down Expand Up @@ -4308,7 +4296,7 @@ describe('NetworkController', () => {
},
});

controller.setActiveNetwork('testNetworkConfigurationId');
await controller.setActiveNetwork('testNetworkConfigurationId');

const { provider } = controller.getProviderAndBlockTracker();
assert(provider, 'Provider is somehow unset');
Expand Down Expand Up @@ -4356,7 +4344,7 @@ describe('NetworkController', () => {

const { provider: providerBefore } =
controller.getProviderAndBlockTracker();
controller.setActiveNetwork('testNetworkConfigurationId');
await controller.setActiveNetwork('testNetworkConfigurationId');
const { provider: providerAfter } =
controller.getProviderAndBlockTracker();

Expand Down Expand Up @@ -4392,8 +4380,8 @@ describe('NetworkController', () => {
const networkDidChange = await waitForPublishedEvents({
messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.NetworkDidChange,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
operation: async () => {
await controller.setActiveNetwork('testNetworkConfigurationId');
},
});

Expand Down Expand Up @@ -4429,8 +4417,8 @@ describe('NetworkController', () => {
const infuraIsUnblocked = await waitForPublishedEvents({
messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.InfuraIsUnblocked,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
operation: async () => {
await controller.setActiveNetwork('testNetworkConfigurationId');
},
});

Expand Down Expand Up @@ -4462,13 +4450,7 @@ describe('NetworkController', () => {
response: SUCCESSFUL_NET_VERSION_RESPONSE,
},
});
await waitForStateChanges({
controller,
propertyPath: ['networkStatus'],
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId');

expect(controller.store.getState().networkStatus).toBe('available');
},
Expand Down Expand Up @@ -4501,16 +4483,7 @@ describe('NetworkController', () => {
latestBlock: POST_1559_BLOCK,
});

await waitForStateChanges({
controller,
propertyPath: ['networkDetails'],
// setActiveNetwork clears networkDetails first, and then updates it
// to what we expect it to be
count: 2,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId');

expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {
Expand Down Expand Up @@ -5657,12 +5630,7 @@ describe('NetworkController', () => {
currentNetwork.mockEssentialRpcCalls();
previousNetwork.mockEssentialRpcCalls();

await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId2');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId2');
expect(controller.store.getState().provider).toStrictEqual({
type: 'rpc',
rpcUrl: 'https://mock-rpc-url-2',
Expand Down Expand Up @@ -5730,12 +5698,7 @@ describe('NetworkController', () => {
});
currentNetwork.mockEssentialRpcCalls();
previousNetwork.mockEssentialRpcCalls();
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId');

await waitForLookupNetworkToComplete({
controller,
Expand Down Expand Up @@ -5787,12 +5750,7 @@ describe('NetworkController', () => {
currentNetwork.mockEssentialRpcCalls();
previousNetwork.mockEssentialRpcCalls();

await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId');
expect(controller.store.getState().networkStatus).toBe(
'available',
);
Expand Down Expand Up @@ -5855,12 +5813,7 @@ describe('NetworkController', () => {
});
previousNetwork.mockEssentialRpcCalls();

await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId');
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {
1559: true,
Expand Down Expand Up @@ -5926,12 +5879,7 @@ describe('NetworkController', () => {
});
currentNetwork.mockEssentialRpcCalls();
previousNetwork.mockEssentialRpcCalls();
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId');

await waitForLookupNetworkToComplete({
controller,
Expand Down Expand Up @@ -5986,12 +5934,7 @@ describe('NetworkController', () => {
});
currentNetwork.mockEssentialRpcCalls();
previousNetwork.mockEssentialRpcCalls();
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId');

const { provider: providerBefore } =
controller.getProviderAndBlockTracker();
Expand Down Expand Up @@ -6045,12 +5988,7 @@ describe('NetworkController', () => {
currentNetwork.mockEssentialRpcCalls();
previousNetwork.mockEssentialRpcCalls();

await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId');

await waitForLookupNetworkToComplete({
controller,
Expand Down Expand Up @@ -6103,12 +6041,7 @@ describe('NetworkController', () => {
response: BLOCKED_INFURA_RESPONSE,
},
});
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId');
const promiseForNoInfuraIsUnblockedEvents =
waitForPublishedEvents({
messenger: unrestrictedMessenger,
Expand Down Expand Up @@ -6173,13 +6106,7 @@ describe('NetworkController', () => {
},
});

await waitForStateChanges({
controller,
propertyPath: ['networkStatus'],
operation: () => {
controller.setActiveNetwork('currentNetworkConfiguration');
},
});
await controller.setActiveNetwork('currentNetworkConfiguration');
expect(controller.store.getState().networkStatus).toBe(
'unavailable',
);
Expand Down Expand Up @@ -6228,12 +6155,7 @@ describe('NetworkController', () => {
latestBlock: POST_1559_BLOCK,
});

await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.setActiveNetwork('testNetworkConfigurationId');
},
});
await controller.setActiveNetwork('testNetworkConfigurationId');
expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: {
1559: false,
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/controllers/network/network-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ export class NetworkController extends EventEmitter {
* @returns The URL of the RPC endpoint representing the newly switched
* network.
*/
setActiveNetwork(networkConfigurationId: NetworkConfigurationId): string {
async setActiveNetwork(networkConfigurationId: NetworkConfigurationId) {
const targetNetwork =
this.store.getState().networkConfigurations[networkConfigurationId];

Expand All @@ -714,7 +714,7 @@ export class NetworkController extends EventEmitter {
);
}

this.#setProviderConfig({
await this.#setProviderConfig({
type: NETWORK_TYPES.RPC,
...targetNetwork,
});
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/sign.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const messageMock = {
const coreMessageMock = {
...messageMock,
messageParams: messageParamsMock,
securityProviderResponse: securityProviderResponseMock,
};

const stateMessageMock = {
Expand Down
Loading

0 comments on commit 6d8d5a8

Please sign in to comment.