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

Make resetConnection async (#18601)

The network controller method `resetConnection` is now async. This has
no functional impact.

Relates to https://github.com/MetaMask/metamask-extension/issues/18587
This commit is contained in:
Mark Stacey 2023-04-17 15:45:22 -02:30 committed by GitHub
parent b87c1b8526
commit e5835ac459
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 46 deletions

View File

@ -4925,6 +4925,8 @@ describe('NetworkController', () => {
messenger: unrestrictedMessenger, messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.NetworkWillChange, eventType: NetworkControllerEventType.NetworkWillChange,
operation: () => { operation: () => {
// Intentionally not awaited because we want to capture an
// event emitted partway throught this operation
controller.resetConnection(); controller.resetConnection();
}, },
}); });
@ -4965,6 +4967,8 @@ describe('NetworkController', () => {
// happens before networkDidChange // happens before networkDidChange
count: 1, count: 1,
operation: () => { operation: () => {
// Intentionally not awaited because we want to capture a
// state change made partway through the operation
controller.resetConnection(); controller.resetConnection();
}, },
}); });
@ -5007,6 +5011,8 @@ describe('NetworkController', () => {
// happens before networkDidChange // happens before networkDidChange
count: 1, count: 1,
operation: () => { operation: () => {
// Intentionally not awaited because we want to check state
// partway through the operation
controller.resetConnection(); controller.resetConnection();
}, },
}); });
@ -5034,7 +5040,7 @@ describe('NetworkController', () => {
async ({ controller, network }) => { async ({ controller, network }) => {
network.mockEssentialRpcCalls(); network.mockEssentialRpcCalls();
controller.resetConnection(); await controller.resetConnection();
const { provider } = controller.getProviderAndBlockTracker(); const { provider } = controller.getProviderAndBlockTracker();
assert(provider, 'Provider is somehow unset'); assert(provider, 'Provider is somehow unset');
@ -5073,7 +5079,7 @@ describe('NetworkController', () => {
const { provider: providerBefore } = const { provider: providerBefore } =
controller.getProviderAndBlockTracker(); controller.getProviderAndBlockTracker();
controller.resetConnection(); await controller.resetConnection();
const { provider: providerAfter } = const { provider: providerAfter } =
controller.getProviderAndBlockTracker(); controller.getProviderAndBlockTracker();
@ -5104,8 +5110,8 @@ describe('NetworkController', () => {
const networkDidChange = await waitForPublishedEvents({ const networkDidChange = await waitForPublishedEvents({
messenger: unrestrictedMessenger, messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.NetworkDidChange, eventType: NetworkControllerEventType.NetworkDidChange,
operation: () => { operation: async () => {
controller.resetConnection(); await controller.resetConnection();
}, },
}); });
@ -5147,7 +5153,7 @@ describe('NetworkController', () => {
eventType: NetworkControllerEventType.InfuraIsBlocked, eventType: NetworkControllerEventType.InfuraIsBlocked,
}); });
controller.resetConnection(); await controller.resetConnection();
expect(await promiseForNoInfuraIsUnblockedEvents).toBeTruthy(); expect(await promiseForNoInfuraIsUnblockedEvents).toBeTruthy();
expect(await promiseForInfuraIsBlocked).toBeTruthy(); expect(await promiseForInfuraIsBlocked).toBeTruthy();
@ -5170,13 +5176,7 @@ describe('NetworkController', () => {
async ({ controller, network }) => { async ({ controller, network }) => {
network.mockEssentialRpcCalls(); network.mockEssentialRpcCalls();
await waitForStateChanges({ await controller.resetConnection();
controller,
propertyPath: ['networkStatus'],
operation: () => {
controller.resetConnection();
},
});
expect(controller.store.getState().networkStatus).toBe( expect(controller.store.getState().networkStatus).toBe(
'available', 'available',
@ -5208,13 +5208,7 @@ describe('NetworkController', () => {
}, },
}); });
await waitForStateChanges({ await controller.resetConnection();
controller,
propertyPath: ['networkDetails'],
operation: () => {
controller.resetConnection();
},
});
expect(controller.store.getState().networkDetails).toStrictEqual({ expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: { EIPS: {
@ -5259,6 +5253,8 @@ describe('NetworkController', () => {
messenger: unrestrictedMessenger, messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.NetworkWillChange, eventType: NetworkControllerEventType.NetworkWillChange,
operation: () => { operation: () => {
// Intentionally not awaited because we're capturing an event
// emitted partway through the operation
controller.resetConnection(); controller.resetConnection();
}, },
}); });
@ -5309,6 +5305,8 @@ describe('NetworkController', () => {
// before networkDidChange // before networkDidChange
count: 1, count: 1,
operation: () => { operation: () => {
// Intentionally not awaited because we want to check state
// partway through the operation
controller.resetConnection(); controller.resetConnection();
}, },
}); });
@ -5359,6 +5357,8 @@ describe('NetworkController', () => {
// before networkDidChange // before networkDidChange
count: 1, count: 1,
operation: () => { operation: () => {
// Intentionally not awaited because we want to check state
// partway through the operation
controller.resetConnection(); controller.resetConnection();
}, },
}); });
@ -5394,7 +5394,7 @@ describe('NetworkController', () => {
async ({ controller, network }) => { async ({ controller, network }) => {
network.mockEssentialRpcCalls(); network.mockEssentialRpcCalls();
controller.resetConnection(); await controller.resetConnection();
const { provider } = controller.getProviderAndBlockTracker(); const { provider } = controller.getProviderAndBlockTracker();
assert(provider, 'Provider is somehow unset'); assert(provider, 'Provider is somehow unset');
@ -5441,12 +5441,7 @@ describe('NetworkController', () => {
const { provider: providerBefore } = const { provider: providerBefore } =
controller.getProviderAndBlockTracker(); controller.getProviderAndBlockTracker();
await waitForLookupNetworkToComplete({ await controller.resetConnection();
controller,
operation: () => {
controller.resetConnection();
},
});
const { provider: providerAfter } = const { provider: providerAfter } =
controller.getProviderAndBlockTracker(); controller.getProviderAndBlockTracker();
@ -5485,8 +5480,8 @@ describe('NetworkController', () => {
const networkDidChange = await waitForPublishedEvents({ const networkDidChange = await waitForPublishedEvents({
messenger: unrestrictedMessenger, messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.NetworkDidChange, eventType: NetworkControllerEventType.NetworkDidChange,
operation: () => { operation: async () => {
controller.resetConnection(); await controller.resetConnection();
}, },
}); });
@ -5525,8 +5520,8 @@ describe('NetworkController', () => {
const infuraIsUnblocked = await waitForPublishedEvents({ const infuraIsUnblocked = await waitForPublishedEvents({
messenger: unrestrictedMessenger, messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.InfuraIsUnblocked, eventType: NetworkControllerEventType.InfuraIsUnblocked,
operation: () => { operation: async () => {
controller.resetConnection(); await controller.resetConnection();
}, },
}); });
@ -5563,13 +5558,7 @@ describe('NetworkController', () => {
}); });
expect(controller.store.getState().networkStatus).toBe('unknown'); expect(controller.store.getState().networkStatus).toBe('unknown');
await waitForStateChanges({ await controller.resetConnection();
controller,
propertyPath: ['networkStatus'],
operation: () => {
controller.resetConnection();
},
});
expect(controller.store.getState().networkStatus).toBe('available'); expect(controller.store.getState().networkStatus).toBe('available');
}, },
@ -5607,13 +5596,7 @@ describe('NetworkController', () => {
}, },
}); });
await waitForStateChanges({ await controller.resetConnection();
controller,
propertyPath: ['networkDetails'],
operation: () => {
controller.resetConnection();
},
});
expect(controller.store.getState().networkDetails).toStrictEqual({ expect(controller.store.getState().networkDetails).toStrictEqual({
EIPS: { EIPS: {

View File

@ -753,8 +753,8 @@ export class NetworkController extends EventEmitter {
/** /**
* Re-initializes the provider and block tracker for the current network. * Re-initializes the provider and block tracker for the current network.
*/ */
resetConnection(): void { async resetConnection() {
this.#setProviderConfig(this.store.getState().provider); await this.#setProviderConfig(this.store.getState().provider);
} }
/** /**