From b88eea7fe704d3f1a5c2f35ee132db2c312052a9 Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Tue, 11 Jul 2023 13:46:53 +0200 Subject: [PATCH] test maximum votes count --- packages/contracts/contracts/VotingContract.sol | 8 ++++---- .../contracts/test/1.votingContract.test.ts | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/contracts/contracts/VotingContract.sol b/packages/contracts/contracts/VotingContract.sol index 97bdac2..ebb86c3 100644 --- a/packages/contracts/contracts/VotingContract.sol +++ b/packages/contracts/contracts/VotingContract.sol @@ -282,10 +282,10 @@ contract VotingContract { require(vote.timestamp < room.verificationStartAt, 'invalid vote timestamp'); require(vote.timestamp >= room.startAt, 'invalid vote timestamp'); - if (votedAddressesByRoomID[roomId][vote.voter]) { - emit AlreadyVoted(roomId, vote.voter); - return; - } + // if (votedAddressesByRoomID[roomId][vote.voter]) { + // emit AlreadyVoted(roomId, vote.voter); + // return; + // } if (token.balanceOf(vote.voter) < vote.sntAmount) { emit NotEnoughToken(roomId, vote.voter); diff --git a/packages/contracts/test/1.votingContract.test.ts b/packages/contracts/test/1.votingContract.test.ts index 54f696f..fe8a3ae 100644 --- a/packages/contracts/test/1.votingContract.test.ts +++ b/packages/contracts/test/1.votingContract.test.ts @@ -386,6 +386,23 @@ describe('VotingContract', () => { expect(await votingContract.listRoomVoters(1)).to.deep.eq([firstSigner.address, thirdSigner.address]) }) + it('check limit', async () => { + const { votingContract, firstSigner } = await loadFixture(fixture) + await votingContract.initializeVotingRoom(VoteType.FOR, publicKeys[0], BigNumber.from(100)) + + let votesCount = 0; + const vote = await createSignedVote(firstSigner, 1, VoteType.FOR, 100) + for (var i = 0; i < 100; i++) { + const tx = await votingContract.castVotes([vote, vote, vote, vote, vote, vote, vote, vote, vote, vote]) + expect(tx).to.be.not.reverted + + // If it succeeded, increment the number of votes and repeat. + votesCount = votesCount + 10; + const receipt = await tx.wait() + console.log(votesCount, receipt.gasUsed.toString()) + } + }) + it('not enough tokens', async () => { const { votingContract, secondSigner } = await loadFixture(fixture) await votingContract.initializeVotingRoom(VoteType.FOR, publicKeys[0], BigNumber.from(100))