Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion x/coredaos/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,12 @@ func (ms MsgServer) VetoProposal(goCtx context.Context, msg *types.MsgVetoPropos
}
proposal.Status = govtypesv1.StatusVetoed

// Since the proposal is veoted, we set the final tally result to an empty tally.
// Since the proposal is veoted, we set the final tally result to an empty tally
// and the voting period ends immediately
emptyTally := govtypesv1.EmptyTallyResult()
proposal.FinalTallyResult = &emptyTally
blockTime := ctx.BlockTime()
proposal.VotingEndTime = &blockTime
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is fine but actually the reason why a vote is possible on a vetoed proposal is due to a bug in the x/gov wrapper.

When a proposal is vetoed, the x/coredao module updates the proposal status and invokes SetProposal() on the wrapper, which calls sdkKeeper.Proposals.Set. But the wrapper should call sdkKeeper.SetProposal(), because it contains some logic regarding an other field sdkKeeper.VotingPeriodProposals. Basically if the proposal is no longer in voting period, SetProposal() removes it from sdkKeeper.VotingPeriodProposals.

This is the reason why a vote is possible on a vetoed proposal, because one of the first check that keeper.AddVote() is doing, is to verify if the proposal is present in this VotingPeriodProposals field.

I will submit an other PR to fix the wrapper.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #266


ms.k.govKeeper.SetProposal(ctx, proposal)
ms.k.govKeeper.DeleteVotes(ctx, proposal.Id)
Expand Down
12 changes: 11 additions & 1 deletion x/coredaos/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ func TestMsgServerVetoProposal(t *testing.T) {
Id: 1,
Status: govtypesv1.StatusVetoed,
FinalTallyResult: &emptyTally,
VotingEndTime: &votingEndTime,
VotingEndTime: &votingEndTime, // will be overwritten in the test
}
depositPeriodProposal := govtypesv1.Proposal{
Title: "Test Proposal",
Expand Down Expand Up @@ -751,6 +751,11 @@ func TestMsgServerVetoProposal(t *testing.T) {
ProposalId: 1,
},
setupMocks: func(ctx sdk.Context, m *testutil.Mocks) {
// ensure proposalWithVeto has the correct VotingEndTime set
// can only do it here because ctx is needed
votingEndTime := ctx.BlockTime()
proposalWithVeto.VotingEndTime = &votingEndTime

call1 := m.GovKeeper.EXPECT().GetProposal(ctx, uint64(1)).Return(votingPeriodProposal, true)
m.GovKeeper.EXPECT().RefundAndDeleteDeposits(ctx, uint64(1)).After(call1)
m.GovKeeper.EXPECT().SetProposal(ctx, proposalWithVeto).After(call1)
Expand All @@ -769,6 +774,11 @@ func TestMsgServerVetoProposal(t *testing.T) {
BurnDeposit: true,
},
setupMocks: func(ctx sdk.Context, m *testutil.Mocks) {
// ensure proposalWithVeto has the correct VotingEndTime set
// can only do it here because ctx is needed
votingEndTime := ctx.BlockTime()
proposalWithVeto.VotingEndTime = &votingEndTime

call1 := m.GovKeeper.EXPECT().GetProposal(ctx, uint64(1)).Return(votingPeriodProposal, true)
m.GovKeeper.EXPECT().DeleteAndBurnDeposits(ctx, uint64(1)).MaxTimes(1)
m.GovKeeper.EXPECT().SetProposal(ctx, proposalWithVeto).After(call1)
Expand Down
Loading