@@ -272,3 +272,44 @@ for url in ["ws://" & providerUrl, "http://" & providerUrl]:
272
272
.confirm (1 )
273
273
274
274
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