Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update new tests to destroy block tracker #156

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/block-ref.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,12 @@ async function withTestSetup<T>(
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 });
}
29 changes: 11 additions & 18 deletions src/retryOnEmpty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
buildMockParamsWithoutBlockParamAt,
buildSimpleFinalMiddleware,
buildStubForBlockNumberRequest,
buildStubForGenericRequest,
expectProviderRequestNotToHaveBeenMade,
ProviderRequestStub,
requestMatches,
Expand Down Expand Up @@ -199,7 +200,7 @@ describe('createRetryOnEmptyMiddleware', () => {
};
const sendAsyncSpy = stubProviderRequests(provider, [
buildStubForBlockNumberRequest(blockNumber),
stubGenericRequest({
buildStubForGenericRequest({
request,
response: (req) => {
return {
Expand Down Expand Up @@ -259,7 +260,7 @@ describe('createRetryOnEmptyMiddleware', () => {
};
stubProviderRequests(provider, [
buildStubForBlockNumberRequest(blockNumber),
stubGenericRequest({
buildStubForGenericRequest({
request,
response: (req) => {
return {
Expand Down Expand Up @@ -661,22 +662,14 @@ async function withTestSetup<T>(
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<T, U>(requestStub: ProviderRequestStub<T, U>) {
return requestStub;
}

/**
Expand All @@ -700,7 +693,7 @@ function stubRequestThatFailsThenFinallySucceeds<T, U>({
numberOfTimesToFail: number;
successfulResponse: ProviderRequestStub<T, U>['response'];
}): ProviderRequestStub<T, U> {
return stubGenericRequest({
return buildStubForGenericRequest({
request,
response: (req, callNumber) => {
if (callNumber <= numberOfTimesToFail) {
Expand Down
13 changes: 7 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down