txpool.js 852 B

123456789101112131415161718192021222324252627
  1. const { network } = require('hardhat');
  2. const { mine } = require('@nomicfoundation/hardhat-network-helpers');
  3. const { unique } = require('./iterate');
  4. async function batchInBlock(txs) {
  5. try {
  6. // disable auto-mining
  7. await network.provider.send('evm_setAutomine', [false]);
  8. // send all transactions
  9. const responses = await Promise.all(txs.map(fn => fn()));
  10. // mine one block
  11. await mine();
  12. // fetch receipts
  13. const receipts = await Promise.all(responses.map(response => response.wait()));
  14. // Sanity check, all tx should be in the same block
  15. expect(unique(receipts.map(receipt => receipt.blockNumber))).to.have.lengthOf(1);
  16. // return responses
  17. return receipts;
  18. } finally {
  19. // enable auto-mining
  20. await network.provider.send('evm_setAutomine', [true]);
  21. }
  22. }
  23. module.exports = {
  24. batchInBlock,
  25. };