Skip to content

Commit d961aef

Browse files
authored
fix(x/gov): grpc query tally for failed proposal (#19725)
1 parent d808ef8 commit d961aef

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
8585

8686
### Bug Fixes
8787

88+
* (x/gov) [#19725](https://github.com/cosmos/cosmos-sdk/pull/19725) Fetch a failed proposal tally from proposal.FinalTallyResult in the gprc query.
8889
* (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.
8990
* (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.
9091
* (client/keys) [#18562](https://github.com/cosmos/cosmos-sdk/pull/18562) `keys delete` won't terminate when a key is not found.

x/gov/keeper/grpc_query.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func (q queryServer) TallyResult(ctx context.Context, req *v1.QueryTallyResultRe
319319
case proposal.Status == v1.StatusDepositPeriod:
320320
tallyResult = v1.EmptyTallyResult()
321321

322-
case proposal.Status == v1.StatusPassed || proposal.Status == v1.StatusRejected:
322+
case proposal.Status == v1.StatusPassed || proposal.Status == v1.StatusRejected || proposal.Status == v1.StatusFailed:
323323
tallyResult = *proposal.FinalTallyResult
324324

325325
default:

x/gov/keeper/grpc_query_test.go

+75
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,48 @@ func (suite *KeeperTestSuite) TestGRPCQueryTallyResult() {
16401640
},
16411641
true,
16421642
},
1643+
{
1644+
"proposal status failed",
1645+
func() {
1646+
propTime := time.Now()
1647+
proposal := v1.Proposal{
1648+
Id: 1,
1649+
Status: v1.StatusFailed,
1650+
FinalTallyResult: &v1.TallyResult{
1651+
YesCount: "4",
1652+
AbstainCount: "1",
1653+
NoCount: "0",
1654+
NoWithVetoCount: "0",
1655+
OptionOneCount: "4",
1656+
OptionTwoCount: "1",
1657+
OptionThreeCount: "0",
1658+
OptionFourCount: "0",
1659+
SpamCount: "0",
1660+
},
1661+
SubmitTime: &propTime,
1662+
VotingStartTime: &propTime,
1663+
VotingEndTime: &propTime,
1664+
Metadata: "proposal metadata",
1665+
}
1666+
err := suite.govKeeper.Proposals.Set(suite.ctx, proposal.Id, proposal)
1667+
suite.Require().NoError(err)
1668+
1669+
req = &v1.QueryTallyResultRequest{ProposalId: proposal.Id}
1670+
1671+
expTally = &v1.TallyResult{
1672+
YesCount: "4",
1673+
AbstainCount: "1",
1674+
NoCount: "0",
1675+
NoWithVetoCount: "0",
1676+
OptionOneCount: "4",
1677+
OptionTwoCount: "1",
1678+
OptionThreeCount: "0",
1679+
OptionFourCount: "0",
1680+
SpamCount: "0",
1681+
}
1682+
},
1683+
true,
1684+
},
16431685
}
16441686

16451687
for _, tc := range testCases {
@@ -1781,6 +1823,39 @@ func (suite *KeeperTestSuite) TestLegacyGRPCQueryTallyResult() {
17811823
},
17821824
true,
17831825
},
1826+
{
1827+
"proposal status failed",
1828+
func() {
1829+
propTime := time.Now()
1830+
proposal := v1.Proposal{
1831+
Id: 1,
1832+
Status: v1.StatusFailed,
1833+
FinalTallyResult: &v1.TallyResult{
1834+
YesCount: "4",
1835+
AbstainCount: "1",
1836+
NoCount: "0",
1837+
NoWithVetoCount: "0",
1838+
SpamCount: "0",
1839+
},
1840+
SubmitTime: &propTime,
1841+
VotingStartTime: &propTime,
1842+
VotingEndTime: &propTime,
1843+
Metadata: "proposal metadata",
1844+
}
1845+
err := suite.govKeeper.Proposals.Set(suite.ctx, proposal.Id, proposal)
1846+
suite.Require().NoError(err)
1847+
1848+
req = &v1beta1.QueryTallyResultRequest{ProposalId: proposal.Id}
1849+
1850+
expTally = &v1beta1.TallyResult{
1851+
Yes: math.NewInt(4),
1852+
Abstain: math.NewInt(1),
1853+
No: math.NewInt(0),
1854+
NoWithVeto: math.NewInt(0),
1855+
}
1856+
},
1857+
true,
1858+
},
17841859
}
17851860

17861861
for _, tc := range testCases {

0 commit comments

Comments
 (0)