Reset Hardhat Network before each test suite (#4652)

This commit is contained in:
Francisco
2023-10-04 20:00:02 -03:00
committed by GitHub
parent 0560576c7a
commit f92dce51ed

View File

@ -2,9 +2,24 @@ extendEnvironment(env => {
const { contract } = env; const { contract } = env;
env.contract = function (name, body) { env.contract = function (name, body) {
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 // remove the default account from the accounts list used in tests, in order
// to protect tests against accidentally passing due to the contract // to protect tests against accidentally passing due to the contract
// deployer being used subsequently as function caller // deployer being used subsequently as function caller
contract(name, accounts => body(accounts.slice(1))); body(accounts.slice(1));
});
}; };
}); });