Skip to content

Commit

Permalink
Update usage after dependencies updates
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed Sep 21, 2023
1 parent 6dc9d97 commit d769966
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
10 changes: 7 additions & 3 deletions src/block-tracker-inspector.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -35,7 +39,7 @@ function hasProperty<ObjectToCheck, Property extends ValidPropertyType>(
}

function getResultBlockNumber(
response: PendingJsonRpcResponse<JsonRpcParams>,
response: PendingJsonRpcResponse<Json>,
): string | undefined {
const { result } = response;
if (
Expand All @@ -57,7 +61,7 @@ export function createBlockTrackerInspectorMiddleware({
blockTracker,
}: BlockTrackerInspectorMiddlewareOptions): JsonRpcMiddleware<
JsonRpcParams,
JsonRpcParams
Json
> {
return createAsyncMiddleware(async (req, res, next) => {
if (!futureBlockRefRequests.includes(req.method)) {
Expand Down
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 d769966

Please sign in to comment.