From 3cc3f6ebcb9069bf8d898635320deda358afa4c4 Mon Sep 17 00:00:00 2001 From: renancloudwalk <53792026+renancloudwalk@users.noreply.github.com> Date: Sun, 3 Mar 2024 10:56:01 -0300 Subject: [PATCH] Test duplicated paralel transactions (#301) * fix: keep block number on execution * lint * chore: make performance tests use postgres * fix: services order on performance testing * fix: remove broken syntax * chore: test duplicated paralel transactions --- e2e/test/e2e-tx-parallel-contract.test.ts | 24 ++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/e2e/test/e2e-tx-parallel-contract.test.ts b/e2e/test/e2e-tx-parallel-contract.test.ts index 86ad63630..f1a85caa3 100644 --- a/e2e/test/e2e-tx-parallel-contract.test.ts +++ b/e2e/test/e2e-tx-parallel-contract.test.ts @@ -29,7 +29,7 @@ describe("Transaction: parallel TestContractBalances", async () => { expect(await _contract.get(CHARLIE.address)).eq(0); }); - it("Sends parallel transactions", async () => { + it("Sends parallel transactions to aggregate value", async () => { // prepare transactions const expectedBalances: Record = {}; expectedBalances[ALICE.address] = 0; @@ -67,6 +67,28 @@ describe("Transaction: parallel TestContractBalances", async () => { expect(await _contract.get(BOB.address)).eq(expectedBalances[BOB.address]); expect(await _contract.get(CHARLIE.address)).eq(expectedBalances[CHARLIE.address]); }); + + it("Sends parallel transactions that should have one success and one fail due to lack of balance", async () => { + expect(await _contract.get(BOB.address)).eq(625); + + const signedTxsSub = []; + + for (let i = 0; i < 2; i++) { + const nonce = await sendGetNonce(ALICE.address); + const tx = await _contract.connect(ALICE.signer()).sub.populateTransaction(BOB.address, 600, { + nonce: nonce, + ...TX_PARAMS, + }); + + signedTxsSub.push(await ALICE.signer().signTransaction(tx)); + } + + const result = await sendRawTransactions(signedTxsSub); + + // only one transaction should be successful + expect(await _contract.get(BOB.address)).eq(25); + expect(result[1]).eq(undefined); + }); }); describe("Transaction: parallel TestContractCounter", async () => {