From ceaf9f7e52494777c4ba68029b0d1bd79d15ab17 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 15 Sep 2022 16:32:08 +0200 Subject: [PATCH 1/2] fix!: Fix group amino codec --- docs/core/encoding.md | 6 ++++-- x/auth/types/codec.go | 2 ++ x/auth/vesting/types/codec.go | 2 ++ x/authz/codec.go | 2 ++ x/bank/types/codec.go | 2 ++ x/crisis/types/codec.go | 2 ++ x/distribution/types/codec.go | 2 ++ x/evidence/types/codec.go | 2 ++ x/feegrant/codec.go | 2 ++ x/gov/codec/doc.go | 1 + x/gov/types/v1/codec.go | 2 ++ x/gov/types/v1beta1/codec.go | 2 ++ x/group/codec.go | 16 ++++----------- x/group/codec/cdc.go | 18 +++++++++++++++++ x/group/codec/doc.go | 19 ++++++++++++++++++ x/group/msgs.go | 29 ++++++++++++++------------- x/group/msgs_test.go | 28 ++++++++++++++++++++++++++ x/group/simulation/operations_test.go | 29 ++++++++++++++------------- x/mint/types/codec.go | 2 ++ x/slashing/types/codec.go | 2 ++ x/staking/types/codec.go | 2 ++ x/upgrade/types/codec.go | 2 ++ 22 files changed, 132 insertions(+), 42 deletions(-) create mode 100644 x/group/codec/cdc.go create mode 100644 x/group/codec/doc.go diff --git a/docs/core/encoding.md b/docs/core/encoding.md index ea05f81be6e0..bcacf0bee1cc 100644 --- a/docs/core/encoding.md +++ b/docs/core/encoding.md @@ -67,15 +67,16 @@ Note, there are length-prefixed variants of the above functionality and this is typically used for when the data needs to be streamed or grouped together (e.g. `ResponseDeliverTx.Data`) -#### Authz authorizations and Gov proposals +#### Authz authorizations and Gov/Group proposals -Since authz's `MsgExec` and `MsgGrant` message types, as well as gov's `MsgSubmitProposal`, can contain different messages instances, it is important that developers +Since authz's `MsgExec` and `MsgGrant` message types, as well as gov's and group's `MsgSubmitProposal`, can contain different messages instances, it is important that developers add the following code inside the `init` method of their module's `codec.go` file: ```go import ( authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) init() { @@ -83,6 +84,7 @@ init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } ``` diff --git a/x/auth/types/codec.go b/x/auth/types/codec.go index 29fda99e090f..76680d824d5b 100644 --- a/x/auth/types/codec.go +++ b/x/auth/types/codec.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers the account interfaces and concrete types on the @@ -62,4 +63,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index 8e14ce6aa1a1..7b2b33f58eab 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers the vesting interfaces and concrete types on the @@ -79,4 +80,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/authz/codec.go b/x/authz/codec.go index ddad1b45d700..acc57f9691b5 100644 --- a/x/authz/codec.go +++ b/x/authz/codec.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers the necessary x/authz interfaces and concrete types @@ -43,4 +44,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index 2f85d785d595..42c9849869a8 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers the necessary x/bank interfaces and concrete types @@ -51,4 +52,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index bce0c3800fca..a971c042d7f0 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers the necessary x/crisis interfaces and concrete types @@ -41,4 +42,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index 574b02f4a319..5c5b21f0b401 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers the necessary x/distribution interfaces @@ -54,4 +55,5 @@ func init() { // instances. RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index 170764a83bec..4ea3ef1ea8e2 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -10,6 +10,7 @@ import ( authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" "github.com/cosmos/cosmos-sdk/x/evidence/exported" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the @@ -45,4 +46,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/feegrant/codec.go b/x/feegrant/codec.go index 421435f34ebb..5007271a7125 100644 --- a/x/feegrant/codec.go +++ b/x/feegrant/codec.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers the necessary x/feegrant interfaces and concrete types @@ -62,4 +63,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/gov/codec/doc.go b/x/gov/codec/doc.go index 574a18d57c9d..c3f3b765649b 100644 --- a/x/gov/codec/doc.go +++ b/x/gov/codec/doc.go @@ -10,6 +10,7 @@ codec.go file as follows: // ... RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/gov/types/v1/codec.go b/x/gov/types/v1/codec.go index 35310cc5f0a3..220985297de4 100644 --- a/x/gov/types/v1/codec.go +++ b/x/gov/types/v1/codec.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the @@ -39,4 +40,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/gov/types/v1beta1/codec.go b/x/gov/types/v1beta1/codec.go index fa9c9f05591a..1d8b2c54c332 100644 --- a/x/gov/types/v1beta1/codec.go +++ b/x/gov/types/v1beta1/codec.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the @@ -42,4 +43,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/group/codec.go b/x/group/codec.go index 437f81460eeb..ef7f34e1f88d 100644 --- a/x/group/codec.go +++ b/x/group/codec.go @@ -1,20 +1,20 @@ package group import ( - "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/legacy" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers all the necessary group module concrete // types and interfaces with the provided codec reference. // These types are used for Amino JSON serialization. -func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { +func RegisterLegacyAminoCodec(cdc *codectypes.LegacyAmino) { cdc.RegisterInterface((*DecisionPolicy)(nil), nil) cdc.RegisterConcrete(&ThresholdDecisionPolicy{}, "cosmos-sdk/ThresholdDecisionPolicy", nil) cdc.RegisterConcrete(&PercentageDecisionPolicy{}, "cosmos-sdk/PercentageDecisionPolicy", nil) @@ -63,18 +63,10 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { ) } -var ( - amino = codec.NewLegacyAmino() - ModuleCdc = codec.NewAminoCodec(amino) -) - func init() { - RegisterLegacyAminoCodec(amino) - cryptocodec.RegisterCrypto(amino) - sdk.RegisterLegacyAminoCodec(amino) - // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/group/codec/cdc.go b/x/group/codec/cdc.go new file mode 100644 index 000000000000..520e435afd69 --- /dev/null +++ b/x/group/codec/cdc.go @@ -0,0 +1,18 @@ +package codec + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(Amino) +) + +func init() { + cryptocodec.RegisterCrypto(Amino) + codec.RegisterEvidences(Amino) + sdk.RegisterLegacyAminoCodec(Amino) +} diff --git a/x/group/codec/doc.go b/x/group/codec/doc.go new file mode 100644 index 000000000000..c3f3b765649b --- /dev/null +++ b/x/group/codec/doc.go @@ -0,0 +1,19 @@ +/* +Package codec provides a singleton instance of Amino codec that should be used to register +any concrete type that can later be referenced inside a MsgSubmitProposal instance so that they +can be (de)serialized properly. + +Amino types should be ideally registered inside this codec within the init function of each module's +codec.go file as follows: + + func init() { + // ... + + RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) + + } + +The codec instance is put inside this package and not the x/gov/types package in order to avoid any dependency cycle. +*/ +package codec diff --git a/x/group/msgs.go b/x/group/msgs.go index 6e0c710a6d7e..4261b44a2478 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/group/codec" errors "github.com/cosmos/cosmos-sdk/x/group/errors" "github.com/cosmos/cosmos-sdk/x/group/internal/math" ) @@ -21,7 +22,7 @@ func (m MsgCreateGroup) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgCreateGroup) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgCreateGroup. @@ -71,7 +72,7 @@ func (m MsgUpdateGroupAdmin) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgUpdateGroupAdmin) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgUpdateGroupAdmin. @@ -119,7 +120,7 @@ func (m MsgUpdateGroupMetadata) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgUpdateGroupMetadata) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgUpdateGroupMetadata. @@ -158,7 +159,7 @@ func (m MsgUpdateGroupMembers) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgUpdateGroupMembers) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } var _ sdk.Msg = &MsgUpdateGroupMembers{} @@ -250,7 +251,7 @@ func (m MsgCreateGroupWithPolicy) Type() string { // GetSignBytes Implements Msg. func (m MsgCreateGroupWithPolicy) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgCreateGroupWithPolicy. @@ -288,7 +289,7 @@ func (m MsgCreateGroupPolicy) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgCreateGroupPolicy) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgCreateGroupPolicy. @@ -333,7 +334,7 @@ func (m MsgUpdateGroupPolicyAdmin) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyAdmin) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgUpdateGroupPolicyAdmin. @@ -409,7 +410,7 @@ func (m MsgUpdateGroupPolicyDecisionPolicy) Type() string { // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyDecisionPolicy) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgUpdateGroupPolicyDecisionPolicy. @@ -470,7 +471,7 @@ func (m MsgUpdateGroupPolicyMetadata) Type() string { return sdk.MsgTypeURL(&m) // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyMetadata) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgUpdateGroupPolicyMetadata. @@ -576,7 +577,7 @@ func (m MsgSubmitProposal) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgSubmitProposal) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgSubmitProposal. @@ -668,7 +669,7 @@ func (m MsgWithdrawProposal) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgWithdrawProposal) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgWithdrawProposal. @@ -704,7 +705,7 @@ func (m MsgVote) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgVote) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgVote. @@ -744,7 +745,7 @@ func (m MsgExec) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg. func (m MsgExec) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgExec. @@ -778,7 +779,7 @@ func (m MsgLeaveGroup) Type() string { return sdk.MsgTypeURL(&m) } // GetSignBytes Implements Msg func (m MsgLeaveGroup) GetSignBytes() []byte { - return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) + return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) } // GetSigners returns the expected signers for a MsgLeaveGroup diff --git a/x/group/msgs_test.go b/x/group/msgs_test.go index 5242f6ca79b9..7043dc580476 100644 --- a/x/group/msgs_test.go +++ b/x/group/msgs_test.go @@ -1,12 +1,14 @@ package group_test import ( + fmt "fmt" "testing" "time" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/group" ) @@ -962,6 +964,32 @@ func TestMsgSubmitProposal(t *testing.T) { } } +func TestMsgSubmitProposalGetSignBytes(t *testing.T) { + testcases := []struct { + name string + proposal []sdk.Msg + expSignBz string + }{ + { + "MsgSend", []sdk.Msg{banktypes.NewMsgSend(member1, member1, sdk.NewCoins())}, + fmt.Sprintf(`{"type":"cosmos-sdk/group/MsgSubmitProposal","value":{"messages":[{"type":"cosmos-sdk/MsgSend","value":{"amount":[],"from_address":"%s","to_address":"%s"}}],"proposers":[""]}}`, member1, member1), + }, + } + + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + msg, err := group.NewMsgSubmitProposal(sdk.AccAddress{}.String(), []string{sdk.AccAddress{}.String()}, tc.proposal, "", group.Exec_EXEC_UNSPECIFIED) + require.NoError(t, err) + var bz []byte + require.NotPanics(t, func() { + bz = msg.GetSignBytes() + }) + fmt.Println(string(bz)) + require.Equal(t, tc.expSignBz, string(bz)) + }) + } +} + func TestMsgVote(t *testing.T) { testCases := []struct { name string diff --git a/x/group/simulation/operations_test.go b/x/group/simulation/operations_test.go index 03aad7205704..ac6aa62de608 100644 --- a/x/group/simulation/operations_test.go +++ b/x/group/simulation/operations_test.go @@ -20,6 +20,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/bank/testutil" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/group" + groupcdc "github.com/cosmos/cosmos-sdk/x/group/codec" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" "github.com/cosmos/cosmos-sdk/x/group/simulation" grouptestutil "github.com/cosmos/cosmos-sdk/x/group/testutil" @@ -137,7 +138,7 @@ func (suite *SimTestSuite) TestSimulateCreateGroup() { suite.Require().NoError(err) var msg group.MsgCreateGroup - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -166,7 +167,7 @@ func (suite *SimTestSuite) TestSimulateCreateGroupWithPolicy() { suite.Require().NoError(err) var msg group.MsgCreateGroupWithPolicy - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -208,7 +209,7 @@ func (suite *SimTestSuite) TestSimulateCreateGroupPolicy() { suite.Require().NoError(err) var msg group.MsgCreateGroupPolicy - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -261,7 +262,7 @@ func (suite *SimTestSuite) TestSimulateSubmitProposal() { suite.Require().NoError(err) var msg group.MsgSubmitProposal - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(groupPolicyRes.Address, msg.GroupPolicyAddress) @@ -327,7 +328,7 @@ func (suite *SimTestSuite) TestWithdrawProposal() { suite.Require().NoError(err) var msg group.MsgWithdrawProposal - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(addr, msg.Address) @@ -394,7 +395,7 @@ func (suite *SimTestSuite) TestSimulateVote() { suite.Require().NoError(err) var msg group.MsgVote - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(addr, msg.Voter) @@ -469,7 +470,7 @@ func (suite *SimTestSuite) TestSimulateExec() { suite.Require().NoError(err) var msg group.MsgExec - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(addr, msg.Executor) @@ -511,7 +512,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupAdmin() { suite.Require().NoError(err) var msg group.MsgUpdateGroupAdmin - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -553,7 +554,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupMetadata() { suite.Require().NoError(err) var msg group.MsgUpdateGroupMetadata - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -595,7 +596,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupMembers() { suite.Require().NoError(err) var msg group.MsgUpdateGroupMembers - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(acc.Address.String(), msg.Admin) @@ -648,7 +649,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupPolicyAdmin() { suite.Require().NoError(err) var msg group.MsgUpdateGroupPolicyAdmin - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(groupPolicyRes.Address, msg.GroupPolicyAddress) @@ -701,7 +702,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupPolicyDecisionPolicy() { suite.Require().NoError(err) var msg group.MsgUpdateGroupPolicyDecisionPolicy - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(groupPolicyRes.Address, msg.GroupPolicyAddress) @@ -754,7 +755,7 @@ func (suite *SimTestSuite) TestSimulateUpdateGroupPolicyMetadata() { suite.Require().NoError(err) var msg group.MsgUpdateGroupPolicyMetadata - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(groupPolicyRes.Address, msg.GroupPolicyAddress) @@ -820,7 +821,7 @@ func (suite *SimTestSuite) TestSimulateLeaveGroup() { suite.Require().NoError(err) var msg group.MsgLeaveGroup - err = group.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + err = groupcdc.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().NoError(err) suite.Require().True(operationMsg.OK) suite.Require().Equal(groupRes.GroupId, msg.GroupId) diff --git a/x/mint/types/codec.go b/x/mint/types/codec.go index 967b3f18106b..866f486ad9b8 100644 --- a/x/mint/types/codec.go +++ b/x/mint/types/codec.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) var ( @@ -26,6 +27,7 @@ func init() { // instances. RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } // RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index 6a7252b17ee3..aff46791a830 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers concrete types on LegacyAmino codec @@ -41,4 +42,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 0ac238e972c4..11c9aec9e860 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers the necessary x/staking interfaces and concrete types @@ -63,4 +64,5 @@ func init() { // used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } diff --git a/x/upgrade/types/codec.go b/x/upgrade/types/codec.go index 4e058d218000..a663c35c6d48 100644 --- a/x/upgrade/types/codec.go +++ b/x/upgrade/types/codec.go @@ -10,6 +10,7 @@ import ( authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) // RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec @@ -51,4 +52,5 @@ func init() { // instances. RegisterLegacyAminoCodec(authzcodec.Amino) RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) } From 97c7c2015c17926ad850c96e7dd33fa76d88e1d5 Mon Sep 17 00:00:00 2001 From: Amaury M <1293565+amaurym@users.noreply.github.com> Date: Thu, 15 Sep 2022 16:36:13 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + x/group/msgs_test.go | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94b7073e8820..ab2b4cdbdb64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking +* (codec) [#13307](https://github.com/cosmos/cosmos-sdk/pull/13307) Register all modules' `Msg`s with group's ModuleCdc so that Amino sign bytes are correctly generated. * (codec) [#13196](https://github.com/cosmos/cosmos-sdk/pull/13196) Register all modules' `Msg`s with gov's ModuleCdc so that Amino sign bytes are correctly generated. * (x/distribution) [#12852](https://github.com/cosmos/cosmos-sdk/pull/12852) Deprecate `CommunityPoolSpendProposal`. Please execute a `MsgCommunityPoolSpend` message via the new v1 `x/gov` module instead. This message can be used to directly fund the `x/gov` module account. * (x/bank) [#12610](https://github.com/cosmos/cosmos-sdk/pull/12610) `MsgMultiSend` now allows only a single input. diff --git a/x/group/msgs_test.go b/x/group/msgs_test.go index 7043dc580476..046044b591d5 100644 --- a/x/group/msgs_test.go +++ b/x/group/msgs_test.go @@ -984,7 +984,6 @@ func TestMsgSubmitProposalGetSignBytes(t *testing.T) { require.NotPanics(t, func() { bz = msg.GetSignBytes() }) - fmt.Println(string(bz)) require.Equal(t, tc.expSignBz, string(bz)) }) }