test maximum votes count

This commit is contained in:
Patryk Osmaczko 2023-07-11 13:46:53 +02:00
parent 7ae7245c6b
commit b88eea7fe7
2 changed files with 21 additions and 4 deletions

View File

@ -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);

View File

@ -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))