test: regression test on VotingPeriodProposalKey deletion (#15368)

## Description

Follow up to #15356 adding a test in which we activate the voting period, delete the proposal and try to vote in the deleted proposal (this vote would have passed before and now it gets rejected).



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Facundo Medica 2023-03-14 06:40:23 -03:00 committed by GitHub
parent 721c24a1ae
commit 0282cfe71e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,6 +95,55 @@ func (suite *KeeperTestSuite) TestActivateVotingPeriod() {
proposalID := types.GetProposalIDFromBytes(activeIterator.Value())
suite.Require().Equal(proposalID, proposal.Id)
activeIterator.Close()
// delete the proposal to avoid issues with other tests
suite.Require().NotPanics(func() {
suite.govKeeper.DeleteProposal(suite.ctx, proposalID)
}, "")
}
}
func (suite *KeeperTestSuite) TestDeleteProposalInVotingPeriod() {
testCases := []struct {
name string
expedited bool
}{
{name: "regular proposal"},
{name: "expedited proposal", expedited: true},
}
for _, tc := range testCases {
suite.reset()
tp := TestProposal
proposal, err := suite.govKeeper.SubmitProposal(suite.ctx, tp, "", "test", "summary", sdk.AccAddress("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"), tc.expedited)
suite.Require().NoError(err)
suite.Require().Nil(proposal.VotingStartTime)
suite.govKeeper.ActivateVotingPeriod(suite.ctx, proposal)
proposal, ok := suite.govKeeper.GetProposal(suite.ctx, proposal.Id)
suite.Require().True(ok)
suite.Require().True(proposal.VotingStartTime.Equal(suite.ctx.BlockHeader().Time))
activeIterator := suite.govKeeper.ActiveProposalQueueIterator(suite.ctx, *proposal.VotingEndTime)
suite.Require().True(activeIterator.Valid())
proposalID := types.GetProposalIDFromBytes(activeIterator.Value())
suite.Require().Equal(proposalID, proposal.Id)
activeIterator.Close()
// add vote
voteOptions := []*v1.WeightedVoteOption{{Option: v1.OptionYes, Weight: "1.0"}}
err = suite.govKeeper.AddVote(suite.ctx, proposal.Id, sdk.AccAddress("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"), voteOptions, "")
suite.Require().NoError(err)
suite.Require().NotPanics(func() {
suite.govKeeper.DeleteProposal(suite.ctx, proposalID)
}, "")
// add vote but proposal is deleted along with its VotingPeriodProposalKey
err = suite.govKeeper.AddVote(suite.ctx, proposal.Id, sdk.AccAddress("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r"), voteOptions, "")
suite.Require().ErrorContains(err, ": inactive proposal")
}
}