From 8484591a96cb695f8747ac9efe1b59c4e68439f3 Mon Sep 17 00:00:00 2001 From: urimihura <43704209+uri-99@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:53:29 -0300 Subject: [PATCH] fix: race condition on zksync tests (#199) * fix: read emited events in zksync tests * fix: workaround for nonce used twice + hardhat not using network flag * fix: test back to dockerizedNode mode * refactor: Update contracts/zksync/test/main.test.ts Co-authored-by: Santos Rosati * refactor: Update contracts/zksync/test/main.test.ts Co-authored-by: Santos Rosati --------- Co-authored-by: Santos Rosati --- contracts/zksync/deploy/utils.ts | 2 +- contracts/zksync/package.json | 2 +- contracts/zksync/test/main.test.ts | 26 ++++++++------------------ 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/contracts/zksync/deploy/utils.ts b/contracts/zksync/deploy/utils.ts index bffc4f1c..f63e2715 100644 --- a/contracts/zksync/deploy/utils.ts +++ b/contracts/zksync/deploy/utils.ts @@ -15,7 +15,7 @@ export const getProvider = () => { if (!rpcUrl) throw `⛔️ RPC URL wasn't found in "${hre.network.name}"! Please add a "url" field to the network config in hardhat.config.ts`; // Initialize zkSync Provider - const provider = new Provider(rpcUrl); + const provider = new Provider(rpcUrl, undefined, {cacheTimeout: -1}); return provider; } diff --git a/contracts/zksync/package.json b/contracts/zksync/package.json index 5dd5554d..7acf0377 100644 --- a/contracts/zksync/package.json +++ b/contracts/zksync/package.json @@ -7,7 +7,7 @@ "deploy-devnet": "hardhat deploy-zksync --network dockerizedNode --script deploy.ts", "compile": "hardhat compile", "clean": "hardhat clean", - "test": "hardhat test --network dockerizedNode --parallel --show-stack-traces" + "test": "hardhat test --network dockerizedNode --show-stack-traces" }, "devDependencies": { "@matterlabs/hardhat-zksync-deploy": "^1.1.2", diff --git a/contracts/zksync/test/main.test.ts b/contracts/zksync/test/main.test.ts index fff4259f..960cc416 100644 --- a/contracts/zksync/test/main.test.ts +++ b/contracts/zksync/test/main.test.ts @@ -18,8 +18,7 @@ beforeEach( async () => { escrow = await deployAndInit(); }); -// /* -// working::: + describe('Pause tests', function () { it("Should start unpaused", async function () { @@ -62,31 +61,22 @@ describe('Pause tests', function () { }); }); -// */ -// // working :: + describe('Set Order tests', function () { it("Should emit correct Event", async () => { - let events = await escrow.queryFilter("*"); - const events_length = events.length; - const setOrderTx = await escrow.connect(user_zk).set_order(user_eth, fee, {value}); - await setOrderTx.wait(); - - events = await escrow.queryFilter("*"); - expect(events.length).to.equal(events_length + 1); - expect(events[events.length - 1].fragment.name).to.equal("SetOrder"); + + await expect(setOrderTx) + .to.emit(escrow, "SetOrder").withArgs(0, user_eth, value-fee, fee) }); it("Should get the order setted", async () => { const setOrderTx = await escrow.connect(user_zk).set_order(user_eth, fee, {value}); - await setOrderTx.wait(); - - let events = await escrow.queryFilter("*"); - const newOrderEvent = events[events.length - 1]; - const orderId = newOrderEvent.args[0]; + await expect(setOrderTx) + .to.emit(escrow, "SetOrder").withArgs(0, user_eth, value-fee, fee) - const newOrder = await escrow.get_order(orderId); + const newOrder = await escrow.get_order(0); expect(newOrder[0]).to.eq(user_eth.address); //recipient_address expect(Number(newOrder[1])).to.eq(value-fee); //amount