Skip to content

Commit

Permalink
fix: various type errors from viem version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOlias committed Jun 28, 2023
1 parent 01cc71a commit 31f7624
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
41 changes: 23 additions & 18 deletions packages/core/src/_test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import {
type Chain,
type HttpTransport,
type PublicClient,
type TestClient,
type WalletClient,
createPublicClient,
createTestClient,
createWalletClient,
Expand All @@ -19,7 +23,7 @@ import { Resources } from "@/Ponder";
// ID of the current test worker. Used by the `@viem/anvil` proxy server.
export const poolId = Number(process.env.VITEST_POOL_ID ?? 1);

export const anvil = {
export const anvil: Chain = {
...mainnet, // We are using a mainnet fork for testing.
id: 1, // We configured our anvil instance to use `1` as the chain id (see `globalSetup.ts`);
rpcUrls: {
Expand All @@ -32,7 +36,7 @@ export const anvil = {
webSocket: [`ws://127.0.0.1:8545/${poolId}`],
},
},
} as Chain;
};

export const testNetworkConfig = {
name: "mainnet",
Expand All @@ -41,27 +45,28 @@ export const testNetworkConfig = {
pollingInterval: 500,
};

export const testClient = createTestClient({
chain: anvil,
mode: "anvil",
transport: http(),
});
export const testClient: TestClient<"anvil", HttpTransport, Chain> =
createTestClient({
chain: anvil,
mode: "anvil",
transport: http(),
});

export const publicClient = createPublicClient({
chain: anvil,
transport: http(),
});
export const publicClient: PublicClient<HttpTransport, Chain> =
createPublicClient({
chain: anvil,
transport: http(),
});

export const walletClient = createWalletClient({
chain: anvil,
transport: http(),
});
export const walletClient: WalletClient<HttpTransport, Chain> =
createWalletClient({
chain: anvil,
transport: http(),
});

export const testResources: Resources = {
options: buildOptions({ cliOptions: { configFile: "", rootDir: "" } }),
logger: new LoggerService({ level: "silent" }),
options: buildOptions({
cliOptions: { configFile: "", rootDir: "" },
}),
errors: new UserErrorService(),
metrics: new MetricsService(),
};
17 changes: 12 additions & 5 deletions packages/core/src/historical-sync/service.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { HttpRequestError, InvalidParamsRpcError } from "viem";
import {
EIP1193RequestFn,
HttpRequestError,
InvalidParamsRpcError,
} from "viem";
import { expect, test, vi } from "vitest";

import { usdcContractConfig } from "@/_test/constants";
Expand All @@ -19,6 +23,11 @@ const network: Network = {
finalityBlockCount: 10,
};

const rpcRequestSpy = vi.spyOn(
network.client as { request: EIP1193RequestFn },
"request"
);

const logFilters: LogFilter[] = [
{
name: "USDC",
Expand Down Expand Up @@ -192,8 +201,7 @@ test("start() retries errors", async (context) => {
test("start() handles Alchemy 'Log response size exceeded' error", async (context) => {
const { eventStore } = context;

const spy = vi.spyOn(network.client, "request");
spy.mockRejectedValueOnce(
rpcRequestSpy.mockRejectedValueOnce(
new InvalidParamsRpcError(
new Error(
// The suggested block range is 16369950 to 16369951.
Expand Down Expand Up @@ -232,8 +240,7 @@ test("start() handles Alchemy 'Log response size exceeded' error", async (contex
test("start() handles Quicknode 'eth_getLogs and eth_newFilter are limited to a 10,000 blocks range' error", async (context) => {
const { eventStore } = context;

const spy = vi.spyOn(network.client, "request");
spy.mockRejectedValueOnce(
rpcRequestSpy.mockRejectedValueOnce(
new HttpRequestError({
url: "http://",
details:
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/user-handlers/contract.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {
type Abi,
type BaseError,
type CallParameters,
type GetContractReturnType,
type Hex,
type PublicClient,
type ReadContractParameters,
BaseError,
CallParameters,
decodeFunctionResult,
encodeFunctionData,
getContract,
getContractError,
Hex,
} from "viem";

import type { Contract } from "@/config/contracts";
Expand All @@ -20,7 +23,7 @@ export function getInjectedContract({
contract: Contract;
getCurrentBlockNumber: () => bigint;
eventStore: EventStore;
}) {
}): GetContractReturnType<Abi, PublicClient> {
const { abi, address } = contract;
const { chainId, client: publicClient } = contract.network;

Expand Down

0 comments on commit 31f7624

Please sign in to comment.