Skip to content

Commit

Permalink
fix(x/gov): grpc query tally for failed proposal (#19725)
Browse files Browse the repository at this point in the history
  • Loading branch information
traviolus authored Mar 12, 2024
1 parent d808ef8 commit d961aef
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

### Bug Fixes

* (x/gov) [#19725](https://github.com/cosmos/cosmos-sdk/pull/19725) Fetch a failed proposal tally from proposal.FinalTallyResult in the gprc query.
* (baseapp) [#18727](https://github.com/cosmos/cosmos-sdk/pull/18727) Ensure that `BaseApp.Init` firstly returns any errors from a nil commit multistore instead of panicking on nil dereferencing and before sealing the app.
* (client) [#18622](https://github.com/cosmos/cosmos-sdk/pull/18622) Fixed a potential under/overflow from `uint64->int64` when computing gas fees as a LegacyDec.
* (client/keys) [#18562](https://github.com/cosmos/cosmos-sdk/pull/18562) `keys delete` won't terminate when a key is not found.
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (q queryServer) TallyResult(ctx context.Context, req *v1.QueryTallyResultRe
case proposal.Status == v1.StatusDepositPeriod:
tallyResult = v1.EmptyTallyResult()

case proposal.Status == v1.StatusPassed || proposal.Status == v1.StatusRejected:
case proposal.Status == v1.StatusPassed || proposal.Status == v1.StatusRejected || proposal.Status == v1.StatusFailed:
tallyResult = *proposal.FinalTallyResult

default:
Expand Down
75 changes: 75 additions & 0 deletions x/gov/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,48 @@ func (suite *KeeperTestSuite) TestGRPCQueryTallyResult() {
},
true,
},
{
"proposal status failed",
func() {
propTime := time.Now()
proposal := v1.Proposal{
Id: 1,
Status: v1.StatusFailed,
FinalTallyResult: &v1.TallyResult{
YesCount: "4",
AbstainCount: "1",
NoCount: "0",
NoWithVetoCount: "0",
OptionOneCount: "4",
OptionTwoCount: "1",
OptionThreeCount: "0",
OptionFourCount: "0",
SpamCount: "0",
},
SubmitTime: &propTime,
VotingStartTime: &propTime,
VotingEndTime: &propTime,
Metadata: "proposal metadata",
}
err := suite.govKeeper.Proposals.Set(suite.ctx, proposal.Id, proposal)
suite.Require().NoError(err)

req = &v1.QueryTallyResultRequest{ProposalId: proposal.Id}

expTally = &v1.TallyResult{
YesCount: "4",
AbstainCount: "1",
NoCount: "0",
NoWithVetoCount: "0",
OptionOneCount: "4",
OptionTwoCount: "1",
OptionThreeCount: "0",
OptionFourCount: "0",
SpamCount: "0",
}
},
true,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -1781,6 +1823,39 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryTallyResult() {
},
true,
},
{
"proposal status failed",
func() {
propTime := time.Now()
proposal := v1.Proposal{
Id: 1,
Status: v1.StatusFailed,
FinalTallyResult: &v1.TallyResult{
YesCount: "4",
AbstainCount: "1",
NoCount: "0",
NoWithVetoCount: "0",
SpamCount: "0",
},
SubmitTime: &propTime,
VotingStartTime: &propTime,
VotingEndTime: &propTime,
Metadata: "proposal metadata",
}
err := suite.govKeeper.Proposals.Set(suite.ctx, proposal.Id, proposal)
suite.Require().NoError(err)

req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.Id}

expTally = &v1beta1.TallyResult{
Yes: math.NewInt(4),
Abstain: math.NewInt(1),
No: math.NewInt(0),
NoWithVeto: math.NewInt(0),
}
},
true,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit d961aef

Please sign in to comment.