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

Feat: Multiple Block Ranges #1384

Open
wants to merge 8 commits into
base: v0.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 66 additions & 24 deletions packages/core/src/build/configAndIndexingFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ test("buildConfigAndIndexingFunctions() builds topics for multiple events", asyn
network: { mainnet: {} },
abi: [event0, event1],
address: address1,
startBlock: 16370000,
endBlock: 16370020,
blocks: [16370000, 16370020],
},
},
});
Expand Down Expand Up @@ -72,8 +71,7 @@ test("buildConfigAndIndexingFunctions() handles overloaded event signatures and
network: { mainnet: {} },
abi: [event1, event1Overloaded],
address: address1,
startBlock: 16370000,
endBlock: 16370020,
blocks: [16370000, 16370020],
},
},
});
Expand Down Expand Up @@ -102,8 +100,7 @@ test("buildConfigAndIndexingFunctions() handles multiple addresses", async () =>
network: {
mainnet: {
address: [address1, address3],
startBlock: 16370000,
endBlock: 16370020,
blocks: [16370000, 16370020],
},
},
abi: [event1, event1Overloaded],
Expand Down Expand Up @@ -163,8 +160,7 @@ test("buildConfigAndIndexingFunctions() builds topics for event filter", async (
},
},
address: address1,
startBlock: 16370000,
endBlock: 16370020,
blocks: [16370000, 16370020],
},
},
});
Expand Down Expand Up @@ -203,8 +199,7 @@ test("buildConfigAndIndexingFunctions() builds topics for multiple event filters
},
],
address: address1,
startBlock: 16370000,
endBlock: 16370020,
blocks: [16370000, 16370020],
},
},
});
Expand Down Expand Up @@ -237,8 +232,7 @@ test("buildConfigAndIndexingFunctions() overrides default values with network-sp
a: {
abi: [event0],
address: address1,
startBlock: 16370000,
endBlock: 16370020,
blocks: [16370000, 16370020],
network: {
mainnet: {
address: address2,
Expand Down Expand Up @@ -266,8 +260,7 @@ test("buildConfigAndIndexingFunctions() handles network name shortcut", async ()
network: "mainnet",
abi: [event0],
address: address1,
startBlock: 16370000,
endBlock: 16370020,
blocks: [16370000, 16370020],
},
},
});
Expand Down Expand Up @@ -441,7 +434,7 @@ test("buildConfigAndIndexingFunctions() validates address length", async () => {
);
});

test("buildConfigAndIndexingFunctions() coerces NaN startBlock to undefined", async () => {
test("buildConfigAndIndexingFunctions() coerces NaN startBlock to 0", async () => {
const config = createConfig({
networks: {
mainnet: { chainId: 1, transport: http("http://127.0.0.1:8545") },
Expand All @@ -450,7 +443,7 @@ test("buildConfigAndIndexingFunctions() coerces NaN startBlock to undefined", as
a: {
network: { mainnet: {} },
abi: [event0, event1],
startBlock: Number.NaN,
blocks: [Number.NaN, 16370020],
},
},
});
Expand All @@ -460,7 +453,7 @@ test("buildConfigAndIndexingFunctions() coerces NaN startBlock to undefined", as
rawIndexingFunctions: [{ name: "a:Event0", fn: () => {} }],
});

expect(sources[0]?.filter.fromBlock).toBe(undefined);
expect(sources[0]?.filter.fromBlock).toBe(0);
});

test("buildConfigAndIndexingFunctions() includeTransactionReceipts", async () => {
Expand Down Expand Up @@ -565,7 +558,7 @@ test("buildConfigAndIndexingFunctions() includeCallTraces with factory", async (
expect(shouldGetTransactionReceipt(sources[0]!.filter)).toBe(false);
});

test("buildConfigAndIndexingFunctions() coerces NaN endBlock to undefined", async () => {
test("buildConfigAndIndexingFunctions() coerces NaN endBlock to Number.MAX_SAFE_INTEGER", async () => {
const config = createConfig({
networks: {
mainnet: { chainId: 1, transport: http("http://127.0.0.1:8545") },
Expand All @@ -574,7 +567,7 @@ test("buildConfigAndIndexingFunctions() coerces NaN endBlock to undefined", asyn
a: {
network: { mainnet: {} },
abi: [event0, event1],
endBlock: Number.NaN,
blocks: [16370000, Number.NaN],
},
},
});
Expand All @@ -584,7 +577,58 @@ test("buildConfigAndIndexingFunctions() coerces NaN endBlock to undefined", asyn
rawIndexingFunctions: [{ name: "a:Event0", fn: () => {} }],
});

expect(sources[0]!.filter.toBlock).toBe(undefined);
expect(sources[0]!.filter.toBlock).toBe(Number.MAX_SAFE_INTEGER);
});

test("buildConfigAndIndexingFunctions() resolves overlapping block ranges", async () => {
const config = createConfig({
networks: {
mainnet: { chainId: 1, transport: http("http://127.0.0.1:8545") },
},
contracts: {
a: {
network: { mainnet: {} },
abi: [event0, event1],
blocks: [
[16370000, 16370020],
[16370010, 16370030],
],
},
},
});

const { sources } = await buildConfigAndIndexingFunctions({
config,
rawIndexingFunctions: [{ name: "a:Event0", fn: () => {} }],
});

expect(sources[0]!.filter.fromBlock).toBe(16370000);
expect(sources[0]!.filter.toBlock).toBe(16370030);
});

test("buildConfigAndIndexingFunctions() multiple block ranges", async () => {
const config = createConfig({
networks: {
mainnet: { chainId: 1, transport: http("http://127.0.0.1:8545") },
},
contracts: {
a: {
network: { mainnet: {} },
abi: [event0, event1],
blocks: [
[16370000, 16370020],
[16370040, 16370060],
],
},
},
});

const { sources } = await buildConfigAndIndexingFunctions({
config,
rawIndexingFunctions: [{ name: "a:Event0", fn: () => {} }],
});

expect(sources).toHaveLength(2);
});

test("buildConfigAndIndexingFunctions() account source", async () => {
Expand All @@ -596,8 +640,7 @@ test("buildConfigAndIndexingFunctions() account source", async () => {
a: {
network: { mainnet: {} },
address: address1,
startBlock: 16370000,
endBlock: 16370020,
blocks: [16370000, 16370020],
},
},
});
Expand Down Expand Up @@ -636,8 +679,7 @@ test("buildConfigAndIndexingFunctions() block source", async () => {
blocks: {
a: {
network: { mainnet: {} },
startBlock: 16370000,
endBlock: 16370020,
blocks: [16370000, 16370020],
},
},
});
Expand Down
Loading
Loading