hardhat
hardhat copied to clipboard
Improve experience of mixing hardhat_reset and fixtures
If you use fixtures and hardhat_reset
, you will likely run into an error like:
FixtureSnapshotError: There was an error reverting the snapshot of the fixture.
This might be caused by using nested loadFixture calls in a test, for example by using multiple beforeEach calls. This is not supported yet.
That message is misleading, and also a lie: we support nested loadFixture calls now.
Two things to do here:
- Update that error message
- Check if there's an easy way to detect that there was a reset and act accordingly (just clear the fixtures array in that case I guess?)
I'm also seeing this issue with fixtures + hardhat_reset
on any test, our workaround was to run this test which required rest without fixtures (and separately from the rest of our tests with fixtures).
hi @fvictorio ,am working on this issue..
- first of all ,in my pr, am changing the the error message to
There was an error reverting the snapshot of the fixture.
This might be caused by using hardhat_reset and loadFixture calls in a testcase.
- what we also can do is, when hardhat_reset is called, we create a function at the loadFixtures which sets the fixtures array to empty.
any thoughts about this idea?
I think Im facing this issue!
What is strange in my case is that i works locally but not in CI. When the test runs in Github actions I get: What could be the reason Im only seeing the error in CI? Is there a workaround?
I do not have nested beforeEach, but I do a network reset and then a beforeEach that deploys a lot of contracts, and performs impersonation, etc.
FixtureSnapshotError: There was an error reverting the snapshot of the fixture.
This might be caused by using nested loadFixture calls in a test, for example by using multiple beforeEach calls. This is not supported yet.
at loadFixture (/home/runner/work/protocol/protocol/node_modules/@nomicfoundation/hardhat-network-helpers/src/loadFixture.ts:51:15)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at runNextTicks (node:internal/process/task_queues:65:3)
at processImmediate (node:internal/timers:437:9)
at async Context.<anonymous> (/home/runner/work/protocol/protocol/test/integration/FacadeMonitorNew.test.ts:159:9)
Caused by: InvalidSnapshotError: Trying to restore an invalid snapshot.
at Object.restore (/home/runner/work/protocol/protocol/node_modules/@nomicfoundation/hardhat-network-helpers/src/helpers/takeSnapshot.ts:46:15)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at runNextTicks (node:internal/process/task_queues:65:3)
at processImmediate (node:internal/timers:437:9)
at async loadFixture (/home/runner/work/protocol/protocol/node_modules/@nomicfoundation/hardhat-network-helpers/src/loadFixture.ts:44:7)
...