Move `confirm()` override into contract module
And simplify its test
This commit is contained in:
parent
4e4a55b13e
commit
09810e73ff
|
@ -234,3 +234,21 @@ proc subscribe*[E: Event](contract: Contract,
|
|||
handler(event)
|
||||
|
||||
contract.provider.subscribe(filter, logHandler)
|
||||
|
||||
proc confirm*(tx: Future[?TransactionResponse],
|
||||
confirmations: int = EthersDefaultConfirmations,
|
||||
timeout: int = EthersReceiptTimeoutBlks):
|
||||
Future[TransactionReceipt] {.async.} =
|
||||
## Convenience method that allows confirm to be chained to a contract
|
||||
## transaction, eg:
|
||||
## `await token.connect(signer0)
|
||||
## .mint(accounts[1], 100.u256)
|
||||
## .confirm(3)`
|
||||
|
||||
without response =? (await tx):
|
||||
raise newException(
|
||||
EthersError,
|
||||
"Transaction hash required. Possibly was a call instead of a send?"
|
||||
)
|
||||
|
||||
return await response.confirm(confirmations, timeout)
|
||||
|
|
|
@ -158,23 +158,5 @@ proc confirm*(tx: Future[TransactionResponse],
|
|||
let txResp = await tx
|
||||
return await txResp.confirm(confirmations, timeout)
|
||||
|
||||
proc confirm*(tx: Future[?TransactionResponse],
|
||||
confirmations: int = EthersDefaultConfirmations,
|
||||
timeout: int = EthersReceiptTimeoutBlks):
|
||||
Future[TransactionReceipt] {.async.} =
|
||||
## Convenience method that allows wait to be chained to a contract
|
||||
## transaction, eg:
|
||||
## `await token.connect(signer0)
|
||||
## .mint(accounts[1], 100.u256)
|
||||
## .confirm(3)`
|
||||
|
||||
without txResp =? (await tx):
|
||||
raise newException(
|
||||
EthersError,
|
||||
"Transaction hash required. Possibly was a call instead of a send?"
|
||||
)
|
||||
|
||||
return await txResp.confirm(confirmations, timeout)
|
||||
|
||||
method close*(provider: Provider) {.async, base.} =
|
||||
discard
|
||||
|
|
|
@ -181,20 +181,11 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]:
|
|||
check transfers.len == 1
|
||||
|
||||
test "can wait for contract interaction tx to be mined":
|
||||
# must not be awaited so we can get newHeads inside of .wait
|
||||
let futMined = provider.mineBlocks(10)
|
||||
|
||||
let signer0 = provider.getSigner(accounts[0])
|
||||
let receipt = await token.connect(signer0)
|
||||
let confirming = token.connect(signer0)
|
||||
.mint(accounts[1], 100.u256)
|
||||
.confirm(3) # wait for 3 confirmations
|
||||
let endBlock = await provider.getBlockNumber()
|
||||
|
||||
check receipt.blockNumber.isSome # was eventually mined
|
||||
|
||||
# >= 3 because more blocks may have been mined by the time the
|
||||
# check in `.wait` was done.
|
||||
# +1 for the block the tx was mined in
|
||||
check (endBlock - !receipt.blockNumber) + 1 >= 3
|
||||
|
||||
await futMined
|
||||
.confirm(3)
|
||||
await sleepAsync(100.millis) # wait for tx to be mined
|
||||
await provider.mineBlocks(2) # two additional blocks
|
||||
let receipt = await confirming
|
||||
check receipt.blockNumber.isSome
|
||||
|
|
Loading…
Reference in New Issue