Open fvictorio opened 1 year ago
Thanks @fvictorio for sharing the bug details! This is definitely not a fix, but maybe a workaround, can u confirm if the error persists if some hardhat contract is deployed before the snapshot?
can u confirm if the error persists if some hardhat contract is deployed before the snapshot
What do you mean? Before the first snapshot? Or before the first revert?
before the first snapshot, i suffered this issue and got it solved by deploying literally contract DumbContract{}
before making any snapshot and it seemed to work ok, i'm just curious why, maybe you'll be more able to detect it.
Same behavior if I do this:
await ethers.deployContract("Dummy");
const snapshotId = await network.provider.send("evm_snapshot")
If I do this instead, it works:
const snapshotId = await network.provider.send("evm_snapshot")
await ethers.deployContract("Dummy");
But that's because this changes the nonce of the deployer, and so both Foo
contracts have different addresses.
Describe the bug If you use snapshots and smock, a non-mocked contract in one test can accidentally get the mocked behavior from a previous test.
Reproduction steps
Consider this contract:
and these tests:
If you run it, the second test will log
1
instead of the expected42
.Expected behavior Newly deployed contracts don't have their functions mocked, even if their address match the address of a previously deployed and mocked contract.
Additional context See this issue in Hardhat's repo.
Possible solutions I'm not sure what's the right solution here, but some ideas:
hardhat_revert
is called. We emit an event in the provider when this happens, so you should be able to listen for it.