Skip to content

Commit d11c3cb

Browse files
committed
Add tests
1 parent 8d218ae commit d11c3cb

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

testmodule/providers/jsonrpc/testJsonRpcSigner.nim

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,3 @@ suite "JsonRpcSigner":
8484
transaction.chainId = 0xdeadbeef.u256.some
8585
expect SignerError:
8686
discard await signer.populateTransaction(transaction)
87-
88-
test "concurrent populate calls increment nonce":
89-
let signer = provider.getSigner()
90-
let count = await signer.getTransactionCount(BlockTag.pending)
91-
var transaction1 = Transaction.example
92-
var transaction2 = Transaction.example
93-
var transaction3 = Transaction.example
94-
95-
let populated = await allFinished(
96-
signer.populateTransaction(transaction1),
97-
signer.populateTransaction(transaction2),
98-
signer.populateTransaction(transaction3)
99-
)
100-
101-
transaction1 = await populated[0]
102-
transaction2 = await populated[1]
103-
transaction3 = await populated[2]
104-
105-
check !transaction1.nonce == count
106-
check !transaction2.nonce == count + 1.u256
107-
check !transaction3.nonce == count + 2.u256

testmodule/testContracts.nim

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,44 @@ for url in ["ws://" & providerUrl, "http://" & providerUrl]:
272272
.confirm(1)
273273

274274
check receipt.status == TransactionStatus.Success
275+
276+
test "can cancel procs that execute transactions":
277+
let signer = provider.getSigner()
278+
let token = TestToken.new(token.address, signer)
279+
let countBefore = await signer.getTransactionCount(BlockTag.pending)
280+
281+
proc executeTx {.async.} =
282+
discard await token.mint(accounts[0], 100.u256)
283+
284+
await executeTx().cancelAndWait()
285+
let countAfter = await signer.getTransactionCount(BlockTag.pending)
286+
check countBefore == countAfter
287+
288+
test "concurrent transactions succeed even if one is cancelled":
289+
let signer = provider.getSigner()
290+
let token = TestToken.new(token.address, signer)
291+
let balanceBefore = await token.myBalance()
292+
293+
proc executeTx: Future[Confirmable] {.async.} =
294+
return await token.mint(accounts[0], 100.u256)
295+
296+
proc executeTxWithCancellation: Future[Confirmable] {.async.} =
297+
let fut = token.mint(accounts[0], 100.u256)
298+
fut.cancelSoon()
299+
return await fut
300+
301+
# emulate concurrent populateTransaction/sendTransaction calls, where the
302+
# first one fails
303+
let futs = await allFinished(
304+
executeTxWithCancellation(),
305+
executeTx(),
306+
executeTx()
307+
)
308+
let receipt1 = await futs[1].confirm(0)
309+
let receipt2 = await futs[2].confirm(0)
310+
311+
check receipt1.status == TransactionStatus.Success
312+
check receipt2.status == TransactionStatus.Success
313+
314+
let balanceAfter = await token.myBalance()
315+
check balanceAfter == balanceBefore + 200.u256

0 commit comments

Comments
 (0)