Skip to content

Commit b69bb7f

Browse files
authored
Merge pull request #7120 from NomicFoundation/test_hangs_on_fork_mode
Set proper fromBlock value to avoid tests hanging on fork mode
2 parents 8035b5e + 260cbc6 commit b69bb7f

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/hardhat-3/01-node-test-runner-viem/test/Counter.ts

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

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

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

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

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

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

5758
// run a series of increments
5859
for (let i = 1; i <= 10; i++) {
@@ -61,7 +62,7 @@ describe("Counter", function () {
6162

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

0 commit comments

Comments
 (0)