From 6df44c91095ec337faf27a8eb6e3ddfa48641b7c Mon Sep 17 00:00:00 2001 From: 3commascapital <90629478+3commascapital@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:16:00 -0600 Subject: [PATCH] Improve type checking for resolvedAddress in configAndIndexingFunctions (#1328) * Improve type checking for resolvedAddress in configAndIndexingFunctions - Add check to ensure resolvedAddress is not an array - Remove unnecessary type assertion when spreading resolvedAddress * Fix address handling and add test for multiple addresses - Correct address2 value in test file - Add new test case for handling multiple addresses - Update buildConfigAndIndexingFunctions to support array of addresses * Fixup tests * chore: changeset --------- Co-authored-by: Kyle Scott --- .changeset/weak-ways-vanish.md | 5 +++ .../build/configAndIndexingFunctions.test.ts | 37 +++++++++++++++++++ .../src/build/configAndIndexingFunctions.ts | 15 +++++--- 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 .changeset/weak-ways-vanish.md diff --git a/.changeset/weak-ways-vanish.md b/.changeset/weak-ways-vanish.md new file mode 100644 index 000000000..4df16bb63 --- /dev/null +++ b/.changeset/weak-ways-vanish.md @@ -0,0 +1,5 @@ +--- +"ponder": patch +--- + +Fixed a bug introduced in v0.8.0 with using an array of addresses in `ponder.config.ts`. diff --git a/packages/core/src/build/configAndIndexingFunctions.test.ts b/packages/core/src/build/configAndIndexingFunctions.test.ts index 8d474080e..5d887c588 100644 --- a/packages/core/src/build/configAndIndexingFunctions.test.ts +++ b/packages/core/src/build/configAndIndexingFunctions.test.ts @@ -30,6 +30,7 @@ const func0 = parseAbiItem( const address1 = "0x0000000000000000000000000000000000000001"; const address2 = "0x0000000000000000000000000000000000000001"; +const address3 = "0x0000000000000000000000000000000000000003"; const bytes1 = "0x0000000000000000000000000000000000000000000000000000000000000001"; const bytes2 = @@ -99,6 +100,42 @@ test("buildConfigAndIndexingFunctions() handles overloaded event signatures and ]); }); +test("buildConfigAndIndexingFunctions() handles multiple addresses", async () => { + const config = createConfig({ + networks: { + mainnet: { chainId: 1, transport: http("http://127.0.0.1:8545") }, + }, + contracts: { + a: { + network: { + mainnet: { + address: [address1, address3], + startBlock: 16370000, + endBlock: 16370020, + }, + }, + abi: [event1, event1Overloaded], + filter: { + event: ["Event1()", "Event1(bytes32 indexed)"], + }, + }, + }, + }); + + const { sources } = await buildConfigAndIndexingFunctions({ + config, + rawIndexingFunctions: [ + { name: "a:Event1()", fn: () => {} }, + { name: "a:Event1(bytes32 indexed)", fn: () => {} }, + ], + }); + + expect((sources[0]!.filter as LogFilter).topic0).toMatchObject([ + toEventSelector(event1), + toEventSelector(event1Overloaded), + ]); +}); + test("buildConfigAndIndexingFunctions() creates a source for each network for multi-network contracts", async () => { const config = createConfig({ networks: { diff --git a/packages/core/src/build/configAndIndexingFunctions.ts b/packages/core/src/build/configAndIndexingFunctions.ts index 84134ac2f..28c14824a 100644 --- a/packages/core/src/build/configAndIndexingFunctions.ts +++ b/packages/core/src/build/configAndIndexingFunctions.ts @@ -1,5 +1,4 @@ import { BuildError } from "@/common/errors.js"; -import type { Factory } from "@/config/address.js"; import type { Config } from "@/config/config.js"; import { type Network, @@ -414,11 +413,14 @@ export async function buildConfigAndIndexingFunctions({ const resolvedAddress = source?.address; - if (typeof resolvedAddress === "object") { + if ( + typeof resolvedAddress === "object" && + !Array.isArray(resolvedAddress) + ) { // Note that this can throw. const logFactory = buildLogFactory({ chainId: network.chainId, - ...(resolvedAddress as Factory), + ...resolvedAddress, }); const logSource = { @@ -579,11 +581,14 @@ export async function buildConfigAndIndexingFunctions({ ); } - if (typeof resolvedAddress === "object") { + if ( + typeof resolvedAddress === "object" && + !Array.isArray(resolvedAddress) + ) { // Note that this can throw. const logFactory = buildLogFactory({ chainId: network.chainId, - ...(resolvedAddress as Factory), + ...resolvedAddress, }); return [