Skip to content

Commit

Permalink
Reset Hardhat Network before each test suite (#4652)
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio authored Oct 4, 2023
1 parent 0560576 commit f92dce5
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions hardhat/env-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@ extendEnvironment(env => {
const { contract } = env;

env.contract = function (name, body) {
// remove the default account from the accounts list used in tests, in order
// to protect tests against accidentally passing due to the contract
// deployer being used subsequently as function caller
contract(name, accounts => body(accounts.slice(1)));
const { takeSnapshot } = require('@nomicfoundation/hardhat-network-helpers');

contract(name, accounts => {
// reset the state of the chain in between contract test suites
let snapshot;

before(async function () {
snapshot = await takeSnapshot();
});

after(async function () {
await snapshot.restore();
});

// remove the default account from the accounts list used in tests, in order
// to protect tests against accidentally passing due to the contract
// deployer being used subsequently as function caller
body(accounts.slice(1));
});
};
});

0 comments on commit f92dce5

Please sign in to comment.