Skip to content

Commit

Permalink
fix(simpledao): reject invalid voting options
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Nov 6, 2024
1 parent 538ebff commit a83adca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/simpledao/propstore.gno
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (p *proposal) Render() string {
output += ufmt.Sprintf("Status: %s", p.Status().String())
output += "\n\n"
output += ufmt.Sprintf(
"Voting stats: YAY %d (%d%%), NAY %d (%d%%), ABSTAIN %d (%d%%), HAVEN'T VOTED %d (%d%%)",
"Voting stats: YES %d (%d%%), NO %d (%d%%), ABSTAIN %d (%d%%), MISSING VOTE %d (%d%%)",
stats.YayVotes,
stats.YayPercent(),
stats.NayVotes,
Expand Down
7 changes: 5 additions & 2 deletions examples/gno.land/p/demo/simpledao/votestore.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package simpledao

import (
"errors"
"strings"

"gno.land/p/demo/avl"
"gno.land/p/demo/dao"
Expand Down Expand Up @@ -39,13 +40,15 @@ func (t *tally) castVote(member membstore.Member, option dao.VoteOption) error {
}

// Update the tally
switch option {
switch strings.ToUpper(option) {
case dao.YesVote:
t.yays += member.VotingPower
case dao.AbstainVote:
t.abstains += member.VotingPower
default:
case dao.NoVote:
t.nays += member.VotingPower
default:
panic("invalid voting option: " + option)
}

// Save the voting status
Expand Down

0 comments on commit a83adca

Please sign in to comment.