From e7d31c10724a956c5f430083fce35f213568ffb2 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Sat, 9 Sep 2023 06:06:05 +0000 Subject: [PATCH] WIP: Update after dependency updates --- src/block-tracker-inspector.ts | 10 +++++++--- src/retryOnEmpty.test.ts | 23 +++++++++++++++-------- src/wallet.ts | 1 - test/util/createHitTrackerMiddleware.ts | 15 ++++++--------- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/block-tracker-inspector.ts b/src/block-tracker-inspector.ts index 08795c93..eba414ec 100644 --- a/src/block-tracker-inspector.ts +++ b/src/block-tracker-inspector.ts @@ -1,6 +1,10 @@ import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; import { createAsyncMiddleware } from '@metamask/json-rpc-engine'; -import type { JsonRpcParams, PendingJsonRpcResponse } from '@metamask/utils'; +import type { + Json, + JsonRpcParams, + PendingJsonRpcResponse, +} from '@metamask/utils'; import type { PollingBlockTracker } from 'eth-block-tracker'; import { projectLogger, createModuleLogger } from './logging-utils'; @@ -35,7 +39,7 @@ function hasProperty( } function getResultBlockNumber( - response: PendingJsonRpcResponse, + response: PendingJsonRpcResponse, ): string | undefined { const { result } = response; if ( @@ -57,7 +61,7 @@ export function createBlockTrackerInspectorMiddleware({ blockTracker, }: BlockTrackerInspectorMiddlewareOptions): JsonRpcMiddleware< JsonRpcParams, - JsonRpcParams + Json > { return createAsyncMiddleware(async (req, res, next) => { if (!futureBlockRefRequests.includes(req.method)) { diff --git a/src/retryOnEmpty.test.ts b/src/retryOnEmpty.test.ts index 644501d8..cbda6489 100644 --- a/src/retryOnEmpty.test.ts +++ b/src/retryOnEmpty.test.ts @@ -1,10 +1,8 @@ import { providerFromEngine } from '@metamask/eth-json-rpc-provider'; import type { SafeEventEmitterProvider } from '@metamask/eth-json-rpc-provider'; -import type { - JsonRpcMiddleware, - JsonRpcRequest, -} from '@metamask/json-rpc-engine'; +import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; import { JsonRpcEngine } from '@metamask/json-rpc-engine'; +import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils'; import { PollingBlockTracker } from 'eth-block-tracker'; import { createRetryOnEmptyMiddleware } from '.'; @@ -223,7 +221,11 @@ describe('createRetryOnEmptyMiddleware', () => { expect(await promiseForResponse).toMatchObject({ error: expect.objectContaining({ - message: 'RetryOnEmptyMiddleware - retries exhausted', + data: expect.objectContaining({ + cause: expect.objectContaining({ + message: 'RetryOnEmptyMiddleware - retries exhausted', + }), + }), }), }); }, @@ -674,7 +676,9 @@ async function withTestSetup( * @param requestStub - The request/response pair. * @returns The request/response pair, properly typed. */ -function stubGenericRequest(requestStub: ProviderRequestStub) { +function stubGenericRequest( + requestStub: ProviderRequestStub, +) { return requestStub; } @@ -690,7 +694,10 @@ function stubGenericRequest(requestStub: ProviderRequestStub) { * return when called past `numberOfTimesToFail`. * @returns The request/response pair, properly typed. */ -function stubRequestThatFailsThenFinallySucceeds({ +function stubRequestThatFailsThenFinallySucceeds< + T extends JsonRpcParams, + U extends Json, +>({ request, numberOfTimesToFail, successfulResponse, @@ -745,7 +752,7 @@ async function waitForRequestToBeRetried({ numberOfTimes, }: { sendAsyncSpy: jest.SpyInstance; - request: JsonRpcRequest; + request: JsonRpcRequest; numberOfTimes: number; }) { let iterationNumber = 1; diff --git a/src/wallet.ts b/src/wallet.ts index 396e9b35..703390ea 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -7,7 +7,6 @@ import { import { providerErrors, rpcErrors } from '@metamask/rpc-errors'; import type { Json, - JsonRpcParams, JsonRpcRequest, PendingJsonRpcResponse, } from '@metamask/utils'; diff --git a/test/util/createHitTrackerMiddleware.ts b/test/util/createHitTrackerMiddleware.ts index 507db578..ad758cd2 100644 --- a/test/util/createHitTrackerMiddleware.ts +++ b/test/util/createHitTrackerMiddleware.ts @@ -1,17 +1,14 @@ -import type { JsonRpcMiddleware, JsonRpcRequest } from 'json-rpc-engine'; +import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; +import type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils'; interface CreateHitTrackerMiddleware { - getHits(method: string): JsonRpcRequest[]; + getHits(method: string): JsonRpcRequest[]; } export default function createHitTrackerMiddleware() { - const hitTracker: Record[]> = {}; - const middleware: JsonRpcMiddleware & CreateHitTrackerMiddleware = ( - req, - _res, - next, - _end, - ) => { + const hitTracker: Record = {}; + const middleware: JsonRpcMiddleware & + CreateHitTrackerMiddleware = (req, _res, next, _end) => { // mark hit for method const hitsForMethod = hitTracker[req.method] || []; hitsForMethod.push(req);