Skip to content

Commit

Permalink
fix(simpledao): reject invalid voting options (#3077)
Browse files Browse the repository at this point in the history
<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
</details>
  • Loading branch information
thehowl authored Nov 6, 2024
1 parent 724ffc9 commit 9dad8f1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 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
8 changes: 7 additions & 1 deletion 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 @@ -38,14 +39,19 @@ func (t *tally) castVote(member membstore.Member, option dao.VoteOption) error {
return ErrAlreadyVoted
}

// convert option to upper-case, like the constants are.
option = dao.VoteOption(strings.ToUpper(string(option)))

// Update the tally
switch 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
6 changes: 3 additions & 3 deletions examples/gno.land/r/gov/dao/v2/prop1_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func main() {
//
// Status: active
//
// Voting stats: YAY 0 (0%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 10 (100%)
// Voting stats: YES 0 (0%), NO 0 (0%), ABSTAIN 0 (0%), MISSING VOTE 10 (100%)
//
// Threshold met: false
//
Expand All @@ -99,7 +99,7 @@ func main() {
//
// Status: accepted
//
// Voting stats: YAY 10 (100%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 0 (0%)
// Voting stats: YES 10 (100%), NO 0 (0%), ABSTAIN 0 (0%), MISSING VOTE 0 (0%)
//
// Threshold met: true
//
Expand All @@ -116,7 +116,7 @@ func main() {
//
// Status: execution successful
//
// Voting stats: YAY 10 (100%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 0 (0%)
// Voting stats: YES 10 (100%), NO 0 (0%), ABSTAIN 0 (0%), MISSING VOTE 0 (0%)
//
// Threshold met: true
//
Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/r/gov/dao/v2/prop2_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func main() {
//
// Status: active
//
// Voting stats: YAY 0 (0%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 10 (100%)
// Voting stats: YES 0 (0%), NO 0 (0%), ABSTAIN 0 (0%), MISSING VOTE 10 (100%)
//
// Threshold met: false
//
Expand All @@ -76,7 +76,7 @@ func main() {
//
// Status: accepted
//
// Voting stats: YAY 10 (100%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 0 (0%)
// Voting stats: YES 10 (100%), NO 0 (0%), ABSTAIN 0 (0%), MISSING VOTE 0 (0%)
//
// Threshold met: true
//
Expand All @@ -95,7 +95,7 @@ func main() {
//
// Status: execution successful
//
// Voting stats: YAY 10 (100%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 0 (0%)
// Voting stats: YES 10 (100%), NO 0 (0%), ABSTAIN 0 (0%), MISSING VOTE 0 (0%)
//
// Threshold met: true
//
Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/r/gov/dao/v2/prop3_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func main() {
//
// Status: active
//
// Voting stats: YAY 0 (0%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 10 (100%)
// Voting stats: YES 0 (0%), NO 0 (0%), ABSTAIN 0 (0%), MISSING VOTE 10 (100%)
//
// Threshold met: false
//
Expand All @@ -90,7 +90,7 @@ func main() {
//
// Status: accepted
//
// Voting stats: YAY 10 (100%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 0 (0%)
// Voting stats: YES 10 (100%), NO 0 (0%), ABSTAIN 0 (0%), MISSING VOTE 0 (0%)
//
// Threshold met: true
//
Expand All @@ -108,7 +108,7 @@ func main() {
//
// Status: execution successful
//
// Voting stats: YAY 10 (25%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 30 (75%)
// Voting stats: YES 10 (25%), NO 0 (0%), ABSTAIN 0 (0%), MISSING VOTE 30 (75%)
//
// Threshold met: false
//
Expand Down

0 comments on commit 9dad8f1

Please sign in to comment.