Skip to content

Commit

Permalink
use cached getSigners() in fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Oct 13, 2023
1 parent 5d5a150 commit 300fa1e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) {
require(path.join(__dirname, 'hardhat', f));
}

const withOptimizations = argv.gas || argv.compileMode === 'production';
const withOptimizations = argv.gas || argv.coverage || argv.compileMode === 'production';

/**
* @type import('hardhat/config').HardhatUserConfig
Expand Down Expand Up @@ -101,7 +101,7 @@ module.exports = {
},
networks: {
hardhat: {
blockGasLimit: 10000000,
blockGasLimit: !argv.coverage ? 30_000_000 : 1_000_000_000_000_000,
allowUnlimitedContractSize: !withOptimizations,
},
},
Expand Down
3 changes: 2 additions & 1 deletion hardhat/env-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// - the return of hre.ethers.getSigners()
extendEnvironment(hre => {
// override hre.ethers.getSigner()
// note that we don't just discard the first signer, we also cache the value to improve speed.
const originalGetSigners = hre.ethers.getSigners;
const filteredSignersAsPromise = originalGetSigners().then(signers => signers.slice(1));
hre.ethers.getSigners = () => filteredSignersAsPromise;
Expand All @@ -30,7 +31,7 @@ extendEnvironment(hre => {
await snapshot.restore();
});

body(accounts.slice(1), filteredSignersAsPromise);
body(accounts.slice(1));
});
};
});
12 changes: 6 additions & 6 deletions test/access/Ownable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ const { ethers } = require('hardhat');
const { expect } = require('chai');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');

contract('Ownable', function (_, signersAsPromise) {
async function fixture() {
const [owner, other] = await signersAsPromise;
const ownable = await ethers.deployContract('$Ownable', [owner]);
return { owner, other, ownable };
}
async function fixture() {
const [owner, other] = await ethers.getSigners();
const ownable = await ethers.deployContract('$Ownable', [owner]);
return { owner, other, ownable };
}

contract('Ownable', function () {
beforeEach(async function () {
Object.assign(this, await loadFixture(fixture));
});
Expand Down
24 changes: 12 additions & 12 deletions test/access/Ownable2Step.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ const { ethers } = require('hardhat');
const { expect } = require('chai');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');

contract('Ownable2Step', function (_, signersAsPromise) {
async function fixture() {
const [owner, accountA, accountB] = await signersAsPromise;
const ownable2Step = await ethers.deployContract('$Ownable2Step', [owner]);
return {
ownable2Step,
owner,
accountA,
accountB,
};
}

async function fixture() {
const [owner, accountA, accountB] = await ethers.getSigners();
const ownable2Step = await ethers.deployContract('$Ownable2Step', [owner]);
return {
ownable2Step,
owner,
accountA,
accountB,
};
}

contract('Ownable2Step', function () {
beforeEach(async function () {
Object.assign(this, await loadFixture(fixture));
});
Expand Down

0 comments on commit 300fa1e

Please sign in to comment.