Closed pabloes closed 2 years ago
If you use confirm
right after mocking the transaction and before interacting with your app/library, it should resolve "immediately":
https://github.com/DePayFi/web3-mock#mock-transaction-confirmations
import { mock, confirm } from '@depay/web3-mock'
let mockedTransaction = mock({
blockchain: 'ethereum',
transaction: {
to: "0x5Af489c8786A018EC4814194dC8048be1007e390",
value: '1000000000000000000'
}
})
confirm(mockedTransaction)
await sentTransaction.wait(1).then(function(receipt){
//... will be executed once confirm is called
})
But some EVM clients like ethers or web3 never "immediately" resolve this due to the async nature of wait()
.
I see with wait(1) it resolves immediatelly, but not with any number >1, sorry for not being specific.
In following example, taken from confirmations.spec.js, it takes like 4 seconds to resolve, I need to resolve it immediatelly. So I guess I would need to find a way to emulate the nature of this wait maybe by wrapping it with custom function.
increaseBlock(12)
let waitedFor12Confirmations;
console.time();
await sentTransaction.wait(12).then(function(receipt){
transactionReceipt = receipt
waitedFor12Confirmations = true
})
console.timeEnd();
ethersjs
does internally try to precompute the approximate time it will take before requesting a block update: https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/base-provider.ts#L1203
Hence you can't speed it up.
Here are the 4 seconds you're waiting for ;)
https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/base-provider.ts#L794
Try to set the provider.pollingInterval
of your etherjs: https://github.com/ethers-io/ethers.js/issues/186#issuecomment-393418416
amazing , thx a lot, provider.pollingInterval = 1;
did the trick;
Is there a way that when calling increaseBlock, or any other method, emulates that the block is mined and transaction.wait(1) is immediatelly resolved?