From ccb2c146f64322108c3217d2f34e6eb52af7e72e Mon Sep 17 00:00:00 2001 From: 0xmad <0xmad@users.noreply.github.com> Date: Tue, 19 Mar 2024 13:16:41 -0500 Subject: [PATCH] fix(contracts): use for-loop instead of async promise --- contracts/tests/MACI.test.ts | 56 +++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/contracts/tests/MACI.test.ts b/contracts/tests/MACI.test.ts index 854fba5c69..38b80f39ed 100644 --- a/contracts/tests/MACI.test.ts +++ b/contracts/tests/MACI.test.ts @@ -80,36 +80,38 @@ describe("MACI", () => { it("should sign up multiple users", async () => { const iface = maciContract.interface; - await Promise.all( - users.map(async (user, index) => { - const tx = await maciContract.signUp( - user.pubKey.asContractParam(), - AbiCoder.defaultAbiCoder().encode(["uint256"], [1]), - AbiCoder.defaultAbiCoder().encode(["uint256"], [0]), - signUpTxOpts, - ); - const receipt = await tx.wait(); - expect(receipt?.status).to.eq(1); - - // Store the state index - const log = receipt!.logs[receipt!.logs.length - 1]; - const event = iface.parseLog(log as unknown as { topics: string[]; data: string }) as unknown as { - args: { - _stateIndex: BigNumberish; - _voiceCreditBalance: BigNumberish; - _timestamp: BigNumberish; - }; + for (let index = 0; index < users.length; index += 1) { + const user = users[index]; + + // eslint-disable-next-line no-await-in-loop + const tx = await maciContract.signUp( + user.pubKey.asContractParam(), + AbiCoder.defaultAbiCoder().encode(["uint256"], [1]), + AbiCoder.defaultAbiCoder().encode(["uint256"], [0]), + signUpTxOpts, + ); + // eslint-disable-next-line no-await-in-loop + const receipt = await tx.wait(); + expect(receipt?.status).to.eq(1); + + // Store the state index + const log = receipt!.logs[receipt!.logs.length - 1]; + const event = iface.parseLog(log as unknown as { topics: string[]; data: string }) as unknown as { + args: { + _stateIndex: BigNumberish; + _voiceCreditBalance: BigNumberish; + _timestamp: BigNumberish; }; + }; - expect(event.args._stateIndex.toString()).to.eq((index + 1).toString()); + expect(event.args._stateIndex.toString()).to.eq((index + 1).toString()); - maciState.signUp( - user.pubKey, - BigInt(event.args._voiceCreditBalance.toString()), - BigInt(event.args._timestamp.toString()), - ); - }), - ); + maciState.signUp( + user.pubKey, + BigInt(event.args._voiceCreditBalance.toString()), + BigInt(event.args._timestamp.toString()), + ); + } }); it("should fail when given an invalid pubkey", async () => {