diff --git a/CHANGELOG.md b/CHANGELOG.md index b6c6a269b7ca..c5d9285158c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,12 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog +## Unreleased + +### Improvements + +* (x/auth/tx) [#14751](https://github.com/cosmos/cosmos-sdk/pull/14751) Remove `.Type()` and `Route()` methods from all msgs and `legacytx.LegacyMsg` interface. + ## [v0.47.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.0) - 2023-03-14 ### Features diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 605c36c5c7f5..5ce311d072a5 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -850,11 +850,8 @@ func createEvents(events sdk.Events, msg sdk.Msg) sdk.Events { // verify that events have no module attribute set if _, found := events.GetAttributes(sdk.AttributeKeyModule); !found { - // here we assume that routes module name is the second element of the route - // e.g. "cosmos.bank.v1beta1.MsgSend" => "bank" - moduleName := strings.Split(eventMsgName, ".") - if len(moduleName) > 1 { - msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeyModule, moduleName[1])) + if moduleName := sdk.GetModuleNameFromTypeURL(eventMsgName); moduleName != "" { + msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeyModule, moduleName)) } } diff --git a/docs/docs/building-modules/02-messages-and-queries.md b/docs/docs/building-modules/02-messages-and-queries.md index 2021c7e967be..749f7547ece9 100644 --- a/docs/docs/building-modules/02-messages-and-queries.md +++ b/docs/docs/building-modules/02-messages-and-queries.md @@ -63,8 +63,6 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/types/tx_msg.go#L14-L26 It extends `proto.Message` and contains the following methods: -* `Route() string`: Name of the route for this message. Typically all `message`s in a module have the same route, which is most often the module's name. -* `Type() string`: Type of the message, used primarily in [events](../core/08-events.md). This should return a message-specific `string`, typically the denomination of the message itself. * [`ValidateBasic() error`](../basics/01-tx-lifecycle.md#ValidateBasic). * `GetSignBytes() []byte`: Return the canonical byte representation of the message. Used to generate a signature. * `GetSigners() []AccAddress`: Return the list of signers. The Cosmos SDK will make sure that each `message` contained in a transaction is signed by all the signers listed in the list returned by this method. diff --git a/docs/docs/core/08-events.md b/docs/docs/core/08-events.md index b07aaffd4025..d368de3e38a4 100644 --- a/docs/docs/core/08-events.md +++ b/docs/docs/core/08-events.md @@ -57,7 +57,6 @@ The following examples show how to query Events using the Cosmos SDK. | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | | `tx.height=23` | Query all transactions at height 23 | | `message.action='/cosmos.bank.v1beta1.Msg/Send'` | Query all transactions containing a x/bank `Send` [Service `Msg`](../building-modules/03-msg-services.md). Note the `'`s around the value. | -| `message.action='send'` | Query all transactions containing a x/bank `Send` [legacy `Msg`](../building-modules/03-msg-services.md#legacy-amino-msgs). Note the `'`s around the value. | | `message.module='bank'` | Query all transactions containing messages from the x/bank module. Note the `'`s around the value. | | `create_validator.validator='cosmosval1...'` | x/staking-specific Event, see [x/staking SPEC](../modules/staking/README.md). | diff --git a/testutil/testdata/tx.go b/testutil/testdata/tx.go index 3d130b398877..d8bcd4ff33b7 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -77,8 +77,6 @@ func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg { var _ sdk.Msg = (*TestMsg)(nil) -func (msg *TestMsg) Route() string { return "TestMsg" } -func (msg *TestMsg) Type() string { return "Test message" } func (msg *TestMsg) GetSignBytes() []byte { bz, err := json.Marshal(msg.Signers) if err != nil { diff --git a/types/simulation/types.go b/types/simulation/types.go index 6a3b0555cbdc..f00627352f9b 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -76,10 +76,10 @@ type OperationMsg struct { } // NewOperationMsgBasic creates a new operation message from raw input. -func NewOperationMsgBasic(route, name, comment string, ok bool, msg []byte) OperationMsg { +func NewOperationMsgBasic(moduleName, msgType, comment string, ok bool, msg []byte) OperationMsg { return OperationMsg{ - Route: route, - Name: name, + Route: moduleName, + Name: msgType, Comment: comment, OK: ok, Msg: msg, @@ -88,18 +88,22 @@ func NewOperationMsgBasic(route, name, comment string, ok bool, msg []byte) Oper // NewOperationMsg - create a new operation message from sdk.Msg func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec) OperationMsg { - if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType { - return NewOperationMsgBasic(legacyMsg.Route(), legacyMsg.Type(), comment, ok, legacyMsg.GetSignBytes()) + msgType := sdk.MsgTypeURL(msg) + moduleName := sdk.GetModuleNameFromTypeURL(msgType) + if moduleName == "" { + moduleName = msgType } - bz := cdc.MustMarshalJSON(msg) + if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType { + return NewOperationMsgBasic(moduleName, msgType, comment, ok, legacyMsg.GetSignBytes()) + } - return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, bz) + return NewOperationMsgBasic(moduleName, msgType, comment, ok, cdc.MustMarshalJSON(msg)) } // NoOpMsg - create a no-operation message -func NoOpMsg(route, msgType, comment string) OperationMsg { - return NewOperationMsgBasic(route, msgType, comment, false, nil) +func NoOpMsg(moduleName, msgType, comment string) OperationMsg { + return NewOperationMsgBasic(moduleName, msgType, comment, false, nil) } // log entry text for this operation msg diff --git a/types/tx_msg.go b/types/tx_msg.go index 41c647e57de5..d0127a7b5b67 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -3,6 +3,7 @@ package types import ( "encoding/json" fmt "fmt" + strings "strings" "github.com/cosmos/gogoproto/proto" @@ -102,3 +103,15 @@ func GetMsgFromTypeURL(cdc codec.Codec, input string) (Msg, error) { return msg, nil } + +// GetModuleNameFromTypeURL assumes that module name is the second element of the msg type URL +// e.g. "cosmos.bank.v1beta1.MsgSend" => "bank" +// It returns an empty string if the input is not a valid type URL +func GetModuleNameFromTypeURL(input string) string { + moduleName := strings.Split(input, ".") + if len(moduleName) > 1 { + return moduleName[1] + } + + return "" +} diff --git a/types/tx_msg_test.go b/types/tx_msg_test.go index 0366d4fb14bc..7a9a5b945dae 100644 --- a/types/tx_msg_test.go +++ b/types/tx_msg_test.go @@ -25,8 +25,6 @@ func (s *testMsgSuite) TestMsg() { msg := testdata.NewTestMsg(accAddr) s.Require().NotNil(msg) s.Require().True(accAddr.Equals(msg.GetSigners()[0])) - s.Require().Equal("TestMsg", msg.Route()) - s.Require().Equal("Test message", msg.Type()) s.Require().Nil(msg.ValidateBasic()) s.Require().NotPanics(func() { msg.GetSignBytes() }) } diff --git a/x/auth/migrations/legacytx/stdsign.go b/x/auth/migrations/legacytx/stdsign.go index 9467ee8027c8..634a5ef27dcb 100644 --- a/x/auth/migrations/legacytx/stdsign.go +++ b/x/auth/migrations/legacytx/stdsign.go @@ -17,22 +17,14 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx/signing" ) -// LegacyMsg defines the old interface a message must fulfill, containing -// Amino signing method and legacy router info. +// LegacyMsg defines the old interface a message must fulfill, +// containing Amino signing method. // Deprecated: Please use `Msg` instead. type LegacyMsg interface { sdk.Msg // Get the canonical byte representation of the Msg. GetSignBytes() []byte - - // Return the message type. - // Must be alphanumeric or empty. - Route() string - - // Returns a human-readable string for the message, intended for utilization - // within tags - Type() string } // StdSignDoc is replay-prevention structure. diff --git a/x/auth/types/msgs.go b/x/auth/types/msgs.go index c0f25ee1e023..4220cfee5761 100644 --- a/x/auth/types/msgs.go +++ b/x/auth/types/msgs.go @@ -3,9 +3,13 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) -var _ sdk.Msg = &MsgUpdateParams{} +var ( + _ sdk.Msg = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} +) // GetSignBytes implements the LegacyMsg interface. func (msg MsgUpdateParams) GetSignBytes() []byte { @@ -13,13 +17,13 @@ func (msg MsgUpdateParams) GetSignBytes() []byte { } // GetSigners returns the expected signers for a MsgUpdateParams message. -func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { +func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(msg.Authority) return []sdk.AccAddress{addr} } // ValidateBasic does a sanity check on the provided data. -func (msg *MsgUpdateParams) ValidateBasic() error { +func (msg MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } diff --git a/x/auth/vesting/types/msgs.go b/x/auth/vesting/types/msgs.go index fbce860cede4..f21fe53d1dff 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -5,22 +5,18 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) -// TypeMsgCreateVestingAccount defines the type value for a MsgCreateVestingAccount. -const TypeMsgCreateVestingAccount = "msg_create_vesting_account" +var ( + _ sdk.Msg = &MsgCreateVestingAccount{} + _ sdk.Msg = &MsgCreatePermanentLockedAccount{} + _ sdk.Msg = &MsgCreatePeriodicVestingAccount{} -// TypeMsgCreatePermanentLockedAccount defines the type value for a MsgCreatePermanentLockedAccount. -const TypeMsgCreatePermanentLockedAccount = "msg_create_permanent_locked_account" - -// TypeMsgCreatePeriodicVestingAccount defines the type value for a MsgCreateVestingAccount. -const TypeMsgCreatePeriodicVestingAccount = "msg_create_periodic_vesting_account" - -var _ sdk.Msg = &MsgCreateVestingAccount{} - -var _ sdk.Msg = &MsgCreatePermanentLockedAccount{} - -var _ sdk.Msg = &MsgCreatePeriodicVestingAccount{} + _ legacytx.LegacyMsg = &MsgCreateVestingAccount{} + _ legacytx.LegacyMsg = &MsgCreatePermanentLockedAccount{} + _ legacytx.LegacyMsg = &MsgCreatePeriodicVestingAccount{} +) // NewMsgCreateVestingAccount returns a reference to a new MsgCreateVestingAccount. // @@ -35,12 +31,6 @@ func NewMsgCreateVestingAccount(fromAddr, toAddr sdk.AccAddress, amount sdk.Coin } } -// Route returns the message route for a MsgCreateVestingAccount. -func (msg MsgCreateVestingAccount) Route() string { return RouterKey } - -// Type returns the message type for a MsgCreateVestingAccount. -func (msg MsgCreateVestingAccount) Type() string { return TypeMsgCreateVestingAccount } - // ValidateBasic Implements Msg. func (msg MsgCreateVestingAccount) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil { @@ -88,12 +78,6 @@ func NewMsgCreatePermanentLockedAccount(fromAddr, toAddr sdk.AccAddress, amount } } -// Route returns the message route for a MsgCreatePermanentLockedAccount. -func (msg MsgCreatePermanentLockedAccount) Route() string { return RouterKey } - -// Type returns the message type for a MsgCreatePermanentLockedAccount. -func (msg MsgCreatePermanentLockedAccount) Type() string { return TypeMsgCreatePermanentLockedAccount } - // ValidateBasic Implements Msg. func (msg MsgCreatePermanentLockedAccount) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil { @@ -138,12 +122,6 @@ func NewMsgCreatePeriodicVestingAccount(fromAddr, toAddr sdk.AccAddress, startTi } } -// Route returns the message route for a MsgCreatePeriodicVestingAccount. -func (msg MsgCreatePeriodicVestingAccount) Route() string { return RouterKey } - -// Type returns the message type for a MsgCreatePeriodicVestingAccount. -func (msg MsgCreatePeriodicVestingAccount) Type() string { return TypeMsgCreatePeriodicVestingAccount } - // GetSigners returns the expected signers for a MsgCreatePeriodicVestingAccount. func (msg MsgCreatePeriodicVestingAccount) GetSigners() []sdk.AccAddress { from, err := sdk.AccAddressFromBech32(msg.FromAddress) diff --git a/x/authz/msgs.go b/x/authz/msgs.go index fd84b311d7e9..792120d6de71 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -66,16 +66,6 @@ func (msg MsgGrant) ValidateBasic() error { return msg.Grant.ValidateBasic() } -// Type implements the LegacyMsg.Type method. -func (msg MsgGrant) Type() string { - return sdk.MsgTypeURL(&msg) -} - -// Route implements the LegacyMsg.Route method. -func (msg MsgGrant) Route() string { - return sdk.MsgTypeURL(&msg) -} - // GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgGrant) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) @@ -157,16 +147,6 @@ func (msg MsgRevoke) ValidateBasic() error { return nil } -// Type implements the LegacyMsg.Type method. -func (msg MsgRevoke) Type() string { - return sdk.MsgTypeURL(&msg) -} - -// Route implements the LegacyMsg.Route method. -func (msg MsgRevoke) Route() string { - return sdk.MsgTypeURL(&msg) -} - // GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgRevoke) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) @@ -235,16 +215,6 @@ func (msg MsgExec) ValidateBasic() error { return nil } -// Type implements the LegacyMsg.Type method. -func (msg MsgExec) Type() string { - return sdk.MsgTypeURL(&msg) -} - -// Route implements the LegacyMsg.Route method. -func (msg MsgExec) Route() string { - return sdk.MsgTypeURL(&msg) -} - // GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgExec) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 20636a02611c..434c0f7550bb 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -69,10 +69,11 @@ func (suite *SimTestSuite) TestWeightedOperations() { expected := []struct { weight int opMsgRoute string + opMsgName string }{ - {simulation.WeightGrant, simulation.TypeMsgGrant}, - {simulation.WeightExec, simulation.TypeMsgExec}, - {simulation.WeightRevoke, simulation.TypeMsgRevoke}, + {simulation.WeightGrant, authz.ModuleName, simulation.TypeMsgGrant}, + {simulation.WeightExec, authz.ModuleName, simulation.TypeMsgExec}, + {simulation.WeightRevoke, authz.ModuleName, simulation.TypeMsgRevoke}, } require := suite.Require() @@ -83,12 +84,9 @@ func (suite *SimTestSuite) TestWeightedOperations() { // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail - require.Equal(expected[i].weight, w.Weight(), - "weight should be the same. %v", op.Comment) - require.Equal(expected[i].opMsgRoute, op.Route, - "route should be the same. %v", op.Comment) - require.Equal(expected[i].opMsgRoute, op.Name, - "operation Msg name should be the same %v", op.Comment) + require.Equal(expected[i].weight, w.Weight(), "weight should be the same. %v", op.Comment) + require.Equal(expected[i].opMsgRoute, op.Route, "route should be the same. %v", op.Comment) + require.Equal(expected[i].opMsgName, op.Name, "operation Msg name should be the same %v", op.Comment) } } diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index a9a8be151e3a..13296686cc16 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -60,27 +60,28 @@ func SimulateMsgSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Operatio r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgSend{}) from, to, coins, skip := randomSendFields(r, ctx, accs, bk, ak) // if coins slice is empty, we can not create valid types.MsgSend if len(coins) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, "empty coins slice"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "empty coins slice"), nil, nil } // Check send_enabled status of each coin denom if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, err.Error()), nil, nil } if skip { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, "skip all transfers"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "skip all transfers"), nil, nil } msg := types.NewMsgSend(from.Address, to.Address, coins) err := sendMsgSend(r, app, bk, ak, msg, ctx, chainID, []cryptotypes.PrivKey{from.PrivKey}) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "invalid transfers"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "invalid transfers"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil @@ -94,27 +95,27 @@ func SimulateMsgSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keeper, mo r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgSend{}) from := accs[0] - to := getModuleAccounts(ak, ctx, moduleAccCount)[0] spendable := bk.SpendableCoins(ctx, from.Address) coins := simtypes.RandSubsetCoins(r, spendable) // if coins slice is empty, we can not create valid types.MsgSend if len(coins) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, "empty coins slice"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "empty coins slice"), nil, nil } // Check send_enabled status of each coin denom if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, err.Error()), nil, nil } msg := types.NewMsgSend(from.Address, to.Address, coins) err := sendMsgSend(r, app, bk, ak, msg, ctx, chainID, []cryptotypes.PrivKey{from.PrivKey}) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "invalid transfers"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "invalid transfers"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil @@ -177,6 +178,8 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgMultiSend{}) + // random number of inputs/outputs between [1, 3] inputs := make([]types.Input, r.Intn(1)+1) //nolint:staticcheck // SA4030: (*math/rand.Rand).Intn(n) generates a random value 0 <= x < n; that is, the generated values don't include n; r.Intn(1) therefore always returns 0 outputs := make([]types.Output, r.Intn(3)+1) @@ -198,7 +201,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope } if skip { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgMultiSend, "skip all transfers"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "skip all transfers"), nil, nil } // set input address in used address map @@ -214,7 +217,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope // Check send_enabled status of each sent coin denom if err := bk.IsSendEnabledCoins(ctx, totalSentCoins...); err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgMultiSend, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, err.Error()), nil, nil } for o := range outputs { @@ -252,7 +255,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope } err := sendMsgMultiSend(r, app, bk, ak, msg, ctx, chainID, privs) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "invalid transfers"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "invalid transfers"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil @@ -265,6 +268,7 @@ func SimulateMsgMultiSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keepe r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgMultiSend{}) inputs := make([]types.Input, 2) outputs := make([]types.Output, moduleAccCount) // collect signer privKeys @@ -279,7 +283,7 @@ func SimulateMsgMultiSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keepe totalSentCoins = totalSentCoins.Add(coins...) } if err := bk.IsSendEnabledCoins(ctx, totalSentCoins...); err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgMultiSend, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, err.Error()), nil, nil } moduleAccounts := getModuleAccounts(ak, ctx, moduleAccCount) for i := range outputs { @@ -311,7 +315,7 @@ func SimulateMsgMultiSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keepe } err := sendMsgMultiSend(r, app, bk, ak, msg, ctx, chainID, privs) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "invalid transfers"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "invalid transfers"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index e7af77508fbe..57831b7ba276 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -72,8 +72,8 @@ func (suite *SimTestSuite) TestWeightedOperations() { opMsgRoute string opMsgName string }{ - {100, types.ModuleName, types.TypeMsgSend}, - {10, types.ModuleName, types.TypeMsgMultiSend}, + {100, types.ModuleName, sdk.MsgTypeURL(&types.MsgSend{})}, + {10, types.ModuleName, sdk.MsgTypeURL(&types.MsgMultiSend{})}, } for i, w := range weightesOps { @@ -112,8 +112,7 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { suite.Require().Equal("65337742stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.FromAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.ToAddress) - suite.Require().Equal(types.TypeMsgSend, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -144,8 +143,7 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() { require.Len(msg.Outputs, 2) require.Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Outputs[1].Address) require.Equal("107287087stake", msg.Outputs[1].Coins.String()) - require.Equal(types.TypeMsgMultiSend, msg.Type()) - require.Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(&msg)) require.Len(futureOperations, 0) } @@ -176,8 +174,7 @@ func (suite *SimTestSuite) TestSimulateModuleAccountMsgSend() { suite.Require().False(operationMsg.OK) suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(types.TypeMsgSend, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -205,8 +202,7 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() { suite.Require().False(operationMsg.OK) // sending tokens to a module account should fail suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(types.TypeMsgMultiSend, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index 81be11f5ac67..171fe7311b5c 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -3,20 +3,17 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// bank message types -const ( - TypeMsgSend = "send" - TypeMsgMultiSend = "multisend" - TypeMsgSetSendEnabled = "set_send_enabled" - TypeMsgUpdateParams = "update_params" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( _ sdk.Msg = &MsgSend{} _ sdk.Msg = &MsgMultiSend{} _ sdk.Msg = &MsgUpdateParams{} + + _ legacytx.LegacyMsg = &MsgSend{} + _ legacytx.LegacyMsg = &MsgMultiSend{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) // NewMsgSend - construct a msg to send coins from one account to another. @@ -26,12 +23,6 @@ func NewMsgSend(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) *MsgSend { return &MsgSend{FromAddress: fromAddr.String(), ToAddress: toAddr.String(), Amount: amount} } -// Route Implements Msg. -func (msg MsgSend) Route() string { return RouterKey } - -// Type Implements Msg. -func (msg MsgSend) Type() string { return TypeMsgSend } - // ValidateBasic Implements Msg. func (msg MsgSend) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil { @@ -69,12 +60,6 @@ func NewMsgMultiSend(in []Input, out []Output) *MsgMultiSend { return &MsgMultiSend{Inputs: in, Outputs: out} } -// Route Implements Msg -func (msg MsgMultiSend) Route() string { return RouterKey } - -// Type Implements Msg -func (msg MsgMultiSend) Type() string { return TypeMsgMultiSend } - // ValidateBasic Implements Msg. func (msg MsgMultiSend) ValidateBasic() error { // this just makes sure the input and all the outputs are properly formatted, diff --git a/x/bank/types/msgs_test.go b/x/bank/types/msgs_test.go index f2fc353521f0..7ce8399be3e1 100644 --- a/x/bank/types/msgs_test.go +++ b/x/bank/types/msgs_test.go @@ -11,16 +11,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) -func TestMsgSendRoute(t *testing.T) { - addr1 := sdk.AccAddress([]byte("from")) - addr2 := sdk.AccAddress([]byte("to")) - coins := sdk.NewCoins(sdk.NewInt64Coin("atom", 10)) - msg := NewMsgSend(addr1, addr2, coins) - - require.Equal(t, msg.Route(), RouterKey) - require.Equal(t, msg.Type(), "send") -} - func TestMsgSendValidation(t *testing.T) { addr1 := sdk.AccAddress([]byte("from________________")) addr2 := sdk.AccAddress([]byte("to__________________")) @@ -67,21 +57,6 @@ func TestMsgSendGetSignBytes(t *testing.T) { require.Equal(t, expected, string(res)) } -func TestMsgMultiSendRoute(t *testing.T) { - // Construct a MsgSend - addr1 := sdk.AccAddress([]byte("input")) - addr2 := sdk.AccAddress([]byte("output")) - coins := sdk.NewCoins(sdk.NewInt64Coin("atom", 10)) - msg := MsgMultiSend{ - Inputs: []Input{NewInput(addr1, coins)}, - Outputs: []Output{NewOutput(addr2, coins)}, - } - - // TODO some failures for bad result - require.Equal(t, msg.Route(), RouterKey) - require.Equal(t, msg.Type(), "multisend") -} - func TestInputValidation(t *testing.T) { addr1 := sdk.AccAddress([]byte("_______alice________")) addr2 := sdk.AccAddress([]byte("________bob_________")) diff --git a/x/consensus/types/msgs.go b/x/consensus/types/msgs.go index 167a7b76cc27..91e3b7ef13ee 100644 --- a/x/consensus/types/msgs.go +++ b/x/consensus/types/msgs.go @@ -8,12 +8,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) -const ( - TypeMsgUpdateParams = "update_params" +var ( + _ sdk.Msg = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) -var _ legacytx.LegacyMsg = &MsgUpdateParams{} - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes. func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { @@ -27,14 +26,6 @@ func (msg MsgUpdateParams) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -func (msg MsgUpdateParams) Route() string { - return sdk.MsgTypeURL(&msg) -} - -func (msg MsgUpdateParams) Type() string { - return sdk.MsgTypeURL(&msg) -} - // ValidateBasic performs basic MsgUpdateParams message validation. func (msg MsgUpdateParams) ValidateBasic() error { params := tmtypes.ConsensusParamsFromProto(msg.ToProtoConsensusParams()) diff --git a/x/crisis/types/msgs.go b/x/crisis/types/msgs.go index c2e2942ba13c..665183b98a5f 100644 --- a/x/crisis/types/msgs.go +++ b/x/crisis/types/msgs.go @@ -3,15 +3,14 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -const ( - TypeMsgVerifyInvariant = "verify_invariant" - TypeMsgUpdateParams = "update_params" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // ensure Msg interface compliance at compile time -var _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} +var ( + _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} + _, _ legacytx.LegacyMsg = &MsgVerifyInvariant{}, &MsgUpdateParams{} +) // NewMsgVerifyInvariant creates a new MsgVerifyInvariant object // @@ -24,12 +23,6 @@ func NewMsgVerifyInvariant(sender sdk.AccAddress, invModeName, invRoute string) } } -// Route returns the MsgVerifyInvariant's route. -func (msg MsgVerifyInvariant) Route() string { return ModuleName } - -// Type returns the MsgVerifyInvariant's type. -func (msg MsgVerifyInvariant) Type() string { return TypeMsgVerifyInvariant } - // get the bytes for the message signer to sign on func (msg MsgVerifyInvariant) GetSigners() []sdk.AccAddress { sender, _ := sdk.AccAddressFromBech32(msg.Sender) @@ -55,12 +48,6 @@ func (msg MsgVerifyInvariant) FullInvariantRoute() string { return msg.InvariantModuleName + "/" + msg.InvariantRoute } -// Route returns the MsgUpdateParams's route. -func (msg MsgUpdateParams) Route() string { return ModuleName } - -// Type returns the MsgUpdateParams's type. -func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams } - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes. func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index 9a5e5de737bf..40165a31798a 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -89,7 +89,7 @@ func SimulateMsgSetWithdrawAddress(txConfig client.TxConfig, ak types.AccountKee r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { if !k.GetWithdrawAddrEnabled(ctx) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSetWithdrawAddress, "withdrawal is not enabled"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), "withdrawal is not enabled"), nil, nil } simAccount, _ := simtypes.RandomAcc(r, accs) @@ -106,7 +106,6 @@ func SimulateMsgSetWithdrawAddress(txConfig client.TxConfig, ak types.AccountKee TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -127,14 +126,14 @@ func SimulateMsgWithdrawDelegatorReward(txConfig client.TxConfig, ak types.Accou simAccount, _ := simtypes.RandomAcc(r, accs) delegations := sk.GetAllDelegatorDelegations(ctx, simAccount.Address) if len(delegations) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawDelegatorReward, "number of delegators equal 0"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), "number of delegators equal 0"), nil, nil } delegation := delegations[r.Intn(len(delegations))] validator := sk.Validator(ctx, delegation.GetValidatorAddr()) if validator == nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawDelegatorReward, "validator is nil"), nil, fmt.Errorf("validator %s not found", delegation.GetValidatorAddr()) + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), "validator is nil"), nil, fmt.Errorf("validator %s not found", delegation.GetValidatorAddr()) } account := ak.GetAccount(ctx, simAccount.Address) @@ -148,7 +147,6 @@ func SimulateMsgWithdrawDelegatorReward(txConfig client.TxConfig, ak types.Accou TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -166,19 +164,21 @@ func SimulateMsgWithdrawValidatorCommission(txConfig client.TxConfig, ak types.A return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}) + validator, ok := testutil.RandSliceElem(r, sk.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawValidatorCommission, "random validator is not ok"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "random validator is not ok"), nil, nil } commission := k.GetValidatorAccumulatedCommission(ctx, validator.GetOperator()) if commission.Commission.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawValidatorCommission, "validator commission is zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator commission is zero"), nil, nil } simAccount, found := simtypes.FindAccount(accs, sdk.AccAddress(validator.GetOperator())) if !found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawValidatorCommission, "could not find account"), nil, fmt.Errorf("validator %s not found", validator.GetOperator()) + return simtypes.NoOpMsg(types.ModuleName, msgType, "could not find account"), nil, fmt.Errorf("validator %s not found", validator.GetOperator()) } account := ak.GetAccount(ctx, simAccount.Address) @@ -192,7 +192,6 @@ func SimulateMsgWithdrawValidatorCommission(txConfig client.TxConfig, ak types.A TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -218,7 +217,7 @@ func SimulateMsgFundCommunityPool(txConfig client.TxConfig, ak types.AccountKeep fundAmount := simtypes.RandSubsetCoins(r, spendable) if fundAmount.Empty() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgFundCommunityPool, "fund amount is empty"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), "fund amount is empty"), nil, nil } var ( @@ -230,7 +229,7 @@ func SimulateMsgFundCommunityPool(txConfig client.TxConfig, ak types.AccountKeep if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgFundCommunityPool, "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), "unable to generate fees"), nil, err } } @@ -242,7 +241,6 @@ func SimulateMsgFundCommunityPool(txConfig client.TxConfig, ak types.AccountKeep TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: funder, AccountKeeper: ak, diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 3f9896287d21..d8561d557ad8 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -44,10 +44,10 @@ func (suite *SimTestSuite) TestWeightedOperations() { opMsgRoute string opMsgName string }{ - {simulation.DefaultWeightMsgSetWithdrawAddress, types.ModuleName, types.TypeMsgSetWithdrawAddress}, - {simulation.DefaultWeightMsgWithdrawDelegationReward, types.ModuleName, types.TypeMsgWithdrawDelegatorReward}, - {simulation.DefaultWeightMsgWithdrawValidatorCommission, types.ModuleName, types.TypeMsgWithdrawValidatorCommission}, - {simulation.DefaultWeightMsgFundCommunityPool, types.ModuleName, types.TypeMsgFundCommunityPool}, + {simulation.DefaultWeightMsgSetWithdrawAddress, types.ModuleName, sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{})}, + {simulation.DefaultWeightMsgWithdrawDelegationReward, types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{})}, + {simulation.DefaultWeightMsgWithdrawValidatorCommission, types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{})}, + {simulation.DefaultWeightMsgFundCommunityPool, types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{})}, } for i, w := range weightesOps { @@ -85,8 +85,7 @@ func (suite *SimTestSuite) TestSimulateMsgSetWithdrawAddress() { suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.WithdrawAddress) - suite.Require().Equal(types.TypeMsgSetWithdrawAddress, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -126,8 +125,7 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() { suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1l4s054098kk9hmr5753c6k3m2kw65h686d3mhr", msg.ValidatorAddress) suite.Require().Equal("cosmos1d6u7zhjwmsucs678d7qn95uqajd4ucl9jcjt26", msg.DelegatorAddress) - suite.Require().Equal(types.TypeMsgWithdrawDelegatorReward, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -186,8 +184,7 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) - suite.Require().Equal(types.TypeMsgWithdrawValidatorCommission, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } } @@ -214,8 +211,7 @@ func (suite *SimTestSuite) TestSimulateMsgFundCommunityPool() { suite.Require().True(operationMsg.OK) suite.Require().Equal("4896096stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Depositor) - suite.Require().Equal(types.TypeMsgFundCommunityPool, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go index ee1660db681f..65ed80c06e64 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +<<<<<<< HEAD ) // distribution message types @@ -15,6 +16,9 @@ const ( TypeMsgFundCommunityPool = "fund_community_pool" TypeMsgUpdateParams = "update_params" TypeMsgCommunityPoolSpend = "community_pool_spend" +======= + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) ) // Verify interface at compile time @@ -24,6 +28,17 @@ var ( _ sdk.Msg = (*MsgWithdrawValidatorCommission)(nil) _ sdk.Msg = (*MsgUpdateParams)(nil) _ sdk.Msg = (*MsgCommunityPoolSpend)(nil) +<<<<<<< HEAD +======= + _ sdk.Msg = (*MsgDepositValidatorRewardsPool)(nil) + + _ legacytx.LegacyMsg = (*MsgSetWithdrawAddress)(nil) + _ legacytx.LegacyMsg = (*MsgWithdrawDelegatorReward)(nil) + _ legacytx.LegacyMsg = (*MsgWithdrawValidatorCommission)(nil) + _ legacytx.LegacyMsg = (*MsgUpdateParams)(nil) + _ legacytx.LegacyMsg = (*MsgCommunityPoolSpend)(nil) + _ legacytx.LegacyMsg = (*MsgDepositValidatorRewardsPool)(nil) +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) ) func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithdrawAddress { @@ -33,9 +48,6 @@ func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithd } } -func (msg MsgSetWithdrawAddress) Route() string { return ModuleName } -func (msg MsgSetWithdrawAddress) Type() string { return TypeMsgSetWithdrawAddress } - // Return address that must sign over msg.GetSignBytes() func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -67,9 +79,6 @@ func NewMsgWithdrawDelegatorReward(delAddr sdk.AccAddress, valAddr sdk.ValAddres } } -func (msg MsgWithdrawDelegatorReward) Route() string { return ModuleName } -func (msg MsgWithdrawDelegatorReward) Type() string { return TypeMsgWithdrawDelegatorReward } - // Return address that must sign over msg.GetSignBytes() func (msg MsgWithdrawDelegatorReward) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -99,9 +108,6 @@ func NewMsgWithdrawValidatorCommission(valAddr sdk.ValAddress) *MsgWithdrawValid } } -func (msg MsgWithdrawValidatorCommission) Route() string { return ModuleName } -func (msg MsgWithdrawValidatorCommission) Type() string { return TypeMsgWithdrawValidatorCommission } - // Return address that must sign over msg.GetSignBytes() func (msg MsgWithdrawValidatorCommission) GetSigners() []sdk.AccAddress { valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) @@ -131,12 +137,6 @@ func NewMsgFundCommunityPool(amount sdk.Coins, depositor sdk.AccAddress) *MsgFun } } -// Route returns the MsgFundCommunityPool message route. -func (msg MsgFundCommunityPool) Route() string { return ModuleName } - -// Type returns the MsgFundCommunityPool message type. -func (msg MsgFundCommunityPool) Type() string { return TypeMsgFundCommunityPool } - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes. func (msg MsgFundCommunityPool) GetSigners() []sdk.AccAddress { @@ -162,12 +162,6 @@ func (msg MsgFundCommunityPool) ValidateBasic() error { return nil } -// Route returns the MsgUpdateParams message route. -func (msg MsgUpdateParams) Route() string { return ModuleName } - -// Type returns the MsgUpdateParams message type. -func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams } - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes. func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { @@ -196,12 +190,6 @@ func (msg MsgUpdateParams) ValidateBasic() error { return msg.Params.ValidateBasic() } -// Route returns the MsgCommunityPoolSpend message route. -func (msg MsgCommunityPoolSpend) Route() string { return ModuleName } - -// Type returns the MsgCommunityPoolSpend message type. -func (msg MsgCommunityPoolSpend) Type() string { return TypeMsgCommunityPoolSpend } - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes, which is the authority. func (msg MsgCommunityPoolSpend) GetSigners() []sdk.AccAddress { @@ -224,3 +212,39 @@ func (msg MsgCommunityPoolSpend) ValidateBasic() error { return msg.Amount.Validate() } +<<<<<<< HEAD +======= + +// NewMsgDepositValidatorRewardsPool returns a new MsgDepositValidatorRewardsPool +// with a sender and a funding amount. +func NewMsgDepositValidatorRewardsPool(depositor sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coins) *MsgDepositValidatorRewardsPool { + return &MsgDepositValidatorRewardsPool{ + Amount: amount, + Authority: depositor.String(), + ValidatorAddress: valAddr.String(), + } +} + +// GetSigners returns the signer addresses that are expected to sign the result +// of GetSignBytes, which is the authority. +func (msg MsgDepositValidatorRewardsPool) GetSigners() []sdk.AccAddress { + authority, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{authority} +} + +// GetSignBytes returns the raw bytes for a MsgDepositValidatorRewardsPool message +// that the expected signer needs to sign. +func (msg MsgDepositValidatorRewardsPool) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(&msg) + return sdk.MustSortJSON(bz) +} + +// ValidateBasic performs basic MsgDepositValidatorRewardsPool message validation. +func (msg MsgDepositValidatorRewardsPool) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err) + } + + return msg.Amount.Validate() +} +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) diff --git a/x/evidence/types/genesis_test.go b/x/evidence/types/genesis_test.go index a2774b2a3588..df881b528f1e 100644 --- a/x/evidence/types/genesis_test.go +++ b/x/evidence/types/genesis_test.go @@ -160,6 +160,10 @@ type TestEvidence struct{} var _ exported.Evidence = &TestEvidence{} +func (*TestEvidence) String() string { + return "test-string" +} + func (*TestEvidence) Route() string { return "test-route" } @@ -168,10 +172,6 @@ func (*TestEvidence) Type() string { return "test-type" } -func (*TestEvidence) String() string { - return "test-string" -} - func (*TestEvidence) ProtoMessage() {} func (*TestEvidence) Reset() {} diff --git a/x/evidence/types/msgs.go b/x/evidence/types/msgs.go index cf488a3e7fb7..3b5c043cf378 100644 --- a/x/evidence/types/msgs.go +++ b/x/evidence/types/msgs.go @@ -8,16 +8,21 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +<<<<<<< HEAD "github.com/cosmos/cosmos-sdk/x/evidence/exported" ) // Message types for the evidence module const ( TypeMsgSubmitEvidence = "submit_evidence" +======= + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) ) var ( _ sdk.Msg = &MsgSubmitEvidence{} + _ legacytx.LegacyMsg = &MsgSubmitEvidence{} _ types.UnpackInterfacesMessage = MsgSubmitEvidence{} _ exported.MsgSubmitEvidenceI = &MsgSubmitEvidence{} ) @@ -37,12 +42,6 @@ func NewMsgSubmitEvidence(s sdk.AccAddress, evi exported.Evidence) (*MsgSubmitEv return &MsgSubmitEvidence{Submitter: s.String(), Evidence: any}, nil } -// Route returns the MsgSubmitEvidence's route. -func (m MsgSubmitEvidence) Route() string { return RouterKey } - -// Type returns the MsgSubmitEvidence's type. -func (m MsgSubmitEvidence) Type() string { return TypeMsgSubmitEvidence } - // ValidateBasic performs basic (non-state-dependant) validation on a MsgSubmitEvidence. func (m MsgSubmitEvidence) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Submitter); err != nil { diff --git a/x/feegrant/msgs.go b/x/feegrant/msgs.go index 4b4d1b3b3a37..13f9a09ccd09 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -10,8 +10,9 @@ import ( ) var ( - _, _ sdk.Msg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} - _, _ legacytx.LegacyMsg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} // For amino support. + _, _ sdk.Msg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} + // For amino support. + _, _ legacytx.LegacyMsg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} _ types.UnpackInterfacesMessage = &MsgGrantAllowance{} ) @@ -61,16 +62,6 @@ func (msg MsgGrantAllowance) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{granter} } -// Type implements the LegacyMsg.Type method. -func (msg MsgGrantAllowance) Type() string { - return sdk.MsgTypeURL(&msg) -} - -// Route implements the LegacyMsg.Route method. -func (msg MsgGrantAllowance) Route() string { - return sdk.MsgTypeURL(&msg) -} - // GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgGrantAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) @@ -122,16 +113,6 @@ func (msg MsgRevokeAllowance) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{granter} } -// Type implements the LegacyMsg.Type method. -func (msg MsgRevokeAllowance) Type() string { - return sdk.MsgTypeURL(&msg) -} - -// Route implements the LegacyMsg.Route method. -func (msg MsgRevokeAllowance) Route() string { - return sdk.MsgTypeURL(&msg) -} - // GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgRevokeAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) diff --git a/x/feegrant/simulation/operations.go b/x/feegrant/simulation/operations.go index 4079a90ef9d4..023d2076e9e4 100644 --- a/x/feegrant/simulation/operations.go +++ b/x/feegrant/simulation/operations.go @@ -103,7 +103,6 @@ func SimulateMsgGrantAllowance(cdc *codec.ProtoCodec, ak feegrant.AccountKeeper, TxGen: tx.NewTxConfig(cdc, tx.DefaultSignModes), Cdc: nil, Msg: msg, - MsgType: TypeMsgGrantAllowance, Context: ctx, SimAccount: granter, AccountKeeper: ak, @@ -153,7 +152,6 @@ func SimulateMsgRevokeAllowance(cdc *codec.ProtoCodec, ak feegrant.AccountKeeper TxGen: tx.NewTxConfig(cdc, tx.DefaultSignModes), Cdc: nil, Msg: &msg, - MsgType: TypeMsgRevokeAllowance, Context: ctx, SimAccount: granter, AccountKeeper: ak, diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 8b97f524046a..d80c2fcfb992 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -89,13 +89,13 @@ func (suite *SimTestSuite) TestWeightedOperations() { }{ { simulation.DefaultWeightGrantAllowance, - feegrant.MsgGrantAllowance{}.Route(), - simulation.TypeMsgGrantAllowance, + feegrant.ModuleName, + sdk.MsgTypeURL(&feegrant.MsgGrantAllowance{}), }, { simulation.DefaultWeightRevokeAllowance, - feegrant.MsgRevokeAllowance{}.Route(), - simulation.TypeMsgRevokeAllowance, + feegrant.ModuleName, + sdk.MsgTypeURL(&feegrant.MsgRevokeAllowance{}), }, } diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index d954ee762482..ca0ee48394ca 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -32,6 +32,28 @@ func (mock TxSearchMock) TxSearch(ctx context.Context, query string, prove bool, *perPage = 0 } +<<<<<<< HEAD +======= + // Get the `message.action` value from the query. + messageAction := regexp.MustCompile(`message\.action='(.*)' .*$`) + msgType := messageAction.FindStringSubmatch(query)[1] + + // Filter only the txs that match the query + matchingTxs := make([]tmtypes.Tx, 0) + for _, tx := range mock.txs { + sdkTx, err := mock.txConfig.TxDecoder()(tx) + if err != nil { + return nil, err + } + for _, msg := range sdkTx.GetMsgs() { + if sdk.MsgTypeURL(msg) == msgType { + matchingTxs = append(matchingTxs, tx) + break + } + } + } + +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) start, end := client.Paginate(len(mock.txs), *page, *perPage, 100) if start < 0 || end < 0 { // nil result with nil error crashes utils.QueryTxsByEvents diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 8cf1af8a5130..178f2d9b73cf 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -206,10 +206,24 @@ func simulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k simtypes.RandStringOfLength(r, 100), ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate a submit proposal msg"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate a submit proposal msg"), nil, err } account := ak.GetAccount(ctx, simAccount.Address) +<<<<<<< HEAD +======= + spendable := bk.SpendableCoins(ctx, account.GetAddress()) + + var fees sdk.Coins + coins, hasNeg := spendable.SafeSub(deposit...) + if !hasNeg { + fees, err = simtypes.RandomFees(r, ctx, coins) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate fees"), nil, err + } + } + +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) txGen := moduletestutil.MakeTestEncodingConfig().TxConfig tx, err := simtestutil.GenSignedMockTx( r, @@ -223,12 +237,12 @@ func simulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k simAccount.PrivKey, ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate mock tx"), nil, err } _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } opMsg := simtypes.NewOperationMsg(msg, true, "", nil) @@ -236,7 +250,7 @@ func simulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k // get the submitted proposal ID proposalID, err := k.GetProposalID(ctx) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate proposalID"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate proposalID"), nil, err } // 2) Schedule operations for votes @@ -294,7 +308,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.K if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate fees"), nil, err } } @@ -304,7 +318,6 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.K TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -354,7 +367,6 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k *ke TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -406,7 +418,6 @@ func operationSimulateMsgVoteWeighted(ak types.AccountKeeper, bk types.BankKeepe TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -419,6 +430,48 @@ func operationSimulateMsgVoteWeighted(ak types.AccountKeeper, bk types.BankKeepe } } +<<<<<<< HEAD +======= +// SimulateMsgCancelProposal generates a MsgCancelProposal. +func SimulateMsgCancelProposal(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper) simtypes.Operation { + return func( + r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, + accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + simAccount := accs[0] + proposal := randomProposal(r, k, ctx) + if proposal == nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgCancelProposal, "no proposals found"), nil, nil + } + + if proposal.Proposer != simAccount.Address.String() { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgCancelProposal, "invalid proposer"), nil, nil + } + + account := ak.GetAccount(ctx, simAccount.Address) + spendable := bk.SpendableCoins(ctx, account.GetAddress()) + + msg := v1.NewMsgCancelProposal(proposal.Id, account.GetAddress().String()) + + txCtx := simulation.OperationInput{ + R: r, + App: app, + TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, + Cdc: nil, + Msg: msg, + Context: ctx, + SimAccount: simAccount, + AccountKeeper: ak, + Bankkeeper: bk, + ModuleName: types.ModuleName, + CoinsSpentInMsg: spendable, + } + + return simulation.GenAndDeliverTxWithRandFees(txCtx) + } +} + +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) // Pick a random deposit with a random denomination with a // deposit amount between (0, min(balance, minDepositAmount)) // This is to simulate multiple users depositing to get the diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 4e5ee7665754..253af082f532 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -185,10 +185,56 @@ func TestSimulateMsgSubmitLegacyProposal(t *testing.T) { require.Equal(t, "2686011stake", msg.InitialDeposit[0].String()) require.Equal(t, "title-3: ZBSpYuLyYggwexjxusrBqDOTtGTOWeLrQKjLxzIivHSlcxgdXhhuTSkuxKGLwQvuyNhYFmBZHeAerqyNEUzXPFGkqEGqiQWIXnku", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetTitle()) require.Equal(t, "description-3: NJWzHdBNpAXKJPHWQdrGYcAHSctgVlqwqHoLfHsXUdStwfefwzqLuKEhmMyYLdbZrcPgYqjNHxPexsruwEGStAneKbWkQDDIlCWBLSiAASNhZqNFlPtfqPJoxKsgMdzjWqLWdqKQuJqWPMvwPQWZUtVMOTMYKJbfdlZsjdsomuScvDmbDkgRualsxDvRJuCAmPOXitIbcyWsKGSdrEunFAOdmXnsuyFVgJqEjbklvmwrUlsxjRSfKZxGcpayDdgoFcnVSutxjRgOSFzPwidAjubMncNweqpbxhXGchpZUxuFDOtpnhNUycJICRYqsPhPSCjPTWZFLkstHWJxvdPEAyEIxXgLwbNOjrgzmaujiBABBIXvcXpLrbcEWNNQsbjvgJFgJkflpRohHUutvnaUqoopuKjTDaemDeSdqbnOzcfJpcTuAQtZoiLZOoAIlboFDAeGmSNwkvObPRvRWQgWkGkxwtPauYgdkmypLjbqhlHJIQTntgWjXwZdOyYEdQRRLfMSdnxqppqUofqLbLQDUjwKVKfZJUJQPsWIPwIVaSTrmKskoAhvmZyJgeRpkaTfGgrJzAigcxtfshmiDCFkuiluqtMOkidknnTBtumyJYlIsWLnCQclqdVmikUoMOPdPWwYbJxXyqUVicNxFxyqJTenNblyyKSdlCbiXxUiYUiMwXZASYfvMDPFgxniSjWaZTjHkqlJvtBsXqwPpyVxnJVGFWhfSxgOcduoxkiopJvFjMmFabrGYeVtTXLhxVUEiGwYUvndjFGzDVntUvibiyZhfMQdMhgsiuysLMiePBNXifRLMsSmXPkwlPloUbJveCvUlaalhZHuvdkCnkSHbMbmOnrfEGPwQiACiPlnihiaOdbjPqPiTXaHDoJXjSlZmltGqNHHNrcKdlFSCdmVOuvDcBLdSklyGJmcLTbSFtALdGlPkqqecJrpLCXNPWefoTJNgEJlyMEPneVaxxduAAEqQpHWZodWyRkDAxzyMnFMcjSVqeRXLqsNyNtQBbuRvunZflWSbbvXXdkyLikYqutQhLPONXbvhcQZJPSWnOulqQaXmbfFxAkqfYeseSHOQidHwbcsOaMnSrrmGjjRmEMQNuknupMxJiIeVjmgZvbmjPIQTEhQFULQLBMPrxcFPvBinaOPYWGvYGRKxLZdwamfRQQFngcdSlvwjfaPbURasIsGJVHtcEAxnIIrhSriiXLOlbEBLXFElXJFGxHJczRBIxAuPKtBisjKBwfzZFagdNmjdwIRvwzLkFKWRTDPxJCmpzHUcrPiiXXHnOIlqNVoGSXZewdnCRhuxeYGPVTfrNTQNOxZmxInOazUYNTNDgzsxlgiVEHPKMfbesvPHUqpNkUqbzeuzfdrsuLDpKHMUbBMKczKKWOdYoIXoPYtEjfOnlQLoGnbQUCuERdEFaptwnsHzTJDsuZkKtzMpFaZobynZdzNydEeJJHDYaQcwUxcqvwfWwNUsCiLvkZQiSfzAHftYgAmVsXgtmcYgTqJIawstRYJrZdSxlfRiqTufgEQVambeZZmaAyRQbcmdjVUZZCgqDrSeltJGXPMgZnGDZqISrGDOClxXCxMjmKqEPwKHoOfOeyGmqWqihqjINXLqnyTesZePQRqaWDQNqpLgNrAUKulklmckTijUltQKuWQDwpLmDyxLppPVMwsmBIpOwQttYFMjgJQZLYFPmxWFLIeZihkRNnkzoypBICIxgEuYsVWGIGRbbxqVasYnstWomJnHwmtOhAFSpttRYYzBmyEtZXiCthvKvWszTXDbiJbGXMcrYpKAgvUVFtdKUfvdMfhAryctklUCEdjetjuGNfJjajZtvzdYaqInKtFPPLYmRaXPdQzxdSQfmZDEVHlHGEGNSPRFJuIfKLLfUmnHxHnRjmzQPNlqrXgifUdzAGKVabYqvcDeYoTYgPsBUqehrBhmQUgTvDnsdpuhUoxskDdppTsYMcnDIPSwKIqhXDCIxOuXrywahvVavvHkPuaenjLmEbMgrkrQLHEAwrhHkPRNvonNQKqprqOFVZKAtpRSpvQUxMoXCMZLSSbnLEFsjVfANdQNQVwTmGxqVjVqRuxREAhuaDrFgEZpYKhwWPEKBevBfsOIcaZKyykQafzmGPLRAKDtTcJxJVgiiuUkmyMYuDUNEUhBEdoBLJnamtLmMJQgmLiUELIhLpiEvpOXOvXCPUeldLFqkKOwfacqIaRcnnZvERKRMCKUkMABbDHytQqQblrvoxOZkwzosQfDKGtIdfcXRJNqlBNwOCWoQBcEWyqrMlYZIAXYJmLfnjoJepgSFvrgajaBAIksoyeHqgqbGvpAstMIGmIhRYGGNPRIfOQKsGoKgxtsidhTaAePRCBFqZgPDWCIkqOJezGVkjfYUCZTlInbxBXwUAVRsxHTQtJFnnpmMvXDYCVlEmnZBKhmmxQOIQzxFWpJQkQoSAYzTEiDWEOsVLNrbfzeHFRyeYATakQQWmFDLPbVMCJcWjFGJjfqCoVzlbNNEsqxdSmNPjTjHYOkuEMFLkXYGaoJlraLqayMeCsTjWNRDPBywBJLAPVkGQqTwApVVwYAetlwSbzsdHWsTwSIcctkyKDuRWYDQikRqsKTMJchrliONJeaZIzwPQrNbTwxsGdwuduvibtYndRwpdsvyCktRHFalvUuEKMqXbItfGcNGWsGzubdPMYayOUOINjpcFBeESdwpdlTYmrPsLsVDhpTzoMegKrytNVZkfJRPuDCUXxSlSthOohmsuxmIZUedzxKmowKOdXTMcEtdpHaPWgIsIjrViKrQOCONlSuazmLuCUjLltOGXeNgJKedTVrrVCpWYWHyVrdXpKgNaMJVjbXxnVMSChdWKuZdqpisvrkBJPoURDYxWOtpjzZoOpWzyUuYNhCzRoHsMjmmWDcXzQiHIyjwdhPNwiPqFxeUfMVFQGImhykFgMIlQEoZCaRoqSBXTSWAeDumdbsOGtATwEdZlLfoBKiTvodQBGOEcuATWXfiinSjPmJKcWgQrTVYVrwlyMWhxqNbCMpIQNoSMGTiWfPTCezUjYcdWppnsYJihLQCqbNLRGgqrwHuIvsazapTpoPZIyZyeeSueJuTIhpHMEJfJpScshJubJGfkusuVBgfTWQoywSSliQQSfbvaHKiLnyjdSbpMkdBgXepoSsHnCQaYuHQqZsoEOmJCiuQUpJkmfyfbIShzlZpHFmLCsbknEAkKXKfRTRnuwdBeuOGgFbJLbDksHVapaRayWzwoYBEpmrlAxrUxYMUekKbpjPNfjUCjhbdMAnJmYQVZBQZkFVweHDAlaqJjRqoQPoOMLhyvYCzqEuQsAFoxWrzRnTVjStPadhsESlERnKhpEPsfDxNvxqcOyIulaCkmPdambLHvGhTZzysvqFauEgkFRItPfvisehFmoBhQqmkfbHVsgfHXDPJVyhwPllQpuYLRYvGodxKjkarnSNgsXoKEMlaSKxKdcVgvOkuLcfLFfdtXGTclqfPOfeoVLbqcjcXCUEBgAGplrkgsmIEhWRZLlGPGCwKWRaCKMkBHTAcypUrYjWwCLtOPVygMwMANGoQwFnCqFrUGMCRZUGJKTZIGPyldsifauoMnJPLTcDHmilcmahlqOELaAUYDBuzsVywnDQfwRLGIWozYaOAilMBcObErwgTDNGWnwQMUgFFSKtPDMEoEQCTKVREqrXZSGLqwTMcxHfWotDllNkIJPMbXzjDVjPOOjCFuIvTyhXKLyhUScOXvYthRXpPfKwMhptXaxIxgqBoUqzrWbaoLTVpQoottZyPFfNOoMioXHRuFwMRYUiKvcWPkrayyTLOCFJlAyslDameIuqVAuxErqFPEWIScKpBORIuZqoXlZuTvAjEdlEWDODFRregDTqGNoFBIHxvimmIZwLfFyKUfEWAnNBdtdzDmTPXtpHRGdIbuucfTjOygZsTxPjfweXhSUkMhPjMaxKlMIJMOXcnQfyzeOcbWwNbeH", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetDescription()) - require.Equal(t, "gov", msg.Route()) - require.Equal(t, simulation.TypeMsgSubmitProposal, msg.Type()) + require.Equal(t, simulation.TypeMsgSubmitProposal, sdk.MsgTypeURL(&msg)) +} + +<<<<<<< HEAD +======= +// TestSimulateMsgCancelProposal tests the normal scenario of a valid message of type TypeMsgCancelProposal. +// Abnormal scenarios, where errors occur, are not tested here. +func TestSimulateMsgCancelProposal(t *testing.T) { + suite, ctx := createTestSuite(t, false) + app := suite.App + blockTime := time.Now().UTC() + ctx = ctx.WithBlockTime(blockTime) + + // setup 3 accounts + s := rand.NewSource(1) + r := rand.New(s) + accounts := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, ctx, 3) + // setup a proposal + proposer := accounts[0].Address + content := v1beta1.NewTextProposal("Test", "description") + contentMsg, err := v1.NewLegacyContent(content, suite.GovKeeper.GetGovernanceAccount(ctx).GetAddress().String()) + require.NoError(t, err) + + submitTime := ctx.BlockHeader().Time + depositPeriod := suite.GovKeeper.GetParams(ctx).MaxDepositPeriod + + proposal, err := v1.NewProposal([]sdk.Msg{contentMsg}, 1, "", submitTime, submitTime.Add(*depositPeriod), "title", "summary", proposer) + require.NoError(t, err) + + suite.GovKeeper.SetProposal(ctx, proposal) + + // begin a new block + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash, Time: blockTime}}) + + // execute operation + op := simulation.SimulateMsgCancelProposal(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper) + operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") + require.NoError(t, err) + + var msg v1.MsgCancelProposal + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + require.NoError(t, err) + + require.True(t, operationMsg.OK) + require.Equal(t, uint64(1), msg.ProposalId) + require.Equal(t, proposer.String(), msg.Proposer) + require.Equal(t, simulation.TypeMsgCancelProposal, sdk.MsgTypeURL(&msg)) } +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) // TestSimulateMsgDeposit tests the normal scenario of a valid message of type TypeMsgDeposit. // Abnormal scenarios, where errors occur, are not tested here. func TestSimulateMsgDeposit(t *testing.T) { @@ -232,8 +278,7 @@ func TestSimulateMsgDeposit(t *testing.T) { require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Depositor) require.NotEqual(t, len(msg.Amount), 0) require.Equal(t, "560969stake", msg.Amount[0].String()) - require.Equal(t, "gov", msg.Route()) - require.Equal(t, simulation.TypeMsgDeposit, msg.Type()) + require.Equal(t, simulation.TypeMsgDeposit, sdk.MsgTypeURL(&msg)) } // TestSimulateMsgVote tests the normal scenario of a valid message of type TypeMsgVote. @@ -277,8 +322,7 @@ func TestSimulateMsgVote(t *testing.T) { require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Voter) require.Equal(t, v1.OptionYes, msg.Option) - require.Equal(t, "gov", msg.Route()) - require.Equal(t, simulation.TypeMsgVote, msg.Type()) + require.Equal(t, simulation.TypeMsgVote, sdk.MsgTypeURL(&msg)) } // TestSimulateMsgVoteWeighted tests the normal scenario of a valid message of type TypeMsgVoteWeighted. @@ -321,8 +365,7 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Voter) require.True(t, len(msg.Options) >= 1) - require.Equal(t, "gov", msg.Route()) - require.Equal(t, simulation.TypeMsgVoteWeighted, msg.Type()) + require.Equal(t, simulation.TypeMsgVoteWeighted, sdk.MsgTypeURL(&msg)) } type suite struct { diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index f1b1667d59d5..bc0e1723d21c 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -9,14 +9,21 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdktx "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/gov/codec" "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) var ( +<<<<<<< HEAD _, _, _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{} _, _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{}, &MsgExecLegacyContent{} +======= + _, _, _, _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} + _, _, _, _, _, _, _ legacytx.LegacyMsg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} + _, _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{}, &MsgExecLegacyContent{} +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) ) // NewMsgSubmitProposal creates a new MsgSubmitProposal. @@ -46,12 +53,6 @@ func (m *MsgSubmitProposal) GetMsgs() ([]sdk.Msg, error) { return sdktx.GetMsgs(m.Messages, "sdk.MsgProposal") } -// Route implements the sdk.Msg interface. -func (m MsgSubmitProposal) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (m MsgSubmitProposal) Type() string { return sdk.MsgTypeURL(&m) } - // ValidateBasic implements the sdk.Msg interface. func (m MsgSubmitProposal) ValidateBasic() error { if m.Title == "" { @@ -118,12 +119,6 @@ func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins return &MsgDeposit{proposalID, depositor.String(), amount} } -// Route implements the sdk.Msg interface. -func (msg MsgDeposit) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgDeposit) Type() string { return sdk.MsgTypeURL(&msg) } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgDeposit) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Depositor); err != nil { @@ -159,12 +154,6 @@ func NewMsgVote(voter sdk.AccAddress, proposalID uint64, option VoteOption, meta return &MsgVote{proposalID, voter.String(), option, metadata} } -// Route implements the sdk.Msg interface. -func (msg MsgVote) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgVote) Type() string { return sdk.MsgTypeURL(&msg) } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgVote) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Voter); err != nil { @@ -196,12 +185,6 @@ func NewMsgVoteWeighted(voter sdk.AccAddress, proposalID uint64, options Weighte return &MsgVoteWeighted{proposalID, voter.String(), options, metadata} } -// Route implements the sdk.Msg interface. -func (msg MsgVoteWeighted) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgVoteWeighted) Type() string { return sdk.MsgTypeURL(&msg) } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgVoteWeighted) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Voter); err != nil { @@ -261,6 +244,12 @@ func NewMsgExecLegacyContent(content *codectypes.Any, authority string) *MsgExec } } +// GetSignBytes returns the message bytes to sign over. +func (c MsgExecLegacyContent) GetSignBytes() []byte { + bz := codec.ModuleCdc.MustMarshalJSON(&c) + return sdk.MustSortJSON(bz) +} + // GetSigners returns the expected signers for a MsgExecLegacyContent. func (c MsgExecLegacyContent) GetSigners() []sdk.AccAddress { authority, _ := sdk.AccAddressFromBech32(c.Authority) @@ -283,12 +272,6 @@ func (c MsgExecLegacyContent) UnpackInterfaces(unpacker codectypes.AnyUnpacker) return unpacker.UnpackAny(c.Content, &content) } -// Route implements the sdk.Msg interface. -func (msg MsgUpdateParams) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgUpdateParams) Type() string { return sdk.MsgTypeURL(&msg) } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { @@ -309,3 +292,37 @@ func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { authority, _ := sdk.AccAddressFromBech32(msg.Authority) return []sdk.AccAddress{authority} } +<<<<<<< HEAD +======= + +// NewMsgCancelProposal creates a new MsgCancelProposal instance +// +//nolint:interfacer +func NewMsgCancelProposal(proposalID uint64, proposer string) *MsgCancelProposal { + return &MsgCancelProposal{ + ProposalId: proposalID, + Proposer: proposer, + } +} + +// ValidateBasic implements Msg +func (msg MsgCancelProposal) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Proposer); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid proposer address: %s", err) + } + + return nil +} + +// GetSignBytes implements Msg +func (msg MsgCancelProposal) GetSignBytes() []byte { + bz := codec.ModuleCdc.MustMarshalJSON(&msg) + return sdk.MustSortJSON(bz) +} + +// GetSigners implements Msg +func (msg MsgCancelProposal) GetSigners() []sdk.AccAddress { + proposer, _ := sdk.AccAddressFromBech32(msg.Proposer) + return []sdk.AccAddress{proposer} +} +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) diff --git a/x/gov/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index 2c20ca6b64c0..d16b86950f7e 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -10,6 +10,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/gov/codec" "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -23,8 +24,10 @@ const ( ) var ( - _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} - _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{} + _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} + _, _, _, _ legacytx.LegacyMsg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} + + _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{} ) // NewMsgSubmitProposal creates a new MsgSubmitProposal. @@ -84,12 +87,6 @@ func (m *MsgSubmitProposal) SetContent(content Content) error { return nil } -// Route implements the sdk.Msg interface. -func (m MsgSubmitProposal) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (m MsgSubmitProposal) Type() string { return TypeMsgSubmitProposal } - // ValidateBasic implements the sdk.Msg interface. func (m MsgSubmitProposal) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Proposer); err != nil { @@ -147,12 +144,6 @@ func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins return &MsgDeposit{proposalID, depositor.String(), amount} } -// Route implements the sdk.Msg interface. -func (msg MsgDeposit) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgDeposit) Type() string { return TypeMsgDeposit } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgDeposit) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Depositor); err != nil { @@ -193,12 +184,6 @@ func NewMsgVote(voter sdk.AccAddress, proposalID uint64, option VoteOption) *Msg return &MsgVote{proposalID, voter.String(), option} } -// Route implements the sdk.Msg interface. -func (msg MsgVote) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgVote) Type() string { return TypeMsgVote } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgVote) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Voter); err != nil { @@ -236,12 +221,6 @@ func NewMsgVoteWeighted(voter sdk.AccAddress, proposalID uint64, options Weighte return &MsgVoteWeighted{proposalID, voter.String(), options} } -// Route implements the sdk.Msg interface. -func (msg MsgVoteWeighted) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgVoteWeighted) Type() string { return TypeMsgVoteWeighted } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgVoteWeighted) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Voter); err != nil { diff --git a/x/group/msgs.go b/x/group/msgs.go index 8e3457b90294..b7c5625005df 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -7,18 +7,16 @@ 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/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/group/codec" "github.com/cosmos/cosmos-sdk/x/group/errors" "github.com/cosmos/cosmos-sdk/x/group/internal/math" ) -var _ sdk.Msg = &MsgCreateGroup{} - -// Route Implements Msg. -func (m MsgCreateGroup) Route() string { return sdk.MsgTypeURL(&m) } - -// Type Implements Msg. -func (m MsgCreateGroup) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgCreateGroup{} + _ legacytx.LegacyMsg = &MsgCreateGroup{} +) // GetSignBytes Implements Msg. func (m MsgCreateGroup) GetSignBytes() []byte { @@ -60,15 +58,10 @@ func (m MemberRequest) ValidateBasic() error { return nil } -var _ sdk.Msg = &MsgUpdateGroupAdmin{} - -// Route Implements Msg. -func (m MsgUpdateGroupAdmin) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupAdmin) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgUpdateGroupAdmin{} + _ legacytx.LegacyMsg = &MsgUpdateGroupAdmin{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupAdmin) GetSignBytes() []byte { @@ -109,15 +102,10 @@ func (m *MsgUpdateGroupAdmin) GetGroupID() uint64 { return m.GroupId } -var _ sdk.Msg = &MsgUpdateGroupMetadata{} - -// Route Implements Msg. -func (m MsgUpdateGroupMetadata) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupMetadata) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgUpdateGroupMetadata{} + _ legacytx.LegacyMsg = &MsgUpdateGroupMetadata{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupMetadata) GetSignBytes() []byte { @@ -149,15 +137,10 @@ func (m *MsgUpdateGroupMetadata) GetGroupID() uint64 { return m.GroupId } -var _ sdk.Msg = &MsgUpdateGroupMembers{} - -// Route Implements Msg. -func (m MsgUpdateGroupMembers) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupMembers) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgUpdateGroupMembers{} + _ legacytx.LegacyMsg = &MsgUpdateGroupMembers{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupMembers) GetSignBytes() []byte { @@ -199,7 +182,9 @@ func (m *MsgUpdateGroupMembers) GetGroupID() uint64 { } var ( - _ sdk.Msg = &MsgCreateGroupWithPolicy{} + _ sdk.Msg = &MsgCreateGroupWithPolicy{} + _ legacytx.LegacyMsg = &MsgCreateGroupWithPolicy{} + _ types.UnpackInterfacesMessage = MsgCreateGroupWithPolicy{} ) @@ -244,16 +229,6 @@ func (m MsgCreateGroupWithPolicy) UnpackInterfaces(unpacker types.AnyUnpacker) e return unpacker.UnpackAny(m.DecisionPolicy, &decisionPolicy) } -// Route Implements Msg. -func (m MsgCreateGroupWithPolicy) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgCreateGroupWithPolicy) Type() string { - return sdk.MsgTypeURL(&m) -} - // GetSignBytes Implements Msg. func (m MsgCreateGroupWithPolicy) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) @@ -282,15 +257,10 @@ func (m MsgCreateGroupWithPolicy) ValidateBasic() error { return strictValidateMembers(m.Members) } -var _ sdk.Msg = &MsgCreateGroupPolicy{} - -// Route Implements Msg. -func (m MsgCreateGroupPolicy) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgCreateGroupPolicy) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgCreateGroupPolicy{} + _ legacytx.LegacyMsg = &MsgCreateGroupPolicy{} +) // GetSignBytes Implements Msg. func (m MsgCreateGroupPolicy) GetSignBytes() []byte { @@ -324,15 +294,10 @@ func (m MsgCreateGroupPolicy) ValidateBasic() error { return nil } -var _ sdk.Msg = &MsgUpdateGroupPolicyAdmin{} - -// Route Implements Msg. -func (m MsgUpdateGroupPolicyAdmin) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupPolicyAdmin) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgUpdateGroupPolicyAdmin{} + _ legacytx.LegacyMsg = &MsgUpdateGroupPolicyAdmin{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyAdmin) GetSignBytes() []byte { @@ -370,7 +335,9 @@ func (m MsgUpdateGroupPolicyAdmin) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgUpdateGroupPolicyDecisionPolicy{} + _ sdk.Msg = &MsgUpdateGroupPolicyDecisionPolicy{} + _ legacytx.LegacyMsg = &MsgUpdateGroupPolicyDecisionPolicy{} + _ types.UnpackInterfacesMessage = MsgUpdateGroupPolicyDecisionPolicy{} ) @@ -401,16 +368,6 @@ func (m *MsgUpdateGroupPolicyDecisionPolicy) SetDecisionPolicy(decisionPolicy De return nil } -// Route Implements Msg. -func (m MsgUpdateGroupPolicyDecisionPolicy) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupPolicyDecisionPolicy) Type() string { - return sdk.MsgTypeURL(&m) -} - // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyDecisionPolicy) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) @@ -463,15 +420,10 @@ func (m MsgUpdateGroupPolicyDecisionPolicy) UnpackInterfaces(unpacker types.AnyU return unpacker.UnpackAny(m.DecisionPolicy, &decisionPolicy) } -var _ sdk.Msg = &MsgUpdateGroupPolicyMetadata{} - -// Route Implements Msg. -func (m MsgUpdateGroupPolicyMetadata) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupPolicyMetadata) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgUpdateGroupPolicyMetadata{} + _ legacytx.LegacyMsg = &MsgUpdateGroupPolicyMetadata{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyMetadata) GetSignBytes() []byte { @@ -501,7 +453,9 @@ func (m MsgUpdateGroupPolicyMetadata) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgCreateGroupPolicy{} + _ sdk.Msg = &MsgCreateGroupPolicy{} + _ legacytx.LegacyMsg = &MsgCreateGroupPolicy{} + _ types.UnpackInterfacesMessage = MsgCreateGroupPolicy{} ) @@ -559,7 +513,10 @@ func (m MsgCreateGroupPolicy) UnpackInterfaces(unpacker types.AnyUnpacker) error return unpacker.UnpackAny(m.DecisionPolicy, &decisionPolicy) } -var _ sdk.Msg = &MsgSubmitProposal{} +var ( + _ sdk.Msg = &MsgSubmitProposal{} + _ legacytx.LegacyMsg = &MsgSubmitProposal{} +) // NewMsgSubmitProposal creates a new MsgSubmitProposal. func NewMsgSubmitProposal(address string, proposers []string, msgs []sdk.Msg, metadata string, exec Exec, title, summary string) (*MsgSubmitProposal, error) { @@ -578,14 +535,6 @@ func NewMsgSubmitProposal(address string, proposers []string, msgs []sdk.Msg, me return m, nil } -// Route Implements Msg. -func (m MsgSubmitProposal) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgSubmitProposal) Type() string { return sdk.MsgTypeURL(&m) } - // GetSignBytes Implements Msg. func (m MsgSubmitProposal) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) @@ -678,13 +627,10 @@ func (m MsgSubmitProposal) UnpackInterfaces(unpacker types.AnyUnpacker) error { return tx.UnpackInterfaces(unpacker, m.Messages) } -var _ sdk.Msg = &MsgWithdrawProposal{} - -// Route Implements Msg. -func (m MsgWithdrawProposal) Route() string { return sdk.MsgTypeURL(&m) } - -// Type Implements Msg. -func (m MsgWithdrawProposal) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgWithdrawProposal{} + _ legacytx.LegacyMsg = &MsgWithdrawProposal{} +) // GetSignBytes Implements Msg. func (m MsgWithdrawProposal) GetSignBytes() []byte { @@ -712,15 +658,10 @@ func (m MsgWithdrawProposal) ValidateBasic() error { return nil } -var _ sdk.Msg = &MsgVote{} - -// Route Implements Msg. -func (m MsgVote) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgVote) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgVote{} + _ legacytx.LegacyMsg = &MsgVote{} +) // GetSignBytes Implements Msg. func (m MsgVote) GetSignBytes() []byte { @@ -752,15 +693,10 @@ func (m MsgVote) ValidateBasic() error { return nil } -var _ sdk.Msg = &MsgExec{} - -// Route Implements Msg. -func (m MsgExec) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgExec) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgExec{} + _ legacytx.LegacyMsg = &MsgExec{} +) // GetSignBytes Implements Msg. func (m MsgExec) GetSignBytes() []byte { @@ -786,15 +722,10 @@ func (m MsgExec) ValidateBasic() error { return nil } -var _ sdk.Msg = &MsgLeaveGroup{} - -// Route Implements Msg -func (m MsgLeaveGroup) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg -func (m MsgLeaveGroup) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgLeaveGroup{} + _ legacytx.LegacyMsg = &MsgLeaveGroup{} +) // GetSignBytes Implements Msg func (m MsgLeaveGroup) GetSignBytes() []byte { diff --git a/x/group/msgs_test.go b/x/group/msgs_test.go index f5ff82913931..acfdeb5b6f9f 100644 --- a/x/group/msgs_test.go +++ b/x/group/msgs_test.go @@ -153,7 +153,7 @@ func TestMsgCreateGroup(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&group.MsgCreateGroup{})) + require.Equal(t, sdk.MsgTypeURL(tc.msg), sdk.MsgTypeURL(&group.MsgCreateGroup{})) } }) } @@ -224,7 +224,7 @@ func TestMsgUpdateGroupAdmin(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupAdmin{})) + require.Equal(t, sdk.MsgTypeURL(tc.msg), sdk.MsgTypeURL(&group.MsgUpdateGroupAdmin{})) } }) } @@ -274,7 +274,7 @@ func TestMsgUpdateGroupMetadata(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupMetadata{})) + require.Equal(t, sdk.MsgTypeURL(tc.msg), sdk.MsgTypeURL(&group.MsgUpdateGroupMetadata{})) } }) } @@ -354,7 +354,7 @@ func TestMsgUpdateGroupMembers(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupMembers{})) + require.Equal(t, sdk.MsgTypeURL(tc.msg), sdk.MsgTypeURL(&group.MsgUpdateGroupMembers{})) } }) } @@ -533,7 +533,7 @@ func TestMsgCreateGroupWithPolicy(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgCreateGroupWithPolicy{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgCreateGroupWithPolicy{})) } }) } @@ -688,7 +688,7 @@ func TestMsgCreateGroupPolicy(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgCreateGroupPolicy{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgCreateGroupPolicy{})) } }) } @@ -788,7 +788,7 @@ func TestMsgUpdateGroupPolicyDecisionPolicy(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyDecisionPolicy{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyDecisionPolicy{})) } }) } @@ -860,7 +860,7 @@ func TestMsgUpdateGroupPolicyAdmin(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyAdmin{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyAdmin{})) } }) } @@ -911,7 +911,7 @@ func TestMsgUpdateGroupPolicyMetadata(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyMetadata{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyMetadata{})) } }) } @@ -984,7 +984,7 @@ func TestMsgSubmitProposal(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgSubmitProposal{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgSubmitProposal{})) } }) } @@ -1069,7 +1069,7 @@ func TestMsgVote(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgVote{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgVote{})) } }) } @@ -1118,7 +1118,7 @@ func TestMsgWithdrawProposal(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgWithdrawProposal{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgWithdrawProposal{})) } }) } @@ -1166,7 +1166,7 @@ func TestMsgExec(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgExec{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgExec{})) } }) } @@ -1214,7 +1214,7 @@ func TestMsgLeaveGroup(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgLeaveGroup{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgLeaveGroup{})) } }) } diff --git a/x/group/simulation/operations.go b/x/group/simulation/operations.go index fe6b53eda0fc..a03934dbf714 100644 --- a/x/group/simulation/operations.go +++ b/x/group/simulation/operations.go @@ -280,7 +280,7 @@ func SimulateMsgCreateGroup(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk gr _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, err @@ -319,7 +319,7 @@ func SimulateMsgCreateGroupWithPolicy(cdc *codec.ProtoCodec, ak group.AccountKee } msg.SetDecisionPolicy(decisionPolicy) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to set decision policy"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to set decision policy"), nil, err } txGen := tx.NewTxConfig(cdc, tx.DefaultSignModes) @@ -340,7 +340,7 @@ func SimulateMsgCreateGroupWithPolicy(cdc *codec.ProtoCodec, ak group.AccountKee _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil @@ -401,7 +401,7 @@ func SimulateMsgCreateGroupPolicy(cdc *codec.ProtoCodec, ak group.AccountKeeper, _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { fmt.Printf("ERR DELIVER %v\n", err) - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, err @@ -452,7 +452,7 @@ func SimulateMsgSubmitProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, "fee error"), nil, err } - msg := group.MsgSubmitProposal{ + msg := &group.MsgSubmitProposal{ GroupPolicyAddress: groupPolicyAddr, Proposers: []string{acc.Address.String()}, Metadata: simtypes.RandStringOfLength(r, 10), @@ -464,7 +464,7 @@ func SimulateMsgSubmitProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -478,10 +478,10 @@ func SimulateMsgSubmitProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -514,7 +514,7 @@ func SimulateMsgUpdateGroupAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, newAdmin, _ = simtypes.RandomAcc(r, accounts) } - msg := group.MsgUpdateGroupAdmin{ + msg := &group.MsgUpdateGroupAdmin{ GroupId: groupID, Admin: account.GetAddress().String(), NewAdmin: newAdmin.Address.String(), @@ -524,7 +524,7 @@ func SimulateMsgUpdateGroupAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -538,10 +538,10 @@ func SimulateMsgUpdateGroupAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -565,7 +565,7 @@ func SimulateMsgUpdateGroupMetadata(cdc *codec.ProtoCodec, ak group.AccountKeepe return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMetadata, "fee error"), nil, err } - msg := group.MsgUpdateGroupMetadata{ + msg := &group.MsgUpdateGroupMetadata{ GroupId: groupID, Admin: account.GetAddress().String(), Metadata: simtypes.RandStringOfLength(r, 10), @@ -575,7 +575,7 @@ func SimulateMsgUpdateGroupMetadata(cdc *codec.ProtoCodec, ak group.AccountKeepe tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -589,10 +589,10 @@ func SimulateMsgUpdateGroupMetadata(cdc *codec.ProtoCodec, ak group.AccountKeepe _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -645,7 +645,7 @@ func SimulateMsgUpdateGroupMembers(cdc *codec.ProtoCodec, ak group.AccountKeeper } } - msg := group.MsgUpdateGroupMembers{ + msg := &group.MsgUpdateGroupMembers{ GroupId: groupID, Admin: acc.Address.String(), MemberUpdates: members, @@ -655,7 +655,7 @@ func SimulateMsgUpdateGroupMembers(cdc *codec.ProtoCodec, ak group.AccountKeeper tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -669,10 +669,10 @@ func SimulateMsgUpdateGroupMembers(cdc *codec.ProtoCodec, ak group.AccountKeeper _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -705,7 +705,7 @@ func SimulateMsgUpdateGroupPolicyAdmin(cdc *codec.ProtoCodec, ak group.AccountKe newAdmin, _ = simtypes.RandomAcc(r, accounts) } - msg := group.MsgUpdateGroupPolicyAdmin{ + msg := &group.MsgUpdateGroupPolicyAdmin{ Admin: acc.Address.String(), GroupPolicyAddress: groupPolicyAddr, NewAdmin: newAdmin.Address.String(), @@ -715,7 +715,7 @@ func SimulateMsgUpdateGroupPolicyAdmin(cdc *codec.ProtoCodec, ak group.AccountKe tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -729,10 +729,10 @@ func SimulateMsgUpdateGroupPolicyAdmin(cdc *codec.ProtoCodec, ak group.AccountKe _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -791,7 +791,7 @@ func SimulateMsgUpdateGroupPolicyDecisionPolicy(cdc *codec.ProtoCodec, ak group. _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } @@ -819,7 +819,7 @@ func SimulateMsgUpdateGroupPolicyMetadata(cdc *codec.ProtoCodec, ak group.Accoun return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyMetadata, "fee error"), nil, err } - msg := group.MsgUpdateGroupPolicyMetadata{ + msg := &group.MsgUpdateGroupPolicyMetadata{ Admin: acc.Address.String(), GroupPolicyAddress: groupPolicyAddr, Metadata: simtypes.RandStringOfLength(r, 10), @@ -829,7 +829,7 @@ func SimulateMsgUpdateGroupPolicyMetadata(cdc *codec.ProtoCodec, ak group.Accoun tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -843,10 +843,10 @@ func SimulateMsgUpdateGroupPolicyMetadata(cdc *codec.ProtoCodec, ak group.Accoun _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -923,7 +923,7 @@ func SimulateMsgWithdrawProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, "fee error"), nil, err } - msg := group.MsgWithdrawProposal{ + msg := &group.MsgWithdrawProposal{ ProposalId: uint64(proposalID), Address: proposer.Address.String(), } @@ -932,7 +932,7 @@ func SimulateMsgWithdrawProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -948,12 +948,12 @@ func SimulateMsgWithdrawProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, if err != nil { if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "no-op:group/group-policy was modified"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "no-op:group/group-policy was modified"), nil, nil } - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -1028,7 +1028,7 @@ func SimulateMsgVote(cdc *codec.ProtoCodec, ak group.AccountKeeper, return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "member has already voted"), nil, nil } - msg := group.MsgVote{ + msg := &group.MsgVote{ ProposalId: uint64(proposalID), Voter: acc.Address.String(), Option: group.VOTE_OPTION_YES, @@ -1038,7 +1038,7 @@ func SimulateMsgVote(cdc *codec.ProtoCodec, ak group.AccountKeeper, tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -1054,12 +1054,12 @@ func SimulateMsgVote(cdc *codec.ProtoCodec, ak group.AccountKeeper, if err != nil { if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "no-op:group/group-policy was modified"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "no-op:group/group-policy was modified"), nil, nil } - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -1072,27 +1072,27 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { _, groupPolicy, acc, account, err := randomGroupPolicy(r, k, ak, sdkCtx, accounts) if err != nil { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, ""), nil, err + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, ""), nil, err } if groupPolicy == nil { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "no group policy found"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "no group policy found"), nil, nil } groupPolicyAddr := groupPolicy.Address spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress()) fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins) if err != nil { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "fee error"), nil, err + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "fee error"), nil, err } ctx := sdk.WrapSDKContext(sdkCtx) proposalsResult, err := k.ProposalsByGroupPolicy(ctx, &group.QueryProposalsByGroupPolicyRequest{Address: groupPolicyAddr}) if err != nil { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "fail to query group info"), nil, err + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "fail to query group info"), nil, err } proposals := proposalsResult.GetProposals() if len(proposals) == 0 { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "no proposals found"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "no proposals found"), nil, nil } proposalID := -1 @@ -1106,10 +1106,10 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, // return no-op if no proposal found if proposalID == -1 { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "no proposals found"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "no proposals found"), nil, nil } - msg := group.MsgExec{ + msg := &group.MsgExec{ ProposalId: uint64(proposalID), Executor: acc.Address.String(), } @@ -1117,7 +1117,7 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -1132,12 +1132,12 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "no-op:group/group-policy was modified"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "no-op:group/group-policy was modified"), nil, nil } - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -1194,7 +1194,7 @@ func SimulateMsgLeaveGroup(cdc *codec.ProtoCodec, k keeper.Keeper, ak group.Acco _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), err.Error()), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), err.Error()), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, err diff --git a/x/group/simulation/operations_test.go b/x/group/simulation/operations_test.go index 31d196ca75e4..ce42c98fcfa9 100644 --- a/x/group/simulation/operations_test.go +++ b/x/group/simulation/operations_test.go @@ -70,21 +70,21 @@ func (suite *SimTestSuite) TestWeightedOperations() { opMsgRoute string opMsgName string }{ - {simulation.WeightMsgCreateGroup, group.MsgCreateGroup{}.Route(), simulation.TypeMsgCreateGroup}, - {simulation.WeightMsgCreateGroupPolicy, group.MsgCreateGroupPolicy{}.Route(), simulation.TypeMsgCreateGroupPolicy}, - {simulation.WeightMsgCreateGroupWithPolicy, group.MsgCreateGroupWithPolicy{}.Route(), simulation.TypeMsgCreateGroupWithPolicy}, - {simulation.WeightMsgSubmitProposal, group.MsgSubmitProposal{}.Route(), simulation.TypeMsgSubmitProposal}, - {simulation.WeightMsgSubmitProposal, group.MsgSubmitProposal{}.Route(), simulation.TypeMsgSubmitProposal}, - {simulation.WeightMsgWithdrawProposal, group.MsgWithdrawProposal{}.Route(), simulation.TypeMsgWithdrawProposal}, - {simulation.WeightMsgVote, group.MsgVote{}.Route(), simulation.TypeMsgVote}, - {simulation.WeightMsgExec, group.MsgExec{}.Route(), simulation.TypeMsgExec}, - {simulation.WeightMsgUpdateGroupMetadata, group.MsgUpdateGroupMetadata{}.Route(), simulation.TypeMsgUpdateGroupMetadata}, - {simulation.WeightMsgUpdateGroupAdmin, group.MsgUpdateGroupAdmin{}.Route(), simulation.TypeMsgUpdateGroupAdmin}, - {simulation.WeightMsgUpdateGroupMembers, group.MsgUpdateGroupMembers{}.Route(), simulation.TypeMsgUpdateGroupMembers}, - {simulation.WeightMsgUpdateGroupPolicyAdmin, group.MsgUpdateGroupPolicyAdmin{}.Route(), simulation.TypeMsgUpdateGroupPolicyAdmin}, - {simulation.WeightMsgUpdateGroupPolicyDecisionPolicy, group.MsgUpdateGroupPolicyDecisionPolicy{}.Route(), simulation.TypeMsgUpdateGroupPolicyDecisionPolicy}, - {simulation.WeightMsgUpdateGroupPolicyMetadata, group.MsgUpdateGroupPolicyMetadata{}.Route(), simulation.TypeMsgUpdateGroupPolicyMetadata}, - {simulation.WeightMsgLeaveGroup, group.MsgLeaveGroup{}.Route(), simulation.TypeMsgLeaveGroup}, + {simulation.WeightMsgCreateGroup, group.ModuleName, simulation.TypeMsgCreateGroup}, + {simulation.WeightMsgCreateGroupPolicy, group.ModuleName, simulation.TypeMsgCreateGroupPolicy}, + {simulation.WeightMsgCreateGroupWithPolicy, group.ModuleName, simulation.TypeMsgCreateGroupWithPolicy}, + {simulation.WeightMsgSubmitProposal, group.ModuleName, simulation.TypeMsgSubmitProposal}, + {simulation.WeightMsgSubmitProposal, group.ModuleName, simulation.TypeMsgSubmitProposal}, + {simulation.WeightMsgWithdrawProposal, group.ModuleName, simulation.TypeMsgWithdrawProposal}, + {simulation.WeightMsgVote, group.ModuleName, simulation.TypeMsgVote}, + {simulation.WeightMsgExec, group.ModuleName, simulation.TypeMsgExec}, + {simulation.WeightMsgUpdateGroupMetadata, group.ModuleName, simulation.TypeMsgUpdateGroupMetadata}, + {simulation.WeightMsgUpdateGroupAdmin, group.ModuleName, simulation.TypeMsgUpdateGroupAdmin}, + {simulation.WeightMsgUpdateGroupMembers, group.ModuleName, simulation.TypeMsgUpdateGroupMembers}, + {simulation.WeightMsgUpdateGroupPolicyAdmin, group.ModuleName, simulation.TypeMsgUpdateGroupPolicyAdmin}, + {simulation.WeightMsgUpdateGroupPolicyDecisionPolicy, group.ModuleName, simulation.TypeMsgUpdateGroupPolicyDecisionPolicy}, + {simulation.WeightMsgUpdateGroupPolicyMetadata, group.ModuleName, simulation.TypeMsgUpdateGroupPolicyMetadata}, + {simulation.WeightMsgLeaveGroup, group.ModuleName, simulation.TypeMsgLeaveGroup}, } for i, w := range weightedOps { diff --git a/x/mint/types/msgs.go b/x/mint/types/msgs.go index a08186ef312c..366a0a02a4c7 100644 --- a/x/mint/types/msgs.go +++ b/x/mint/types/msgs.go @@ -3,9 +3,13 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) -var _ sdk.Msg = &MsgUpdateParams{} +var ( + _ sdk.Msg = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} +) // GetSignBytes implements the LegacyMsg interface. func (m MsgUpdateParams) GetSignBytes() []byte { @@ -13,13 +17,13 @@ func (m MsgUpdateParams) GetSignBytes() []byte { } // GetSigners returns the expected signers for a MsgUpdateParams message. -func (m *MsgUpdateParams) GetSigners() []sdk.AccAddress { +func (m MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(m.Authority) return []sdk.AccAddress{addr} } // ValidateBasic does a sanity check on the provided data. -func (m *MsgUpdateParams) ValidateBasic() error { +func (m MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } diff --git a/x/simulation/event_stats.go b/x/simulation/event_stats.go index 675380e8215a..d34b716e561e 100644 --- a/x/simulation/event_stats.go +++ b/x/simulation/event_stats.go @@ -17,18 +17,18 @@ func NewEventStats() EventStats { } // Tally increases the count of a simulation event. -func (es EventStats) Tally(route, op, evResult string) { - _, ok := es[route] +func (es EventStats) Tally(moduleName, op, evResult string) { + _, ok := es[moduleName] if !ok { - es[route] = make(map[string]map[string]int) + es[moduleName] = make(map[string]map[string]int) } - _, ok = es[route][op] + _, ok = es[moduleName][op] if !ok { - es[route][op] = make(map[string]int) + es[moduleName][op] = make(map[string]int) } - es[route][op][evResult]++ + es[moduleName][op][evResult]++ } // Print the event stats in JSON format. diff --git a/x/simulation/util.go b/x/simulation/util.go index f65a3f035b2d..13e90bb29ef3 100644 --- a/x/simulation/util.go +++ b/x/simulation/util.go @@ -68,7 +68,6 @@ type OperationInput struct { TxGen client.TxConfig Cdc *codec.ProtoCodec Msg sdk.Msg - MsgType string CoinsSpentInMsg sdk.Coins Context sdk.Context SimAccount simtypes.Account @@ -87,12 +86,12 @@ func GenAndDeliverTxWithRandFees(txCtx OperationInput) (simtypes.OperationMsg, [ coins, hasNeg := spendable.SafeSub(txCtx.CoinsSpentInMsg...) if hasNeg { - return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "message doesn't leave room for fees"), nil, err + return simtypes.NoOpMsg(txCtx.ModuleName, sdk.MsgTypeURL(txCtx.Msg), "message doesn't leave room for fees"), nil, err } fees, err = simtypes.RandomFees(txCtx.R, txCtx.Context, coins) if err != nil { - return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "unable to generate fees"), nil, err + return simtypes.NoOpMsg(txCtx.ModuleName, sdk.MsgTypeURL(txCtx.Msg), "unable to generate fees"), nil, err } return GenAndDeliverTx(txCtx, fees) } @@ -112,12 +111,12 @@ func GenAndDeliverTx(txCtx OperationInput, fees sdk.Coins) (simtypes.OperationMs txCtx.SimAccount.PrivKey, ) if err != nil { - return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(txCtx.ModuleName, sdk.MsgTypeURL(txCtx.Msg), "unable to generate mock tx"), nil, err } _, _, err = txCtx.App.SimDeliver(txCtx.TxGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(txCtx.ModuleName, sdk.MsgTypeURL(txCtx.Msg), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(txCtx.Msg, true, "", txCtx.Cdc), nil, nil diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 47c7155f0350..41649e2793d1 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -52,33 +52,35 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgUnjail{}) + validator, ok := testutil.RandSliceElem(r, sk.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "validator is not ok"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is not ok"), nil, nil // skip } simAccount, found := simtypes.FindAccount(accs, sdk.AccAddress(validator.GetOperator())) if !found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to find account"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to find account"), nil, nil // skip } if !validator.IsJailed() { // TODO: due to this condition this message is almost, if not always, skipped ! - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "validator is not jailed"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is not jailed"), nil, nil } consAddr, err := validator.GetConsAddr() if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to get validator consensus key"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to get validator consensus key"), nil, err } info, found := k.GetValidatorSigningInfo(ctx, consAddr) if !found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to find validator signing info"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to find validator signing info"), nil, nil // skip } selfDel := sk.Delegation(ctx, simAccount.Address, validator.GetOperator()) if selfDel == nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "self delegation is nil"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "self delegation is nil"), nil, nil // skip } account := ak.GetAccount(ctx, sdk.AccAddress(validator.GetOperator())) @@ -86,7 +88,7 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B fees, err := simtypes.RandomFees(r, ctx, spendable) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate fees"), nil, err } msg := types.NewMsgUnjail(validator.GetOperator()) @@ -104,7 +106,7 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B simAccount.PrivKey, ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate mock tx"), nil, err } _, res, err := app.SimDeliver(txGen.TxEncoder(), tx) @@ -132,7 +134,7 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B } if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, errors.New(res.Log) + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, errors.New(res.Log) } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 991ac17f0b3c..d3595dd7fcae 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -123,7 +123,9 @@ func (suite *SimTestSuite) TestWeightedOperations() { weight int opMsgRoute string opMsgName string - }{{simulation.DefaultWeightMsgUnjail, types.ModuleName, types.TypeMsgUnjail}} + }{ + {simulation.DefaultWeightMsgUnjail, types.ModuleName, sdk.MsgTypeURL(&types.MsgUnjail{})}, + } weightesOps := simulation.WeightedOperations(appParams, suite.codec, suite.accountKeeper, suite.bankKeeper, suite.slashingKeeper, suite.stakingKeeper) for i, w := range weightesOps { @@ -181,7 +183,6 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) - suite.Require().Equal(types.TypeMsgUnjail, msg.Type()) suite.Require().Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddr) suite.Require().Len(futureOperations, 0) } diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index 4f958ec1a456..df9178fd3d6f 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -3,17 +3,16 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// slashing message types -const ( - TypeMsgUnjail = "unjail" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // verify interface at compile time var ( _ sdk.Msg = &MsgUnjail{} _ sdk.Msg = &MsgUpdateParams{} + + _ legacytx.LegacyMsg = &MsgUnjail{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) // NewMsgUnjail creates a new MsgUnjail instance @@ -25,12 +24,6 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) *MsgUnjail { } } -// Route implements the sdk.Msg interface. -func (msg MsgUnjail) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgUnjail) Type() string { return TypeMsgUnjail } - // GetSigners returns the expected signers for MsgUnjail. func (msg MsgUnjail) GetSigners() []sdk.AccAddress { valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddr) @@ -57,13 +50,13 @@ func (msg MsgUpdateParams) GetSignBytes() []byte { } // GetSigners returns the expected signers for a MsgUpdateParams message. -func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { +func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(msg.Authority) return []sdk.AccAddress{addr} } // ValidateBasic does a sanity check on the provided data. -func (msg *MsgUpdateParams) ValidateBasic() error { +func (msg MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 5d38a6045f95..e9879a6d55a5 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -230,7 +230,7 @@ func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*typ defer func() { telemetry.IncrCounter(1, types.ModuleName, "delegate") telemetry.SetGaugeWithLabels( - []string{"tx", "msg", msg.Type()}, + []string{"tx", "msg", sdk.MsgTypeURL(msg)}, float32(msg.Amount.Amount.Int64()), []metrics.Label{telemetry.NewLabel("denom", msg.Amount.Denom)}, ) @@ -290,7 +290,7 @@ func (k msgServer) BeginRedelegate(goCtx context.Context, msg *types.MsgBeginRed defer func() { telemetry.IncrCounter(1, types.ModuleName, "redelegate") telemetry.SetGaugeWithLabels( - []string{"tx", "msg", msg.Type()}, + []string{"tx", "msg", sdk.MsgTypeURL(msg)}, float32(msg.Amount.Amount.Int64()), []metrics.Label{telemetry.NewLabel("denom", msg.Amount.Denom)}, ) @@ -347,7 +347,7 @@ func (k msgServer) Undelegate(goCtx context.Context, msg *types.MsgUndelegate) ( defer func() { telemetry.IncrCounter(1, types.ModuleName, "undelegate") telemetry.SetGaugeWithLabels( - []string{"tx", "msg", msg.Type()}, + []string{"tx", "msg", sdk.MsgTypeURL(msg)}, float32(msg.Amount.Amount.Int64()), []metrics.Label{telemetry.NewLabel("denom", msg.Amount.Denom)}, ) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index a675c4c9e634..18794553b037 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -118,25 +118,27 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k * return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgCreateValidator{}) + simAccount, _ := simtypes.RandomAcc(r, accs) address := sdk.ValAddress(simAccount.Address) // ensure the validator doesn't exist already _, found := k.GetValidator(ctx, address) if found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "validator already exists"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator already exists"), nil, nil } denom := k.GetParams(ctx).BondDenom balance := bk.GetBalance(ctx, simAccount.Address, denom).Amount if !balance.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "balance is negative"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "balance is negative"), nil, nil } amount, err := simtypes.RandPositiveInt(r, balance) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "unable to generate positive amount"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate positive amount"), nil, err } selfDelegation := sdk.NewCoin(denom, amount) @@ -150,7 +152,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k * if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate fees"), nil, err } } @@ -171,7 +173,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k * msg, err := types.NewMsgCreateValidator(address, simAccount.ConsKey.PubKey(), selfDelegation, description, commission, math.OneInt()) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to create CreateValidator message"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to create CreateValidator message"), nil, err } txCtx := simulation.OperationInput{ @@ -180,7 +182,6 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k * TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -196,13 +197,15 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k *ke return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgEditValidator{}) + if len(k.GetAllValidators(ctx)) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEditValidator, "number of validators equal zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "number of validators equal zero"), nil, nil } val, ok := testutil.RandSliceElem(r, k.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEditValidator, "unable to pick a validator"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to pick a validator"), nil, nil } address := val.GetOperator() @@ -210,12 +213,12 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k *ke if err := val.Commission.ValidateNewRate(newCommissionRate, ctx.BlockHeader().Time); err != nil { // skip as the commission is invalid - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEditValidator, "invalid commission rate"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "invalid commission rate"), nil, nil } simAccount, found := simtypes.FindAccount(accs, sdk.AccAddress(val.GetOperator())) if !found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEditValidator, "unable to find account"), nil, fmt.Errorf("validator %s not found", val.GetOperator()) + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to find account"), nil, fmt.Errorf("validator %s not found", val.GetOperator()) } account := ak.GetAccount(ctx, simAccount.Address) @@ -237,7 +240,6 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k *ke TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -255,30 +257,31 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper. return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgDelegate{}) denom := k.GetParams(ctx).BondDenom if len(k.GetAllValidators(ctx)) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "number of validators equal zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "number of validators equal zero"), nil, nil } simAccount, _ := simtypes.RandomAcc(r, accs) val, ok := testutil.RandSliceElem(r, k.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "unable to pick a validator"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to pick a validator"), nil, nil } if val.InvalidExRate() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "validator's invalid echange rate"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator's invalid echange rate"), nil, nil } amount := bk.GetBalance(ctx, simAccount.Address, denom).Amount if !amount.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "balance is negative"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "balance is negative"), nil, nil } amount, err := simtypes.RandPositiveInt(r, amount) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "unable to generate positive amount"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate positive amount"), nil, err } bondAmt := sdk.NewCoin(denom, amount) @@ -292,7 +295,7 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper. if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate fees"), nil, err } } @@ -304,7 +307,6 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper. TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -320,15 +322,17 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keepe return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgUndelegate{}) + val, ok := testutil.RandSliceElem(r, k.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "validator is not ok"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is not ok"), nil, nil } valAddr := val.GetOperator() delegations := k.GetValidatorDelegations(ctx, val.GetOperator()) if delegations == nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "keeper does have any delegation entries"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "keeper does have any delegation entries"), nil, nil } // get random delegator from validator @@ -336,21 +340,21 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keepe delAddr := delegation.GetDelegatorAddr() if k.HasMaxUnbondingDelegationEntries(ctx, delAddr, valAddr) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "keeper does have a max unbonding delegation entries"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "keeper does have a max unbonding delegation entries"), nil, nil } totalBond := val.TokensFromShares(delegation.GetShares()).TruncateInt() if !totalBond.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "total bond is negative"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "total bond is negative"), nil, nil } unbondAmt, err := simtypes.RandPositiveInt(r, totalBond) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "invalid unbond amount"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "invalid unbond amount"), nil, err } if unbondAmt.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "unbond amount is zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unbond amount is zero"), nil, nil } msg := types.NewMsgUndelegate( @@ -368,7 +372,7 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keepe } // if simaccount.PrivKey == nil, delegation address does not exist in accs. Return error if simAccount.PrivKey == nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "account private key is nil"), nil, fmt.Errorf("delegation addr: %s does not exist in simulation accounts", delAddr) + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "account private key is nil"), nil, fmt.Errorf("delegation addr: %s does not exist in simulation accounts", delAddr) } account := ak.GetAccount(ctx, delAddr) @@ -380,7 +384,6 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keepe TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -398,23 +401,25 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{}) + if len(k.GetAllValidators(ctx)) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "number of validators equal zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "number of validators equal zero"), nil, nil } simAccount, _ := simtypes.RandomAcc(r, accs) val, ok := testutil.RandSliceElem(r, k.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "validator is not ok"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is not ok"), nil, nil } if val.IsJailed() || val.InvalidExRate() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "validator is jailed"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is jailed"), nil, nil } valAddr := val.GetOperator() unbondingDelegation, found := k.GetUnbondingDelegation(ctx, simAccount.Address, valAddr) if !found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "account does have any unbonding delegation"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "account does have any unbonding delegation"), nil, nil } // This is a temporary fix to make staking simulation pass. We should fetch @@ -435,17 +440,17 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee } if unbondingDelegationEntry.CompletionTime.Before(ctx.BlockTime()) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "unbonding delegation is already processed"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unbonding delegation is already processed"), nil, nil } if !unbondingDelegationEntry.Balance.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "delegator receiving balance is negative"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "delegator receiving balance is negative"), nil, nil } cancelBondAmt := simtypes.RandomAmount(r, unbondingDelegationEntry.Balance) if cancelBondAmt.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "cancelBondAmt amount is zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "cancelBondAmt amount is zero"), nil, nil } msg := types.NewMsgCancelUnbondingDelegation( @@ -460,7 +465,6 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -478,16 +482,18 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k * return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgBeginRedelegate{}) + allVals := k.GetAllValidators(ctx) srcVal, ok := testutil.RandSliceElem(r, allVals) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "unable to pick validator"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to pick validator"), nil, nil } srcAddr := srcVal.GetOperator() delegations := k.GetValidatorDelegations(ctx, srcAddr) if delegations == nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "keeper does have any delegation entries"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "keeper does have any delegation entries"), nil, nil } // get random delegator from src validator @@ -495,42 +501,42 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k * delAddr := delegation.GetDelegatorAddr() if k.HasReceivingRedelegation(ctx, delAddr, srcAddr) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "receveing redelegation is not allowed"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "receveing redelegation is not allowed"), nil, nil // skip } // get random destination validator destVal, ok := testutil.RandSliceElem(r, allVals) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "unable to pick validator"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to pick validator"), nil, nil } destAddr := destVal.GetOperator() if srcAddr.Equals(destAddr) || destVal.InvalidExRate() || k.HasMaxRedelegationEntries(ctx, delAddr, srcAddr, destAddr) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "checks failed"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "checks failed"), nil, nil } totalBond := srcVal.TokensFromShares(delegation.GetShares()).TruncateInt() if !totalBond.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "total bond is negative"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "total bond is negative"), nil, nil } redAmt, err := simtypes.RandPositiveInt(r, totalBond) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "unable to generate positive amount"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate positive amount"), nil, err } if redAmt.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "amount is zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "amount is zero"), nil, nil } // check if the shares truncate to zero shares, err := srcVal.SharesFromTokens(redAmt) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "invalid shares"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "invalid shares"), nil, err } if srcVal.TokensFromShares(shares).TruncateInt().IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "shares truncate to zero"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "shares truncate to zero"), nil, nil // skip } // need to retrieve the simulation account associated with delegation to retrieve PrivKey @@ -545,7 +551,7 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k * // if simaccount.PrivKey == nil, delegation address does not exist in accs. Return error if simAccount.PrivKey == nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "account private key is nil"), nil, fmt.Errorf("delegation addr: %s does not exist in simulation accounts", delAddr) + return simtypes.NoOpMsg(types.ModuleName, msgType, "account private key is nil"), nil, fmt.Errorf("delegation addr: %s does not exist in simulation accounts", delAddr) } account := ak.GetAccount(ctx, delAddr) @@ -562,7 +568,6 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k * TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index de7bbb4f05ee..c46416f8584e 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -131,12 +131,12 @@ func (s *SimTestSuite) TestWeightedOperations() { opMsgRoute string opMsgName string }{ - {simulation.DefaultWeightMsgCreateValidator, types.ModuleName, types.TypeMsgCreateValidator}, - {simulation.DefaultWeightMsgEditValidator, types.ModuleName, types.TypeMsgEditValidator}, - {simulation.DefaultWeightMsgDelegate, types.ModuleName, types.TypeMsgDelegate}, - {simulation.DefaultWeightMsgUndelegate, types.ModuleName, types.TypeMsgUndelegate}, - {simulation.DefaultWeightMsgBeginRedelegate, types.ModuleName, types.TypeMsgBeginRedelegate}, - {simulation.DefaultWeightMsgCancelUnbondingDelegation, types.ModuleName, types.TypeMsgCancelUnbondingDelegation}, + {simulation.DefaultWeightMsgCreateValidator, types.ModuleName, sdk.MsgTypeURL(&types.MsgCreateValidator{})}, + {simulation.DefaultWeightMsgEditValidator, types.ModuleName, sdk.MsgTypeURL(&types.MsgEditValidator{})}, + {simulation.DefaultWeightMsgDelegate, types.ModuleName, sdk.MsgTypeURL(&types.MsgDelegate{})}, + {simulation.DefaultWeightMsgUndelegate, types.ModuleName, sdk.MsgTypeURL(&types.MsgUndelegate{})}, + {simulation.DefaultWeightMsgBeginRedelegate, types.ModuleName, sdk.MsgTypeURL(&types.MsgBeginRedelegate{})}, + {simulation.DefaultWeightMsgCancelUnbondingDelegation, types.ModuleName, sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{})}, } for i, w := range weightesOps { @@ -168,8 +168,15 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) +<<<<<<< HEAD require.Equal(types.TypeMsgCreateValidator, msg.Type()) require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.DelegatorAddress) +======= + require.Equal(sdk.MsgTypeURL(&types.MsgCreateValidator{}), sdk.MsgTypeURL(&msg)) + valaddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + require.NoError(err) + require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", sdk.AccAddress(valaddr).String()) +>>>>>>> 8dbdfea9e (refactor: remove `.Type()` and `.Route()` from msgs (#14751)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -212,7 +219,7 @@ func (s *SimTestSuite) TestSimulateMsgCancelUnbondingDelegation() { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgCancelUnbondingDelegation, msg.Type()) + require.Equal(sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{}), sdk.MsgTypeURL(&msg)) require.Equal(delegator.Address.String(), msg.DelegatorAddress) require.Equal(validator0.GetOperator().String(), msg.ValidatorAddress) require.Len(futureOperations, 0) @@ -240,7 +247,7 @@ func (s *SimTestSuite) TestSimulateMsgEditValidator() { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgEditValidator, msg.Type()) + require.Equal(sdk.MsgTypeURL(&types.MsgEditValidator{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -263,7 +270,7 @@ func (s *SimTestSuite) TestSimulateMsgDelegate() { require.True(operationMsg.OK) require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgDelegate, msg.Type()) + require.Equal(sdk.MsgTypeURL(&types.MsgDelegate{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -303,7 +310,7 @@ func (s *SimTestSuite) TestSimulateMsgUndelegate() { require.Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) require.Equal("1646627814093010272", msg.Amount.Amount.String()) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgUndelegate, msg.Type()) + require.Equal(sdk.MsgTypeURL(&types.MsgUndelegate{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -346,7 +353,7 @@ func (s *SimTestSuite) TestSimulateMsgBeginRedelegate() { require.True(operationMsg.OK) require.Equal("cosmos1ua0fwyws7vzjrry3pqkklvf8mny93l9s9zg0h4", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgBeginRedelegate, msg.Type()) + require.Equal(sdk.MsgTypeURL(&types.MsgBeginRedelegate{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1ghekyjucln7y67ntx7cf27m9dpuxxemnsvnaes", msg.ValidatorDstAddress) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorSrcAddress) require.Len(futureOperations, 0) diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index a8539bd21884..5e4f539ffdf6 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -6,29 +6,26 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// staking message types -const ( - TypeMsgUndelegate = "begin_unbonding" - TypeMsgCancelUnbondingDelegation = "cancel_unbond" - TypeMsgEditValidator = "edit_validator" - TypeMsgCreateValidator = "create_validator" - TypeMsgDelegate = "delegate" - TypeMsgBeginRedelegate = "begin_redelegate" - TypeMsgUpdateParams = "update_params" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( _ sdk.Msg = &MsgCreateValidator{} _ codectypes.UnpackInterfacesMessage = (*MsgCreateValidator)(nil) - _ sdk.Msg = &MsgCreateValidator{} _ sdk.Msg = &MsgEditValidator{} _ sdk.Msg = &MsgDelegate{} _ sdk.Msg = &MsgUndelegate{} _ sdk.Msg = &MsgBeginRedelegate{} _ sdk.Msg = &MsgCancelUnbondingDelegation{} _ sdk.Msg = &MsgUpdateParams{} + + _ legacytx.LegacyMsg = &MsgCreateValidator{} + _ legacytx.LegacyMsg = &MsgEditValidator{} + _ legacytx.LegacyMsg = &MsgDelegate{} + _ legacytx.LegacyMsg = &MsgUndelegate{} + _ legacytx.LegacyMsg = &MsgBeginRedelegate{} + _ legacytx.LegacyMsg = &MsgCancelUnbondingDelegation{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) // NewMsgCreateValidator creates a new MsgCreateValidator instance. @@ -55,12 +52,6 @@ func NewMsgCreateValidator( }, nil } -// Route implements the sdk.Msg interface. -func (msg MsgCreateValidator) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgCreateValidator) Type() string { return TypeMsgCreateValidator } - // GetSigners implements the sdk.Msg interface. It returns the address(es) that // must sign over msg.GetSignBytes(). // If the validator address is not same as delegator's, then the validator must @@ -152,12 +143,6 @@ func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRat } } -// Route implements the sdk.Msg interface. -func (msg MsgEditValidator) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgEditValidator) Type() string { return TypeMsgEditValidator } - // GetSigners implements the sdk.Msg interface. func (msg MsgEditValidator) GetSigners() []sdk.AccAddress { valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) @@ -207,12 +192,6 @@ func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.C } } -// Route implements the sdk.Msg interface. -func (msg MsgDelegate) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgDelegate) Type() string { return TypeMsgDelegate } - // GetSigners implements the sdk.Msg interface. func (msg MsgDelegate) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -258,12 +237,6 @@ func NewMsgBeginRedelegate( } } -// Route implements the sdk.Msg interface. -func (msg MsgBeginRedelegate) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface -func (msg MsgBeginRedelegate) Type() string { return TypeMsgBeginRedelegate } - // GetSigners implements the sdk.Msg interface func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -309,12 +282,6 @@ func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk } } -// Route implements the sdk.Msg interface. -func (msg MsgUndelegate) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgUndelegate) Type() string { return TypeMsgUndelegate } - // GetSigners implements the sdk.Msg interface. func (msg MsgUndelegate) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -358,12 +325,6 @@ func NewMsgCancelUnbondingDelegation(delAddr sdk.AccAddress, valAddr sdk.ValAddr } } -// Route implements the sdk.Msg interface. -func (msg MsgCancelUnbondingDelegation) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgCancelUnbondingDelegation) Type() string { return TypeMsgCancelUnbondingDelegation } - // GetSigners implements the sdk.Msg interface. func (msg MsgCancelUnbondingDelegation) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -403,13 +364,13 @@ func (msg MsgCancelUnbondingDelegation) ValidateBasic() error { // GetSignBytes returns the raw bytes for a MsgUpdateParams message that // the expected signer needs to sign. -func (m *MsgUpdateParams) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(m) +func (m MsgUpdateParams) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(&m) return sdk.MustSortJSON(bz) } // ValidateBasic executes sanity validation on the provided data -func (m *MsgUpdateParams) ValidateBasic() error { +func (m MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } @@ -417,7 +378,7 @@ func (m *MsgUpdateParams) ValidateBasic() error { } // GetSigners returns the expected signers for a MsgUpdateParams message -func (m *MsgUpdateParams) GetSigners() []sdk.AccAddress { +func (m MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(m.Authority) return []sdk.AccAddress{addr} } diff --git a/x/upgrade/types/msgs.go b/x/upgrade/types/msgs.go index 86dc6a1338b2..b14255433878 100644 --- a/x/upgrade/types/msgs.go +++ b/x/upgrade/types/msgs.go @@ -11,12 +11,6 @@ var ( _, _ legacytx.LegacyMsg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} ) -// Route implements the LegacyMsg interface. -func (m MsgSoftwareUpgrade) Route() string { return sdk.MsgTypeURL(&m) } - -// Type implements the LegacyMsg interface. -func (m MsgSoftwareUpgrade) Type() string { return sdk.MsgTypeURL(&m) } - // GetSignBytes implements the LegacyMsg interface. func (m MsgSoftwareUpgrade) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) @@ -41,12 +35,6 @@ func (m *MsgSoftwareUpgrade) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{addr} } -// Route implements the LegacyMsg interface. -func (m MsgCancelUpgrade) Route() string { return sdk.MsgTypeURL(&m) } - -// Type implements the LegacyMsg interface. -func (m MsgCancelUpgrade) Type() string { return sdk.MsgTypeURL(&m) } - // GetSignBytes implements the LegacyMsg interface. func (m MsgCancelUpgrade) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) diff --git a/x/upgrade/types/msgs_test.go b/x/upgrade/types/msgs_test.go index feb648be97bd..70981f9e389b 100644 --- a/x/upgrade/types/msgs_test.go +++ b/x/upgrade/types/msgs_test.go @@ -63,7 +63,6 @@ func TestMsgSoftwareUpgrade(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&types.MsgSoftwareUpgrade{})) } }) } @@ -102,7 +101,6 @@ func TestMsgCancelUpgrade(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&types.MsgCancelUpgrade{})) } }) }