diff --git a/package.json b/package.json index 43092b98..33941b6f 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@metamask/utils": "^3.0.3", "btoa": "^1.2.1", "clone": "^2.1.1", - "eth-block-tracker": "^5.0.1", + "eth-block-tracker": "^6.0.0", "eth-rpc-errors": "^4.0.3", "json-rpc-engine": "^6.1.0", "json-stable-stringify": "^1.0.1", diff --git a/src/block-ref.test.ts b/src/block-ref.test.ts index ac87ffea..df4ba73a 100644 --- a/src/block-ref.test.ts +++ b/src/block-ref.test.ts @@ -472,8 +472,12 @@ async function withTestSetup( engine.push(middleware); } - if (callback === undefined) { - return undefined; + try { + if (callback === undefined) { + return undefined; + } + return await callback({ engine, provider, blockTracker }); + } finally { + await blockTracker.destroy(); } - return await callback({ engine, provider, blockTracker }); } diff --git a/src/retryOnEmpty.test.ts b/src/retryOnEmpty.test.ts index ec9c3cc9..1f474b29 100644 --- a/src/retryOnEmpty.test.ts +++ b/src/retryOnEmpty.test.ts @@ -10,6 +10,7 @@ import { buildMockParamsWithoutBlockParamAt, buildSimpleFinalMiddleware, buildStubForBlockNumberRequest, + buildStubForGenericRequest, expectProviderRequestNotToHaveBeenMade, ProviderRequestStub, requestMatches, @@ -199,7 +200,7 @@ describe('createRetryOnEmptyMiddleware', () => { }; const sendAsyncSpy = stubProviderRequests(provider, [ buildStubForBlockNumberRequest(blockNumber), - stubGenericRequest({ + buildStubForGenericRequest({ request, response: (req) => { return { @@ -259,7 +260,7 @@ describe('createRetryOnEmptyMiddleware', () => { }; stubProviderRequests(provider, [ buildStubForBlockNumberRequest(blockNumber), - stubGenericRequest({ + buildStubForGenericRequest({ request, response: (req) => { return { @@ -661,22 +662,14 @@ async function withTestSetup( engine.push(middleware); } - if (callback === undefined) { - return undefined; + try { + if (callback === undefined) { + return undefined; + } + return await callback({ engine, provider, blockTracker }); + } finally { + await blockTracker.destroy(); } - return await callback({ engine, provider, blockTracker }); -} - -/** - * Builds a canned response for a request made to `provider.sendAsync`. Intended - * to be used in conjunction with `stubProviderRequests`. Although not strictly - * necessary, it helps to assign a proper type to a request/response pair. - * - * @param requestStub - The request/response pair. - * @returns The request/response pair, properly typed. - */ -function stubGenericRequest(requestStub: ProviderRequestStub) { - return requestStub; } /** @@ -700,7 +693,7 @@ function stubRequestThatFailsThenFinallySucceeds({ numberOfTimesToFail: number; successfulResponse: ProviderRequestStub['response']; }): ProviderRequestStub { - return stubGenericRequest({ + return buildStubForGenericRequest({ request, response: (req, callNumber) => { if (callNumber <= numberOfTimesToFail) { diff --git a/yarn.lock b/yarn.lock index 2a34ff3c..03feba3d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -866,7 +866,7 @@ __metadata: languageName: node linkType: hard -"@metamask/utils@npm:^3.0.3": +"@metamask/utils@npm:^3.0.1, @metamask/utils@npm:^3.0.3": version: 3.0.3 resolution: "@metamask/utils@npm:3.0.3" dependencies: @@ -2766,14 +2766,15 @@ __metadata: languageName: node linkType: hard -"eth-block-tracker@npm:^5.0.1": - version: 5.0.1 - resolution: "eth-block-tracker@npm:5.0.1" +"eth-block-tracker@npm:^6.0.0": + version: 6.0.0 + resolution: "eth-block-tracker@npm:6.0.0" dependencies: "@metamask/safe-event-emitter": ^2.0.0 + "@metamask/utils": ^3.0.1 json-rpc-random-id: ^1.0.1 pify: ^3.0.0 - checksum: 83b2dd28fb7f12d644f1c1bc72011fb6bb683012489973e31171d445a34ddf6a1c167be4e4232bf7eb65144f08d92705795cf6b371c5aa6a8e78ebf48e4d5654 + checksum: ad1199b822a9a3ff2673ecc92ca7cda0a37828e5bfd1927fd917a8085a99904fc29d3ef2392068bcfb14e47589df097940ef28f3e9025d1681e56a89b07e284e languageName: node linkType: hard @@ -2807,7 +2808,7 @@ __metadata: eslint-plugin-jest: ^24.1.3 eslint-plugin-node: ^11.1.0 eslint-plugin-prettier: ^3.3.1 - eth-block-tracker: ^5.0.1 + eth-block-tracker: ^6.0.0 eth-rpc-errors: ^4.0.3 jest: ^27.5.1 json-rpc-engine: ^6.1.0