Skip to content

Instantly share code, notes, and snippets.

@ylv-io
Created April 20, 2021 18:36
Show Gist options
  • Save ylv-io/62be8cde2fc15153ff4717037998e210 to your computer and use it in GitHub Desktop.
Save ylv-io/62be8cde2fc15153ff4717037998e210 to your computer and use it in GitHub Desktop.
/**
* Can't await on transactionSend because it will never resolve due to
* automine disabled. Save a promise instead and resolve it later.
* Should set gasLimit on txs because default gasLimit is blockGasLimit.
* promise = signer.sendTransaction({
* to: signer.address,
* value: 1,
* });
* const txReceipt = await promise;
* @param {func} Lambda to run within the same block.
*/
async function mineInBlock(lambda) {
await ethers.provider.send('evm_setAutomine', [false]);
await lambda();
await ethers.provider.send('evm_mine');
await ethers.provider.send('evm_setAutomine', [true]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment