Skip to content

Commit

Permalink
WIP: Update after dependency updates
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Sep 9, 2023
1 parent b71f0fa commit 061daf1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
23 changes: 15 additions & 8 deletions src/retryOnEmpty.test.ts
Original file line number Diff line number Diff line change
@@ -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 '.';
Expand Down Expand Up @@ -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',
}),
}),
}),
});
},
Expand Down Expand Up @@ -674,7 +676,9 @@ async function withTestSetup<T>(
* @param requestStub - The request/response pair.
* @returns The request/response pair, properly typed.
*/
function stubGenericRequest<T, U>(requestStub: ProviderRequestStub<T, U>) {
function stubGenericRequest<T extends JsonRpcParams, U extends Json>(
requestStub: ProviderRequestStub<T, U>,
) {
return requestStub;
}

Expand All @@ -690,7 +694,10 @@ function stubGenericRequest<T, U>(requestStub: ProviderRequestStub<T, U>) {
* return when called past `numberOfTimesToFail`.
* @returns The request/response pair, properly typed.
*/
function stubRequestThatFailsThenFinallySucceeds<T, U>({
function stubRequestThatFailsThenFinallySucceeds<
T extends JsonRpcParams,
U extends Json,
>({
request,
numberOfTimesToFail,
successfulResponse,
Expand Down Expand Up @@ -745,7 +752,7 @@ async function waitForRequestToBeRetried({
numberOfTimes,
}: {
sendAsyncSpy: jest.SpyInstance;
request: JsonRpcRequest<unknown>;
request: JsonRpcRequest;
numberOfTimes: number;
}) {
let iterationNumber = 1;
Expand Down
1 change: 0 additions & 1 deletion src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import { providerErrors, rpcErrors } from '@metamask/rpc-errors';
import type {
Json,
JsonRpcParams,
JsonRpcRequest,
PendingJsonRpcResponse,
} from '@metamask/utils';
Expand Down
15 changes: 6 additions & 9 deletions test/util/createHitTrackerMiddleware.ts
Original file line number Diff line number Diff line change
@@ -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<any>[];
getHits(method: string): JsonRpcRequest[];
}

export default function createHitTrackerMiddleware() {
const hitTracker: Record<string, JsonRpcRequest<any>[]> = {};
const middleware: JsonRpcMiddleware<any, any> & CreateHitTrackerMiddleware = (
req,
_res,
next,
_end,
) => {
const hitTracker: Record<string, JsonRpcRequest[]> = {};
const middleware: JsonRpcMiddleware<JsonRpcParams, Json> &
CreateHitTrackerMiddleware = (req, _res, next, _end) => {
// mark hit for method
const hitsForMethod = hitTracker[req.method] || [];
hitsForMethod.push(req);
Expand Down

0 comments on commit 061daf1

Please sign in to comment.