Skip to content

Commit

Permalink
Improve type checking for resolvedAddress in configAndIndexingFunctio…
Browse files Browse the repository at this point in the history
…ns (#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 <kyscott@umich.edu>
  • Loading branch information
3commascapital and kyscott18 authored Dec 11, 2024
1 parent 48040c5 commit 6df44c9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-ways-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ponder": patch
---

Fixed a bug introduced in v0.8.0 with using an array of addresses in `ponder.config.ts`.
37 changes: 37 additions & 0 deletions packages/core/src/build/configAndIndexingFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const func0 = parseAbiItem(

const address1 = "0x0000000000000000000000000000000000000001";
const address2 = "0x0000000000000000000000000000000000000001";
const address3 = "0x0000000000000000000000000000000000000003";
const bytes1 =
"0x0000000000000000000000000000000000000000000000000000000000000001";
const bytes2 =
Expand Down Expand Up @@ -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: {
Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/build/configAndIndexingFunctions.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 [
Expand Down

0 comments on commit 6df44c9

Please sign in to comment.