Skip to content

Commit

Permalink
fix: race condition on zksync tests (#199)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* refactor: Update contracts/zksync/test/main.test.ts

Co-authored-by: Santos Rosati <[email protected]>

---------

Co-authored-by: Santos Rosati <[email protected]>
  • Loading branch information
uri-99 and taturosati authored Mar 27, 2024
1 parent a38119b commit 8484591
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion contracts/zksync/deploy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/zksync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 8 additions & 18 deletions contracts/zksync/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ beforeEach( async () => {
escrow = await deployAndInit();
});

// /*
// working:::

describe('Pause tests', function () {

it("Should start unpaused", async function () {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8484591

Please sign in to comment.