Skip to content

Commit a83adca

Browse files
committed
fix(simpledao): reject invalid voting options
1 parent 538ebff commit a83adca

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

examples/gno.land/p/demo/simpledao/propstore.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (p *proposal) Render() string {
7171
output += ufmt.Sprintf("Status: %s", p.Status().String())
7272
output += "\n\n"
7373
output += ufmt.Sprintf(
74-
"Voting stats: YAY %d (%d%%), NAY %d (%d%%), ABSTAIN %d (%d%%), HAVEN'T VOTED %d (%d%%)",
74+
"Voting stats: YES %d (%d%%), NO %d (%d%%), ABSTAIN %d (%d%%), MISSING VOTE %d (%d%%)",
7575
stats.YayVotes,
7676
stats.YayPercent(),
7777
stats.NayVotes,

examples/gno.land/p/demo/simpledao/votestore.gno

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package simpledao
22

33
import (
44
"errors"
5+
"strings"
56

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

4142
// Update the tally
42-
switch option {
43+
switch strings.ToUpper(option) {
4344
case dao.YesVote:
4445
t.yays += member.VotingPower
4546
case dao.AbstainVote:
4647
t.abstains += member.VotingPower
47-
default:
48+
case dao.NoVote:
4849
t.nays += member.VotingPower
50+
default:
51+
panic("invalid voting option: " + option)
4952
}
5053

5154
// Save the voting status

0 commit comments

Comments
 (0)