dexorder
This commit is contained in:
29
lib_openzeppelin_contracts/test/helpers/txpool.js
Normal file
29
lib_openzeppelin_contracts/test/helpers/txpool.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const { network } = require('hardhat');
|
||||
const { expect } = require('chai');
|
||||
const { mine } = require('@nomicfoundation/hardhat-network-helpers');
|
||||
|
||||
const { unique } = require('./iterate');
|
||||
|
||||
async function batchInBlock(txs) {
|
||||
try {
|
||||
// disable auto-mining
|
||||
await network.provider.send('evm_setAutomine', [false]);
|
||||
// send all transactions
|
||||
const responses = await Promise.all(txs.map(fn => fn()));
|
||||
// mine one block
|
||||
await mine();
|
||||
// fetch receipts
|
||||
const receipts = await Promise.all(responses.map(response => response.wait()));
|
||||
// Sanity check, all tx should be in the same block
|
||||
expect(unique(receipts.map(receipt => receipt.blockNumber))).to.have.lengthOf(1);
|
||||
// return responses
|
||||
return receipts;
|
||||
} finally {
|
||||
// enable auto-mining
|
||||
await network.provider.send('evm_setAutomine', [true]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
batchInBlock,
|
||||
};
|
||||
Reference in New Issue
Block a user