Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(x/gov): grpc query tally for failed proposal (backport #19725) #19727

Merged
merged 3 commits into from
Mar 12, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### 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.
* (types) [#19709](https://github.com/cosmos/cosmos-sdk/pull/19709) Fix skip staking genesis export when using `CoreAppModuleAdaptor` / `CoreAppModuleBasicAdaptor` for it.
* (x/auth) [#19549](https://github.com/cosmos/cosmos-sdk/pull/19549) Accept custom get signers when injecting `x/auth/tx`.
* (x/staking) Fix a possible bypass of delegator slashing: [GHSA-86h5-xcpx-cfqc](https://github.com/cosmos/cosmos-sdk/security/advisories/GHSA-86h5-xcpx-cfqc)
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 @@ -260,7 +260,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
64 changes: 64 additions & 0 deletions x/gov/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,38 @@ 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",
},
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",
}
},
true,
},
}

for _, testCase := range testCases {
Expand Down Expand Up @@ -1696,6 +1728,38 @@ 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",
},
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 _, testCase := range testCases {
Expand Down
Loading