Skip to content

Commit

Permalink
fix(x/gov): disable spam vote in optimisic proposal (#19407)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Feb 12, 2024
1 parent 89df28c commit 313a989
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
2 changes: 0 additions & 2 deletions x/gov/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
sidebar_position: 1
---

<!--- TODO(@julienrbrt), describe spam votes and vote options changes -->

# `x/gov`

## Abstract
Expand Down
25 changes: 0 additions & 25 deletions x/gov/keeper/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,31 +994,6 @@ func TestTally_Optimistic(t *testing.T) {
SpamCount: "0",
},
},
{
name: "spam votes: prop fails/burn deposit",
setup: func(s tallyFixture) {
setTotalBonded(s, 10000000)
validatorVote(s, s.valAddrs[1], v1.VoteOption_VOTE_OPTION_SPAM)
validatorVote(s, s.valAddrs[2], v1.VoteOption_VOTE_OPTION_SPAM)
validatorVote(s, s.valAddrs[3], v1.VoteOption_VOTE_OPTION_SPAM)
validatorVote(s, s.valAddrs[4], v1.VoteOption_VOTE_OPTION_SPAM)
validatorVote(s, s.valAddrs[5], v1.VoteOption_VOTE_OPTION_SPAM)
validatorVote(s, s.valAddrs[6], v1.VoteOption_VOTE_OPTION_SPAM)
},
expectedPass: false,
expectedBurn: true,
expectedTally: v1.TallyResult{
YesCount: "0",
AbstainCount: "0",
NoCount: "0",
NoWithVetoCount: "0",
OptionOneCount: "0",
OptionTwoCount: "0",
OptionThreeCount: "0",
OptionFourCount: "0",
SpamCount: "6000000",
},
},
{
name: "one delegator votes: threshold no not reached, prop passes",
setup: func(s tallyFixture) {
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (k Keeper) AddVote(ctx context.Context, proposalID uint64, voterAddr sdk.Ac
for _, option := range options {
switch proposal.ProposalType {
case v1.ProposalType_PROPOSAL_TYPE_OPTIMISTIC:
if option.Option != v1.OptionNo && option.Option != v1.OptionSpam {
if option.Option != v1.OptionNo {
return errors.Wrap(types.ErrInvalidVote, "optimistic proposals can only be rejected")
}
case v1.ProposalType_PROPOSAL_TYPE_MULTIPLE_CHOICE:
Expand Down
25 changes: 25 additions & 0 deletions x/gov/keeper/vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,31 @@ func TestVotes(t *testing.T) {
require.ErrorIs(t, err, collections.ErrNotFound)
}

func TestVotes_Optimisic(t *testing.T) {
govKeeper, mocks, _, ctx := setupGovKeeper(t)
authKeeper, bankKeeper, stakingKeeper := mocks.acctKeeper, mocks.bankKeeper, mocks.stakingKeeper
addrs := simtestutil.AddTestAddrsIncremental(bankKeeper, stakingKeeper, ctx, 2, sdkmath.NewInt(10000000))
authKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()

proposal, err := govKeeper.SubmitProposal(ctx, nil, "", "title", "description", sdk.AccAddress("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"), v1.ProposalType_PROPOSAL_TYPE_OPTIMISTIC)
require.NoError(t, err)

proposal.Status = v1.StatusVotingPeriod
require.NoError(t, govKeeper.Proposals.Set(ctx, proposal.Id, proposal))

proposalID := proposal.Id

// invalid options
require.Error(t, govKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(invalidOption), ""), "invalid option")
require.Error(t, govKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionYes), ""), "invalid option")
require.Error(t, govKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionAbstain), "invalid option"))
require.Error(t, govKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionNoWithVeto), ""), "invalid option")
require.Error(t, govKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionSpam), ""), "invalid option")

// valid options
require.NoError(t, govKeeper.AddVote(ctx, proposalID, addrs[0], v1.NewNonSplitVoteOption(v1.OptionNo), ""))
}

func TestVotes_MultipleChoiceProposal(t *testing.T) {
govKeeper, mocks, _, ctx := setupGovKeeper(t)
authKeeper, bankKeeper, stakingKeeper := mocks.acctKeeper, mocks.bankKeeper, mocks.stakingKeeper
Expand Down

0 comments on commit 313a989

Please sign in to comment.