Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace all ModuleCdc instances with legacy.Cdc #11240

Merged
Prev Previous commit
Next Next commit
fixed tests
  • Loading branch information
RiccardoM committed Feb 22, 2022
commit fc76332dc01675085c9a75e9b312510a0030bd18
9 changes: 5 additions & 4 deletions x/bank/simulation/operations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package simulation_test

import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
"math/rand"
"testing"

Expand Down Expand Up @@ -80,7 +81,7 @@ func (suite *SimTestSuite) TestSimulateMsgSend() {
suite.Require().NoError(err)

var msg types.MsgSend
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

suite.Require().True(operationMsg.OK)
suite.Require().Equal("65337742stake", msg.Amount.String())
Expand Down Expand Up @@ -109,7 +110,7 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() {
require.NoError(err)

var msg types.MsgMultiSend
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(operationMsg.OK)
require.Len(msg.Inputs, 3)
Expand Down Expand Up @@ -146,7 +147,7 @@ func (suite *SimTestSuite) TestSimulateModuleAccountMsgSend() {
suite.Require().Error(err)

var msg types.MsgSend
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

suite.Require().False(operationMsg.OK)
suite.Require().Equal(operationMsg.Comment, "invalid transfers")
Expand Down Expand Up @@ -175,7 +176,7 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() {
suite.Require().Error(err)

var msg types.MsgMultiSend
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

suite.Require().False(operationMsg.OK) // sending tokens to a module account should fail
suite.Require().Equal(operationMsg.Comment, "invalid transfers")
Expand Down
9 changes: 5 additions & 4 deletions x/distribution/simulation/operations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package simulation_test

import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
"math/rand"
"testing"

Expand Down Expand Up @@ -73,7 +74,7 @@ func (suite *SimTestSuite) TestSimulateMsgSetWithdrawAddress() {
suite.Require().NoError(err)

var msg types.MsgSetWithdrawAddress
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

suite.Require().True(operationMsg.OK)
suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress)
Expand Down Expand Up @@ -114,7 +115,7 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() {
suite.Require().NoError(err)

var msg types.MsgWithdrawDelegatorReward
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

suite.Require().True(operationMsg.OK)
suite.Require().Equal("cosmosvaloper1l4s054098kk9hmr5753c6k3m2kw65h686d3mhr", msg.ValidatorAddress)
Expand Down Expand Up @@ -175,7 +176,7 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName
suite.Require().NoError(err)

var msg types.MsgWithdrawValidatorCommission
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

suite.Require().True(operationMsg.OK)
suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress)
Expand All @@ -202,7 +203,7 @@ func (suite *SimTestSuite) TestSimulateMsgFundCommunityPool() {
suite.Require().NoError(err)

var msg types.MsgFundCommunityPool
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

suite.Require().True(operationMsg.OK)
suite.Require().Equal("4896096stake", msg.Amount.String())
Expand Down
1 change: 0 additions & 1 deletion x/distribution/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var _ govtypes.Content = &CommunityPoolSpendProposal{}

func init() {
govtypes.RegisterProposalType(ProposalTypeCommunityPoolSpend)
govtypes.RegisterProposalTypeCodec(&CommunityPoolSpendProposal{}, "cosmos-sdk/CommunityPoolSpendProposal")
}

// NewCommunityPoolSpendProposal creates a new community pool spend proposal.
Expand Down
9 changes: 5 additions & 4 deletions x/gov/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package simulation_test

import (
"fmt"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"math/rand"
"testing"
"time"
Expand Down Expand Up @@ -116,7 +117,7 @@ func TestSimulateMsgSubmitProposal(t *testing.T) {
require.NoError(t, err)

var msg v1beta2.MsgSubmitProposal
err = types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)
require.NoError(t, err)

require.True(t, operationMsg.OK)
Expand Down Expand Up @@ -163,7 +164,7 @@ func TestSimulateMsgDeposit(t *testing.T) {
require.NoError(t, err)

var msg v1beta2.MsgDeposit
err = types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
err = legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)
require.NoError(t, err)

require.True(t, operationMsg.OK)
Expand Down Expand Up @@ -209,7 +210,7 @@ func TestSimulateMsgVote(t *testing.T) {
require.NoError(t, err)

var msg v1beta2.MsgVote
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(t, operationMsg.OK)
require.Equal(t, uint64(1), msg.ProposalId)
Expand Down Expand Up @@ -252,7 +253,7 @@ func TestSimulateMsgVoteWeighted(t *testing.T) {
require.NoError(t, err)

var msg v1beta2.MsgVoteWeighted
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(t, operationMsg.OK)
require.Equal(t, uint64(1), msg.ProposalId)
Expand Down
10 changes: 0 additions & 10 deletions x/gov/types/v1beta1/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

// RegisterProposalTypeCodec registers an external proposal content type defined
// in another module for the internal ModuleCdc. This allows the MsgSubmitProposal
// to be correctly Amino encoded and decoded.
//
// NOTE: This should only be used for applications that are still using a concrete
// Amino codec for serialization.
func RegisterProposalTypeCodec(o interface{}, name string) {
legacy.Cdc.RegisterConcrete(o, name, nil)
}

func init() {
RegisterLegacyAminoCodec(legacy.Cdc)
}
1 change: 0 additions & 1 deletion x/params/types/proposal/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var _ govtypes.Content = &ParameterChangeProposal{}

func init() {
govtypes.RegisterProposalType(ProposalTypeChange)
govtypes.RegisterProposalTypeCodec(&ParameterChangeProposal{}, "cosmos-sdk/ParameterChangeProposal")
}

func NewParameterChangeProposal(title, description string, changes []ParamChange) *ParameterChangeProposal {
Expand Down
3 changes: 2 additions & 1 deletion x/slashing/simulation/operations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package simulation_test

import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
"math/rand"
"testing"
"time"
Expand Down Expand Up @@ -99,7 +100,7 @@ func TestSimulateMsgUnjail(t *testing.T) {
require.NoError(t, err)

var msg types.MsgUnjail
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(t, operationMsg.OK)
require.Equal(t, types.TypeMsgUnjail, msg.Type())
Expand Down
11 changes: 6 additions & 5 deletions x/staking/simulation/operations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package simulation_test

import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
"math/big"
"math/rand"
"testing"
Expand Down Expand Up @@ -80,7 +81,7 @@ func TestSimulateMsgCreateValidator(t *testing.T) {
require.NoError(t, err)

var msg types.MsgCreateValidator
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(t, operationMsg.OK)
require.Equal(t, "0.080000000000000000", msg.Commission.MaxChangeRate.String())
Expand Down Expand Up @@ -117,7 +118,7 @@ func TestSimulateMsgEditValidator(t *testing.T) {
require.NoError(t, err)

var msg types.MsgEditValidator
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(t, operationMsg.OK)
require.Equal(t, "0.280623462081924936", msg.CommissionRate.String())
Expand Down Expand Up @@ -146,7 +147,7 @@ func TestSimulateMsgDelegate(t *testing.T) {
require.NoError(t, err)

var msg types.MsgDelegate
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(t, operationMsg.OK)
require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress)
Expand Down Expand Up @@ -192,7 +193,7 @@ func TestSimulateMsgUndelegate(t *testing.T) {
require.NoError(t, err)

var msg types.MsgUndelegate
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(t, operationMsg.OK)
require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress)
Expand Down Expand Up @@ -241,7 +242,7 @@ func TestSimulateMsgBeginRedelegate(t *testing.T) {
require.NoError(t, err)

var msg types.MsgBeginRedelegate
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
legacy.Cdc.UnmarshalJSON(operationMsg.Msg, &msg)

require.True(t, operationMsg.OK)
require.Equal(t, "cosmos1092v0qgulpejj8y8hs6dmlw82x9gv8f7jfc7jl", msg.DelegatorAddress)
Expand Down
6 changes: 4 additions & 2 deletions x/staking/types/historical_info_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types_test

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"math/rand"
"sort"
"testing"
Expand Down Expand Up @@ -32,11 +34,11 @@ func TestHistoricalInfo(t *testing.T) {

var value []byte
require.NotPanics(t, func() {
value = types.ModuleCdc.MustMarshal(&hi)
value = legacy.Cdc.MustMarshal(&hi)
})
require.NotNil(t, value, "Marshalled HistoricalInfo is nil")

recv, err := types.UnmarshalHistoricalInfo(types.ModuleCdc, value)
recv, err := types.UnmarshalHistoricalInfo(codec.NewAminoCodec(legacy.Cdc), value)
require.Nil(t, err, "Unmarshalling HistoricalInfo failed")
require.Equal(t, hi.Header, recv.Header)
for i := range hi.Valset {
Expand Down
2 changes: 0 additions & 2 deletions x/upgrade/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ var _ gov.Content = &SoftwareUpgradeProposal{}

func init() {
gov.RegisterProposalType(ProposalTypeSoftwareUpgrade)
gov.RegisterProposalTypeCodec(&SoftwareUpgradeProposal{}, "cosmos-sdk/SoftwareUpgradeProposal")
gov.RegisterProposalType(ProposalTypeCancelSoftwareUpgrade)
gov.RegisterProposalTypeCodec(&CancelSoftwareUpgradeProposal{}, "cosmos-sdk/CancelSoftwareUpgradeProposal")
}

func (sup *SoftwareUpgradeProposal) GetTitle() string { return sup.Title }
Expand Down