Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(contracts): use for-loop instead of async promise #1318

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions contracts/tests/MACI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Loading