From 4205aaf4b4870ae7c6c402f231dbe6fb40aedaad Mon Sep 17 00:00:00 2001 From: John Letey Date: Fri, 18 Nov 2022 10:08:54 +0100 Subject: [PATCH 1/4] fix: correctly propagate msg errors in gov --- x/gov/abci.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x/gov/abci.go b/x/gov/abci.go index 79efc725bfe7..a19762be44be 100644 --- a/x/gov/abci.go +++ b/x/gov/abci.go @@ -72,7 +72,9 @@ func EndBlocker(ctx sdk.Context, keeper *keeper.Keeper) { if err == nil { for idx, msg = range messages { handler := keeper.Router().Handler(msg) - res, err := handler(cacheCtx, msg) + + var res *sdk.Result + res, err = handler(cacheCtx, msg) if err != nil { break } From f866c66a23a2de12f1c22cc791f79a1fdafda489 Mon Sep 17 00:00:00 2001 From: John Letey Date: Fri, 18 Nov 2022 11:44:12 +0100 Subject: [PATCH 2/4] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f3b8fa5f145..f6a275d62a2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -195,6 +195,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf * (snapshot) [#13400](https://github.com/cosmos/cosmos-sdk/pull/13400) Fix snapshot checksum issue in golang 1.19. * (server) [#13778](https://github.com/cosmos/cosmos-sdk/pull/13778) Set Cosmos SDK default endpoints to localhost to avoid unknown exposure of endpoints. * (x/auth) [#13877](https://github.com/cosmos/cosmos-sdk/pull/13877) Handle missing account numbers during `InitGenesis`. +* (x/gov) [#13918](https://github.com/cosmos/cosmos-sdk/pull/13918) Fix propagation of message errors when executing a proposal. ### Deprecated From e288b1cf027441890be46af48c708bdf6aff44e5 Mon Sep 17 00:00:00 2001 From: John Letey Date: Fri, 18 Nov 2022 16:20:16 +0100 Subject: [PATCH 3/4] fix: correctly check proposal status in tests --- x/gov/abci_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/x/gov/abci_test.go b/x/gov/abci_test.go index bf7432feed96..86860e5c46da 100644 --- a/x/gov/abci_test.go +++ b/x/gov/abci_test.go @@ -11,6 +11,8 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/gov/keeper" "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -347,10 +349,8 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) { createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10}) staking.EndBlocker(ctx, suite.StakingKeeper) - // Create a proposal where the handler will pass for the test proposal - // because the value of contextKeyBadProposal is true. - ctx = ctx.WithValue(contextKeyBadProposal, true) - proposal, err := suite.GovKeeper.SubmitProposal(ctx, []sdk.Msg{mkTestLegacyContent(t)}, "") + msg := banktypes.NewMsgSend(authtypes.NewModuleAddress(types.ModuleName), addrs[0], sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000)))) + proposal, err := suite.GovKeeper.SubmitProposal(ctx, []sdk.Msg{msg}, "") require.NoError(t, err) proposalCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, suite.StakingKeeper.TokensFromConsensusPower(ctx, 10))) @@ -368,12 +368,12 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) { newHeader.Time = ctx.BlockHeader().Time.Add(*suite.GovKeeper.GetParams(ctx).MaxDepositPeriod).Add(*suite.GovKeeper.GetParams(ctx).VotingPeriod) ctx = ctx.WithBlockHeader(newHeader) - // Set the contextKeyBadProposal value to false so that the handler will fail - // during the processing of the proposal in the EndBlocker. - ctx = ctx.WithValue(contextKeyBadProposal, false) - // validate that the proposal fails/has been rejected gov.EndBlocker(ctx, suite.GovKeeper) + + proposal, ok := suite.GovKeeper.GetProposal(ctx, proposal.Id) + require.True(t, ok) + require.Equal(t, v1.StatusFailed, proposal.Status) } func createValidators(t *testing.T, stakingMsgSvr stakingtypes.MsgServer, ctx sdk.Context, addrs []sdk.ValAddress, powerAmt []int64) { From 84843beb1b9c9a46170fd22120cd7b46dd5b9acc Mon Sep 17 00:00:00 2001 From: John Letey Date: Fri, 18 Nov 2022 16:26:22 +0100 Subject: [PATCH 4/4] chore: delete unused var --- x/gov/common_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/gov/common_test.go b/x/gov/common_test.go index ca3512f4b255..6bca2818cb83 100644 --- a/x/gov/common_test.go +++ b/x/gov/common_test.go @@ -91,8 +91,6 @@ func SortByteArrays(src [][]byte) [][]byte { return sorted } -const contextKeyBadProposal = "contextKeyBadProposal" - var pubkeys = []cryptotypes.PubKey{ ed25519.GenPrivKey().PubKey(), ed25519.GenPrivKey().PubKey(),