Fix: voters counter wasn't updated correctly

This commit is contained in:
Richard Ramos 2018-10-01 08:58:40 -04:00
parent 38c1fa2844
commit 28553030d2
2 changed files with 10 additions and 2 deletions

View File

@ -205,11 +205,11 @@ contract PollManager is Controlled {
if(p.voters == 0) return;
p.voters--;
uint prevVotes = 0;
for(uint8 i = 0; i < p.numBallots; i++){
uint ballotAmount = p.ballots[i][msg.sender];
prevVotes += ballotAmount;
p.ballots[i][msg.sender] = 0;
if(ballotAmount != 0){
@ -218,6 +218,10 @@ contract PollManager is Controlled {
}
}
if(prevVotes != 0){
p.voters--;
}
emit Unvote(_idPoll, msg.sender);
}

View File

@ -133,6 +133,10 @@ describe("VotingDapp", function () {
it("More than 1 user should be able to vote", async() => {
const receipt = await PollManager.methods.vote(pollId, [decimals(4), decimals(4), decimals(1)]).send({from: accounts[2]});
assert(!!receipt.events.Vote, "Vote not triggered");
const poll = await PollManager.methods.poll(pollId).call();
assert.equal(poll._voters, 2, "Invalid number of voters");
});
it("Voting when you're not a SNT holder SHOULD FAIL!", async () => {