mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-03 22:23:06 +00:00
Add tests
This commit is contained in:
parent
b460535447
commit
0240203513
@ -84,24 +84,3 @@ suite "JsonRpcSigner":
|
||||
transaction.chainId = 0xdeadbeef.u256.some
|
||||
expect SignerError:
|
||||
discard await signer.populateTransaction(transaction)
|
||||
|
||||
test "concurrent populate calls increment nonce":
|
||||
let signer = provider.getSigner()
|
||||
let count = await signer.getTransactionCount(BlockTag.pending)
|
||||
var transaction1 = Transaction.example
|
||||
var transaction2 = Transaction.example
|
||||
var transaction3 = Transaction.example
|
||||
|
||||
let populated = await allFinished(
|
||||
signer.populateTransaction(transaction1),
|
||||
signer.populateTransaction(transaction2),
|
||||
signer.populateTransaction(transaction3)
|
||||
)
|
||||
|
||||
transaction1 = await populated[0]
|
||||
transaction2 = await populated[1]
|
||||
transaction3 = await populated[2]
|
||||
|
||||
check !transaction1.nonce == count
|
||||
check !transaction2.nonce == count + 1.u256
|
||||
check !transaction3.nonce == count + 2.u256
|
||||
|
||||
@ -272,3 +272,44 @@ for url in ["ws://" & providerUrl, "http://" & providerUrl]:
|
||||
.confirm(1)
|
||||
|
||||
check receipt.status == TransactionStatus.Success
|
||||
|
||||
test "can cancel procs that execute transactions":
|
||||
let signer = provider.getSigner()
|
||||
let token = TestToken.new(token.address, signer)
|
||||
let countBefore = await signer.getTransactionCount(BlockTag.pending)
|
||||
|
||||
proc executeTx {.async.} =
|
||||
discard await token.mint(accounts[0], 100.u256)
|
||||
|
||||
await executeTx().cancelAndWait()
|
||||
let countAfter = await signer.getTransactionCount(BlockTag.pending)
|
||||
check countBefore == countAfter
|
||||
|
||||
test "concurrent transactions succeed even if one is cancelled":
|
||||
let signer = provider.getSigner()
|
||||
let token = TestToken.new(token.address, signer)
|
||||
let balanceBefore = await token.myBalance()
|
||||
|
||||
proc executeTx: Future[Confirmable] {.async.} =
|
||||
return await token.mint(accounts[0], 100.u256)
|
||||
|
||||
proc executeTxWithCancellation: Future[Confirmable] {.async.} =
|
||||
let fut = token.mint(accounts[0], 100.u256)
|
||||
fut.cancelSoon()
|
||||
return await fut
|
||||
|
||||
# emulate concurrent populateTransaction/sendTransaction calls, where the
|
||||
# first one fails
|
||||
let futs = await allFinished(
|
||||
executeTxWithCancellation(),
|
||||
executeTx(),
|
||||
executeTx()
|
||||
)
|
||||
let receipt1 = await futs[1].confirm(0)
|
||||
let receipt2 = await futs[2].confirm(0)
|
||||
|
||||
check receipt1.status == TransactionStatus.Success
|
||||
check receipt2.status == TransactionStatus.Success
|
||||
|
||||
let balanceAfter = await token.myBalance()
|
||||
check balanceAfter == balanceBefore + 200.u256
|
||||
Loading…
x
Reference in New Issue
Block a user