This week at a talking by our friend Patrick Collins during the Chainlink Spring 2022 Hackathon schedule, I took knowledge of the possibility of moving ahead of time on the blockchain during tests:
async moveTime(amount: number) {
console.log("Moving blocks...");
await network.provider.send("evm_increaseTime", [amount]);
console.log(`Moved forward in time ${amount} seconds`);
}
So I'm trying to use it on my tests but, from the moment I started to use it, my tests started to have this exception:
Error: nonce has already been used [ See: https://links.ethers.org/v5-errors-NONCE_EXPIRED ] (error={"name":"InvalidInputError","code":-32000,"_isProviderError":true}, method="sendTransaction", transaction="0x02f872827a69148459682f008461277a0a8401bad45894532323de74bab864b7005d910e5bd8562d038b9b8084478c7d5fc001a0e987896b237af1c098617321e8356a5dd903b834f7fe9e4188f6b5858530d263a06fce96280dc21b5d41909353ae33897f4155a3742d1deefac0f77575d9ec9151", code=NONCE_EXPIRED, version=providers/5.6.1)
I've found out a similar post with this kind of error at NONCE_EXPIRED error with ethers.js on local hardhat node and have followed the instructions about doing the snapshot but it didn't solve the problem:
before(async function () {
const accounts = waffle.provider.getWallets();
....
this.loadFixture = waffle.createFixtureLoader(accounts);
snapshot = await waffle.provider.send("evm_snapshot", []);
});
after(async function () {
await waffle.provider.send("evm_revert", [snapshot]);
});
Anyone else faced this kind of problem and succeded solving it?
IMPORTANT: The error does not happen in all execution, only when I run the tests few seconds after a previous execution.
Regards,