Skip to content

Commit 2f92d5f

Browse files
authored
Change the way blocks are mined during testing (#554)
- For the default local network, disable automining, so transactions will not trigger a mined block, and instead they will only be mined every 30 seconds - For the unit tests, enable automining and disable the mining interval. - An additional small change: we allow passing file paths to yarn test so that we can optionally run only specific testfiles.
1 parent 87a2468 commit 2f92d5f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const config: HardhatUserConfig = {
125125
mnemonic: DEFAULT_TEST_MNEMONIC,
126126
},
127127
mining: {
128-
auto: true,
128+
auto: false,
129129
interval: 30000,
130130
},
131131
hardfork: 'london',

scripts/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fi
4141
mkdir -p reports
4242

4343
# Run using the standalone evm instance
44-
npx hardhat test --network hardhat
44+
npx hardhat test --network hardhat $@
4545

4646
### Cleanup
4747

test/lib/fixtures.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { utils, Wallet, Signer } from 'ethers'
33

44
import * as deployment from './deployment'
5-
import { evmSnapshot, evmRevert } from './testHelpers'
5+
import { evmSnapshot, evmRevert, provider } from './testHelpers'
66

77
export class NetworkFixture {
88
lastSnapshotId: number
@@ -16,6 +16,12 @@ export class NetworkFixture {
1616
slasher: Signer = Wallet.createRandom() as Signer,
1717
arbitrator: Signer = Wallet.createRandom() as Signer,
1818
): Promise<any> {
19+
// Enable automining with each transaction, and disable
20+
// the mining interval. Individual tests may modify this
21+
// behavior as needed.
22+
provider().send('evm_setIntervalMining', [0])
23+
provider().send('evm_setAutomine', [true])
24+
1925
// Roles
2026
const arbitratorAddress = await arbitrator.getAddress()
2127
const slasherAddress = await slasher.getAddress()

0 commit comments

Comments
 (0)