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

Bump viem/abitype versions #239

Merged
merged 11 commits into from
Jun 30, 2023
5 changes: 5 additions & 0 deletions .changeset/late-birds-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-ponder": patch
---

Bumped `viem` and `abitype` versions.
5 changes: 5 additions & 0 deletions .changeset/nervous-vans-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

Fixed a bug where the Ponder server would occasionally fail to start due to a port detection race condition.
5 changes: 5 additions & 0 deletions .changeset/smart-roses-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ponder/core": patch
---

Bumped `viem` and `abitype` versions.
4 changes: 2 additions & 2 deletions examples/art-gobblers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@ponder/core": "workspace:latest"
},
"devDependencies": {
"abitype": "^0.6.7",
"abitype": "^0.8.11",
"typescript": "^5.1.3",
"viem": "0.3.50"
"viem": "^1.2.6"
}
}
4 changes: 2 additions & 2 deletions examples/ethfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@ponder/core": "workspace:latest"
},
"devDependencies": {
"abitype": "^0.6.7",
"abitype": "^0.8.11",
"typescript": "^5.1.3",
"viem": "0.3.50"
"viem": "^1.2.6"
}
}
7 changes: 3 additions & 4 deletions examples/token-erc20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
"@ponder/core": "workspace:latest"
},
"devDependencies": {
"@types/node": "^18.11.18",
"abitype": "^0.6.7",
"typescript": "^4.9.5",
"viem": "0.1.6"
"abitype": "^0.8.11",
"typescript": "^5.1.3",
"viem": "^1.2.6"
}
}
7 changes: 3 additions & 4 deletions examples/token-erc721/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
"@ponder/core": "workspace:latest"
},
"devDependencies": {
"@types/node": "^18.11.18",
"abitype": "^0.6.7",
"typescript": "^4.9.5",
"viem": "0.1.6"
"abitype": "^0.8.11",
"typescript": "^5.1.3",
"viem": "^1.2.6"
}
}
5 changes: 2 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"chokidar": "^3.5.3",
"cors": "^2.8.5",
"data-uri-to-buffer": "3.0.1",
"detect-port": "^1.5.1",
"dotenv": "^16.0.1",
"emittery": "^0.13.1",
"esbuild": "^0.15.2",
Expand All @@ -53,7 +52,7 @@
"retry": "^0.13.1",
"stacktrace-parser": "^0.1.10",
"tsc-alias": "^1.8.2",
"viem": "0.3.50"
"viem": "^1.2.6"
},
"devDependencies": {
"@types/babel__code-frame": "^7.0.3",
Expand All @@ -69,7 +68,7 @@
"@types/react": "^18.0.25",
"@types/retry": "^0.12.2",
"@types/supertest": "^2.0.12",
"abitype": "^0.6.7",
"abitype": "^0.8.11",
"module-alias": "^2.2.2",
"supertest": "^6.3.3",
"tsup": "^6.7.0",
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/Ponder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ export class Ponder {
this.eventHandlerService.metrics.totalMatchedEvents;
this.uiService.ui.handlersToTimestamp =
this.eventHandlerService.metrics.latestHandledEventTimestamp;

this.uiService.ui.port = this.serverService.port;
}, 17);

this.killFunctions.push(() => {
Expand All @@ -432,9 +434,5 @@ export class Ponder {
this.eventHandlerService.metrics.latestHandledEventTimestamp;
this.uiService.render();
});

this.serverService.on("serverStarted", ({ port }) => {
this.uiService.ui.port = port;
});
}
}
6 changes: 5 additions & 1 deletion packages/core/src/_test/art-gobblers/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { rmSync } from "node:fs";
import path from "node:path";
import request from "supertest";
import { afterEach, expect, test, TestContext } from "vitest";
import { afterEach, beforeEach, expect, test, TestContext } from "vitest";

import { setupEventStore, setupUserStore } from "@/_test/setup";
import { testNetworkConfig } from "@/_test/utils";
import { buildOptions } from "@/config/options";
import { buildPonderConfig } from "@/config/ponderConfig";
import { Ponder } from "@/Ponder";

beforeEach(async (context) => await setupEventStore(context));
beforeEach(async (context) => await setupUserStore(context));

const setup = async ({ context }: { context: TestContext }) => {
const config = await buildPonderConfig({
configFile: path.resolve("src/_test/art-gobblers/app/ponder.config.ts"),
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/_test/ens/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { rmSync } from "node:fs";
import path from "node:path";
import request from "supertest";
import { afterEach, expect, test, TestContext } from "vitest";
import { afterEach, beforeEach, expect, test, TestContext } from "vitest";

import { setupEventStore, setupUserStore } from "@/_test/setup";
import { testNetworkConfig } from "@/_test/utils";
import { buildOptions } from "@/config/options";
import { buildPonderConfig } from "@/config/ponderConfig";
import { Ponder } from "@/Ponder";

beforeEach(async (context) => await setupEventStore(context));
beforeEach(async (context) => await setupUserStore(context));

const setup = async ({ context }: { context: TestContext }) => {
const config = await buildPonderConfig({
configFile: path.resolve("src/_test/ens/app/ponder.config.ts"),
Expand Down
48 changes: 41 additions & 7 deletions packages/core/src/_test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import SqliteDatabase from "better-sqlite3";
import moduleAlias from "module-alias";
import path from "node:path";
import { Pool } from "pg";
import { beforeEach } from "vitest";
import type { TestContext } from "vitest";

import { patchSqliteDatabase } from "@/config/database";
import { PostgresEventStore } from "@/event-store/postgres/store";
import { SqliteEventStore } from "@/event-store/sqlite/store";
import type { EventStore } from "@/event-store/store";
import { PostgresUserStore } from "@/user-store/postgres/store";
import { SqliteUserStore } from "@/user-store/sqlite/store";
import { UserStore } from "@/user-store/store";
import type { UserStore } from "@/user-store/store";

import { FORK_BLOCK_NUMBER, FORK_URL, vitalik } from "./constants";
import { poolId, testClient } from "./utils";
Expand All @@ -38,25 +38,59 @@ declare module "vitest" {
}
}

beforeEach(async (context) => {
/**
* Sets up an isolated EventStore on the test context.
*
* ```ts
* // Add this to any test suite that uses the test client.
* beforeEach(async (context) => {
* return await setupEventStore(context);
* })
* ```
*/
export async function setupEventStore(context: TestContext) {
if (process.env.DATABASE_URL) {
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const databaseSchema = `vitest_pool_${poolId}`;
const databaseSchema = `vitest_pool_${process.pid}_${poolId}`;
context.eventStore = new PostgresEventStore({ pool, databaseSchema });
context.userStore = new PostgresUserStore({ pool, databaseSchema });
} else {
const rawSqliteDb = new SqliteDatabase(":memory:");
const db = patchSqliteDatabase({ db: rawSqliteDb });
context.eventStore = new SqliteEventStore({ db });
context.userStore = new SqliteUserStore({ db });
}

await context.eventStore.migrateUp();

return async () => {
await context.eventStore.migrateDown();
};
});
}

/**
* Sets up an isolated UserStore on the test context.
*
* ```ts
* // Add this to any test suite that uses the test client.
* beforeEach(async (context) => {
* return await setupUserStore(context);
* })
* ```
*/
export async function setupUserStore(context: TestContext) {
if (process.env.DATABASE_URL) {
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const databaseSchema = `vitest_pool_${process.pid}_${poolId}`;
context.userStore = new PostgresUserStore({ pool, databaseSchema });
} else {
const rawSqliteDb = new SqliteDatabase(":memory:");
const db = patchSqliteDatabase({ db: rawSqliteDb });
context.userStore = new SqliteUserStore({ db });
}

return async () => {
await context.userStore.teardown();
};
}

/**
* Resets the Anvil instance to the defaults.
Expand Down
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(),
};
5 changes: 4 additions & 1 deletion packages/core/src/event-aggregator/service.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { expect, test, vi } from "vitest";
import { beforeEach, expect, test, vi } from "vitest";

import { usdcContractConfig } from "@/_test/constants";
import { setupEventStore } from "@/_test/setup";
import { publicClient } from "@/_test/utils";
import { encodeLogFilterKey } from "@/config/logFilterKey";
import { LogFilter } from "@/config/logFilters";
import { Network } from "@/config/networks";

import { EventAggregatorService } from "./service";

beforeEach(async (context) => await setupEventStore(context));

const mainnet: Network = {
name: "mainnet",
chainId: 1,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/event-store/store.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { hexToNumber, RpcBlock, RpcLog, RpcTransaction } from "viem";
import { expect, test } from "vitest";
import { beforeEach, expect, test } from "vitest";

import { usdcContractConfig } from "@/_test/constants";
import { setupEventStore } from "@/_test/setup";
import { blobToBigInt } from "@/utils/decode";

/**
* This test suite uses the `store` object injected during setup.
* At the moment, this could be either a PostgresEventStore or a
* SqliteEventStore; the tests run as expected either way.
*/
beforeEach(async (context) => await setupEventStore(context));

test("setup creates tables", async (context) => {
const { eventStore } = context;
Expand Down
Loading