txpool.js 889 B

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