NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.28k stars 1.41k forks source link

Improve experience of mixing hardhat_reset and fixtures #4151

Open fvictorio opened 1 year ago

fvictorio commented 1 year ago

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:

zdenham commented 1 year ago

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).

Saty248 commented 1 year ago

hi @fvictorio ,am working on this issue..

  1. 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.

  1. 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?

julianmrodri commented 10 months ago

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)
  ...