Reset or move a fork
reset() on a forked node re-forks at its fork block, discarding local changes.
Back to the fork block
await fork.cheats.dealErc20(token, HOLDER, 0n).mine(10);
await fork.reset();
expect(await fork.testClient.getBlockNumber()).toBe(forkBlock);
expect(await balanceOf(fork.testClient, token, HOLDER)).toBe(
parseEther("1000000"),
);
Tested in examples/test/e2e/forking.e2e.test.ts:133
Another block
await fork.reset({ blockNumber: forkBlock + 1n });
expect(await balanceOf(fork.testClient, token, HOLDER)).toBe(
parseEther("1000000") + 1n, // now includes the later mint
);
Tested in examples/test/e2e/forking.e2e.test.ts:159
reset({ jsonRpcUrl }) re-forks from another URL.
Another endpoint
const backup = network.urlOf(mainnet, "mainnet-backup");
await fork.cheats.setRpcUrl(backup); // e.g. fail over to another provider
expect((await fork.nodeInfo()).forkConfig.forkUrl).toBe(backup);
await fork.reset(); // re-forks through the new endpoint
expect(await balanceOf(fork.testClient, token, HOLDER)).toBe(
parseEther("1000000"),
);
Tested in examples/test/e2e/forking.e2e.test.ts:146
reset() discards snapshots: don't combine it with useAnvil()'s per-test
isolation in one file (Reset the chain).