diff --git a/packages/network-controller/tests/NetworkController.test.ts b/packages/network-controller/tests/NetworkController.test.ts index 105315d185..f5838512a3 100644 --- a/packages/network-controller/tests/NetworkController.test.ts +++ b/packages/network-controller/tests/NetworkController.test.ts @@ -7,7 +7,6 @@ import { Patch } from 'immer'; import { v4 } from 'uuid'; import { ethErrors } from 'eth-rpc-errors'; import { BUILT_IN_NETWORKS, NetworkType } from '@metamask/controller-utils'; -import { waitForResult } from '../../../tests/helpers'; import { NetworkController, NetworkControllerActions, @@ -7145,7 +7144,7 @@ async function setFakeProvider( stubLookupNetworkWhileSetting?: boolean; stubGetEIP1559CompatibilityWhileSetting?: boolean; } = {}, -): Promise { +): Promise { const fakeProvider = buildFakeProvider(stubs); const fakeNetworkClient = buildFakeClient(fakeProvider); createNetworkClientMock.mockReturnValue(fakeNetworkClient); @@ -7163,10 +7162,6 @@ async function setFakeProvider( } await controller.initializeProvider(); - await waitForResult( - true, - () => controller.getProviderAndBlockTracker().provider !== undefined, - ); assert(controller.getProviderAndBlockTracker().provider); if (stubLookupNetworkWhileSetting) { @@ -7175,10 +7170,6 @@ async function setFakeProvider( if (stubGetEIP1559CompatibilityWhileSetting) { lookupGetEIP1559CompatibilityMock.mockRestore(); } - - const { provider } = controller.getProviderAndBlockTracker(); - assert(provider); - return provider; } /** diff --git a/tests/helpers.ts b/tests/helpers.ts deleted file mode 100644 index 11a01e2593..0000000000 --- a/tests/helpers.ts +++ /dev/null @@ -1,47 +0,0 @@ -// Store this up front in case it gets stubbed later -const originalSetTimeout = global.setTimeout; - -/** - * Calls the given function repeatedly (or at least, for a reasonable amount of - * times) until it returns a value. - * - * @param expectedValue - The value that the function should return. - * @param operation - The function to call. - * @returns A promise that either resolves to a successful result as soon as it - * returns the expected value, or a failure result if that never happens. - */ -export async function waitForResult( - expectedValue: any, - operation: () => any, -): Promise<{ pass: boolean; lastActualValue?: any }> { - const approximateRunTime = 10000; - const intervalBetweenRetries = 25; - const maxNumIterations = approximateRunTime / intervalBetweenRetries; - - let numIterations = 0; - let lastActualValue: any; - - while (numIterations < maxNumIterations) { - const actualValue = operation(); - if (actualValue === expectedValue) { - return { pass: true }; - } - await wait(intervalBetweenRetries); - numIterations += 1; - lastActualValue = actualValue; - } - - return { pass: false, lastActualValue }; -} - -/** - * Returns a promise that resolves after a while. - * - * @param duration - The amount of time to wait in milliseconds. - * @returns The promise. - */ -async function wait(duration: number): Promise { - return new Promise((resolve) => { - originalSetTimeout(resolve, duration); - }); -}