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

View File

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