forked from OpenZeppelin/openzeppelin-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for improved coverage (OpenZeppelin#3448)
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
- Loading branch information
Showing
9 changed files
with
81 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const { network } = require('hardhat'); | ||
const { promisify } = require('util'); | ||
|
||
const queue = promisify(setImmediate); | ||
|
||
async function countPendingTransactions () { | ||
return parseInt( | ||
await network.provider.send('eth_getBlockTransactionCountByNumber', ['pending']), | ||
); | ||
} | ||
|
||
async function batchInBlock (txs) { | ||
try { | ||
// disable auto-mining | ||
await network.provider.send('evm_setAutomine', [false]); | ||
// send all transactions | ||
const promises = txs.map(fn => fn()); | ||
// wait for node to have all pending transactions | ||
while (txs.length > await countPendingTransactions()) { | ||
await queue(); | ||
} | ||
// mine one block | ||
await network.provider.send('evm_mine'); | ||
// fetch receipts | ||
const receipts = await Promise.all(promises); | ||
// Sanity check, all tx should be in the same block | ||
const minedBlocks = new Set(receipts.map(({ receipt }) => receipt.blockNumber)); | ||
expect(minedBlocks.size).to.equal(1); | ||
|
||
return receipts; | ||
} finally { | ||
// enable auto-mining | ||
await network.provider.send('evm_setAutomine', [true]); | ||
} | ||
} | ||
|
||
module.exports = { | ||
countPendingTransactions, | ||
batchInBlock, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters