-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contracts can be unintenionally mocked when snapshots are used #178
Comments
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? |
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 |
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 |
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.The text was updated successfully, but these errors were encountered: