From f1cf30ac4f15fc966f945e32ad61c905c1c392e2 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 23 Dec 2022 01:03:23 +0100 Subject: [PATCH] feat(gov): support v1.Proposal in v1beta1.Proposal.Content (backport #14347) (#14400) --- CHANGELOG.md | 4 ++++ x/gov/migrations/v3/convert_test.go | 26 +++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 916213bc7a7d..765297a9cadb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements + +* (x/gov) [#14347](https://github.com/cosmos/cosmos-sdk/pull/14347) Support `v1.Proposal` message in `v1beta1.Proposal.Content`. + ## [v0.46.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.7) - 2022-12-13 ### Features diff --git a/x/gov/migrations/v3/convert_test.go b/x/gov/migrations/v3/convert_test.go index ff93e5474873..55cf715f9ff6 100644 --- a/x/gov/migrations/v3/convert_test.go +++ b/x/gov/migrations/v3/convert_test.go @@ -14,6 +14,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" + v046 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v046" + v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/stretchr/testify/require" ) func TestConvertToLegacyProposal(t *testing.T) { @@ -60,10 +65,10 @@ func TestConvertToLegacyProposal(t *testing.T) { require.Equal(t, v1beta1Proposal.VotingEndTime, *proposal.VotingEndTime) require.Equal(t, v1beta1Proposal.SubmitTime, *proposal.SubmitTime) require.Equal(t, v1beta1Proposal.DepositEndTime, *proposal.DepositEndTime) - require.Equal(t, v1beta1Proposal.FinalTallyResult.Yes, math.NewInt(0)) - require.Equal(t, v1beta1Proposal.FinalTallyResult.No, math.NewInt(0)) - require.Equal(t, v1beta1Proposal.FinalTallyResult.NoWithVeto, math.NewInt(0)) - require.Equal(t, v1beta1Proposal.FinalTallyResult.Abstain, math.NewInt(0)) + require.Equal(t, v1beta1Proposal.FinalTallyResult.Yes, sdk.NewInt(0)) + require.Equal(t, v1beta1Proposal.FinalTallyResult.No, sdk.NewInt(0)) + require.Equal(t, v1beta1Proposal.FinalTallyResult.NoWithVeto, sdk.NewInt(0)) + require.Equal(t, v1beta1Proposal.FinalTallyResult.Abstain, sdk.NewInt(0)) tp, ok := v1beta1Proposal.Content.GetCachedValue().(*v1beta1.TextProposal) require.Truef(t, ok, "expected *TextProposal, got %T", v1beta1Proposal.Content.GetCachedValue()) require.Equal(t, tp.Title, "title") @@ -74,7 +79,7 @@ func TestConvertToLegacyProposal(t *testing.T) { } func TestConvertToLegacyProposalContent(t *testing.T) { - msg := v1.MsgCancelProposal{ProposalId: 1, Proposer: "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"} + msg := upgradetypes.MsgSoftwareUpgrade{Authority: "gov module", Plan: upgradetypes.Plan{Name: "test upgrade"}} msgsAny, err := tx.SetMsgs([]sdk.Msg{&msg}) require.NoError(t, err) tallyResult := v1.EmptyTallyResult() @@ -86,24 +91,23 @@ func TestConvertToLegacyProposalContent(t *testing.T) { FinalTallyResult: &tallyResult, } - legacyP, err := v3.ConvertToLegacyProposal(proposal) + legacyP, err := v046.ConvertToLegacyProposal(proposal) require.NoError(t, err) - tp, ok := legacyP.Content.GetCachedValue().(*v1.MsgCancelProposal) - require.Truef(t, ok, "expected *MsgCancelProposal, got %T", legacyP.Content.GetCachedValue()) + tp, ok := legacyP.Content.GetCachedValue().(*upgradetypes.MsgSoftwareUpgrade) + require.Truef(t, ok, "expected *MsgSoftwareUpgrade, got %T", legacyP.Content.GetCachedValue()) require.Equal(t, &msg, tp) // more than one message is not supported proposal.Messages, err = tx.SetMsgs([]sdk.Msg{&msg, &msg}) require.NoError(t, err) - _, err = v3.ConvertToLegacyProposal(proposal) + _, err = v046.ConvertToLegacyProposal(proposal) require.ErrorIs(t, sdkerrors.ErrInvalidType, err) // zero messages is not supported proposal.Messages = nil - _, err = v3.ConvertToLegacyProposal(proposal) + _, err = v046.ConvertToLegacyProposal(proposal) require.ErrorIs(t, sdkerrors.ErrInvalidType, err) } - func TestConvertToLegacyTallyResult(t *testing.T) { tallyResult := v1.EmptyTallyResult() testCases := map[string]struct {