Skip to content

Commit 1e5d699

Browse files
committed
Set proper fromBlock value to avoid tests hanging on fork mode
1 parent 3c7131d commit 1e5d699

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.changeset/brave-falcons-reply.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Fix example tests hanging when running on fork mode ([#6967](https://github.com/NomicFoundation/hardhat/pull/7120))

v-next/hardhat/templates/01-node-test-runner-viem/test/Counter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ describe("Counter", async function () {
7171
});
7272

7373
it("The sum of the Increment events should match the current value", async function () {
74+
const startBlockNumber = await publicClient.getBlockNumber();
7475
const counter = await viem.deployContract("Counter");
7576

7677
// run a series of increments
@@ -82,7 +83,7 @@ describe("Counter", async function () {
8283
address: counter.address,
8384
abi: counter.abi,
8485
eventName: "Increment",
85-
fromBlock: 0n,
86+
fromBlock: startBlockNumber,
8687
strict: true,
8788
});
8889

v-next/hardhat/templates/02-mocha-ethers/test/Counter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe("Counter", function () {
5252
});
5353

5454
it("The sum of the Increment events should match the current value", async function () {
55+
const startBlockNumber = await ethers.provider.getBlockNumber();
5556
const counter = await ethers.deployContract("Counter");
5657

5758
// run a series of increments
@@ -61,7 +62,7 @@ describe("Counter", function () {
6162

6263
const events = await counter.queryFilter(
6364
counter.filters.Increment(),
64-
0,
65+
startBlockNumber,
6566
"latest",
6667
);
6768

0 commit comments

Comments
 (0)