Skip to content

Commit

Permalink
Test duplicated paralel transactions (#301)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
renancloudwalk authored Mar 3, 2024
1 parent f321624 commit 3cc3f6e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion e2e/test/e2e-tx-parallel-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number> = {};
expectedBalances[ALICE.address] = 0;
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 3cc3f6e

Please sign in to comment.