mirror of
https://github.com/status-im/snt-voting.git
synced 2025-02-23 23:58:13 +00:00
Fix: voters counter wasn't updated correctly
This commit is contained in:
parent
38c1fa2844
commit
28553030d2
@ -205,11 +205,11 @@ contract PollManager is Controlled {
|
|||||||
|
|
||||||
if(p.voters == 0) return;
|
if(p.voters == 0) return;
|
||||||
|
|
||||||
p.voters--;
|
uint prevVotes = 0;
|
||||||
|
|
||||||
for(uint8 i = 0; i < p.numBallots; i++){
|
for(uint8 i = 0; i < p.numBallots; i++){
|
||||||
uint ballotAmount = p.ballots[i][msg.sender];
|
uint ballotAmount = p.ballots[i][msg.sender];
|
||||||
|
|
||||||
|
prevVotes += ballotAmount;
|
||||||
p.ballots[i][msg.sender] = 0;
|
p.ballots[i][msg.sender] = 0;
|
||||||
|
|
||||||
if(ballotAmount != 0){
|
if(ballotAmount != 0){
|
||||||
@ -218,6 +218,10 @@ contract PollManager is Controlled {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(prevVotes != 0){
|
||||||
|
p.voters--;
|
||||||
|
}
|
||||||
|
|
||||||
emit Unvote(_idPoll, msg.sender);
|
emit Unvote(_idPoll, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +133,10 @@ describe("VotingDapp", function () {
|
|||||||
it("More than 1 user should be able to vote", async() => {
|
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]});
|
const receipt = await PollManager.methods.vote(pollId, [decimals(4), decimals(4), decimals(1)]).send({from: accounts[2]});
|
||||||
assert(!!receipt.events.Vote, "Vote not triggered");
|
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 () => {
|
it("Voting when you're not a SNT holder SHOULD FAIL!", async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user