Skip to content

Commit

Permalink
feat(gov): support v1.Proposal in v1beta1.Proposal.Content (backport c…
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba authored and JeancarloBarrios committed Sep 28, 2024
1 parent 993b155 commit f1cf30a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions x/gov/migrations/v3/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand All @@ -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 {
Expand Down

0 comments on commit f1cf30a

Please sign in to comment.