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
(cherry picked from commit d961aef)

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
traviolus authored and mergify[bot] committed Mar 12, 2024
1 parent c382225 commit 084fbc7
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,22 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

<<<<<<< HEAD
* (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)
=======
* (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.
* (baseapp) [#18383](https://github.com/cosmos/cosmos-sdk/pull/18383) Fixed a data race inside BaseApp.getContext, found by end-to-end (e2e) tests.
* (client/server) [#18345](https://github.com/cosmos/cosmos-sdk/pull/18345) Consistently set viper prefix in client and server. It defaults for the binary name for both client and server.
* (simulation) [#17911](https://github.com/cosmos/cosmos-sdk/pull/17911) Fix all problems with executing command `make test-sim-custom-genesis-fast` for simulation test.
* (simulation) [#18196](https://github.com/cosmos/cosmos-sdk/pull/18196) Fix the problem of `validator set is empty after InitGenesis` in simulation test.
* (baseapp) [#18551](https://github.com/cosmos/cosmos-sdk/pull/18551) Fix SelectTxForProposal the calculation method of tx bytes size is inconsistent with CometBFT
* (server) [#18994](https://github.com/cosmos/cosmos-sdk/pull/18994) Update server context directly rather than a reference to a sub-object
>>>>>>> d961aef76 (fix(x/gov): grpc query tally for failed proposal (#19725))
## [v0.50.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.4) - 2024-02-19

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
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 @@ -1560,6 +1560,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",

Check failure on line 1575 in x/gov/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / Analyze

unknown field OptionOneCount in struct literal of type "github.com/cosmos/cosmos-sdk/x/gov/types/v1".TallyResult
OptionTwoCount: "1",

Check failure on line 1576 in x/gov/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / Analyze

unknown field OptionTwoCount in struct literal of type "github.com/cosmos/cosmos-sdk/x/gov/types/v1".TallyResult
OptionThreeCount: "0",

Check failure on line 1577 in x/gov/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / Analyze

unknown field OptionThreeCount in struct literal of type "github.com/cosmos/cosmos-sdk/x/gov/types/v1".TallyResult
OptionFourCount: "0",

Check failure on line 1578 in x/gov/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / Analyze

unknown field OptionFourCount in struct literal of type "github.com/cosmos/cosmos-sdk/x/gov/types/v1".TallyResult
SpamCount: "0",

Check failure on line 1579 in x/gov/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / Analyze

unknown field SpamCount in struct literal of type "github.com/cosmos/cosmos-sdk/x/gov/types/v1".TallyResult
},
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",

Check failure on line 1596 in x/gov/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / Analyze

unknown field OptionOneCount in struct literal of type "github.com/cosmos/cosmos-sdk/x/gov/types/v1".TallyResult
OptionTwoCount: "1",

Check failure on line 1597 in x/gov/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / Analyze

unknown field OptionTwoCount in struct literal of type "github.com/cosmos/cosmos-sdk/x/gov/types/v1".TallyResult
OptionThreeCount: "0",

Check failure on line 1598 in x/gov/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / Analyze

unknown field OptionThreeCount in struct literal of type "github.com/cosmos/cosmos-sdk/x/gov/types/v1".TallyResult
OptionFourCount: "0",

Check failure on line 1599 in x/gov/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / Analyze

unknown field OptionFourCount in struct literal of type "github.com/cosmos/cosmos-sdk/x/gov/types/v1".TallyResult
SpamCount: "0",

Check failure on line 1600 in x/gov/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / Analyze

unknown field SpamCount in struct literal of type "github.com/cosmos/cosmos-sdk/x/gov/types/v1".TallyResult
}
},
true,
},
}

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

0 comments on commit 084fbc7

Please sign in to comment.