From 8dbdfea9ef705aeb96d20fa3959548fdc22eca6c Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 18:03:06 +0100 Subject: [PATCH] refactor: remove `.Type()` and `.Route()` from msgs (#14751) --- CHANGELOG.md | 2 + baseapp/baseapp.go | 7 +- .../02-messages-and-queries.md | 2 - docs/docs/core/08-events.md | 1 - testutil/testdata/tx.go | 2 - types/simulation/types.go | 22 ++- types/tx_msg.go | 13 ++ types/tx_msg_test.go | 2 - x/auth/migrations/legacytx/stdsign.go | 12 +- x/auth/types/msgs.go | 10 +- x/auth/vesting/types/msgs.go | 40 +--- x/authz/msgs.go | 30 --- x/authz/simulation/operations_test.go | 16 +- x/bank/simulation/operations.go | 30 +-- x/bank/simulation/operations_test.go | 16 +- x/bank/types/msgs.go | 25 +-- x/bank/types/msgs_test.go | 25 --- x/consensus/types/msgs.go | 15 +- x/crisis/types/msgs.go | 23 +-- x/distribution/simulation/operations.go | 22 +-- x/distribution/simulation/operations_test.go | 20 +- x/distribution/types/msg.go | 52 +---- x/evidence/types/genesis_test.go | 8 +- x/evidence/types/msgs.go | 13 +- x/feegrant/msgs.go | 25 +-- x/feegrant/simulation/operations.go | 2 - x/feegrant/simulation/operations_test.go | 8 +- x/gov/client/utils/query_test.go | 3 +- x/gov/simulation/operations.go | 16 +- x/gov/simulation/operations_test.go | 15 +- x/gov/types/v1/msgs.go | 44 +---- x/gov/types/v1beta1/msgs.go | 31 +-- x/group/msgs.go | 185 ++++++------------ x/group/msgs_test.go | 28 +-- x/group/simulation/operations.go | 102 +++++----- x/group/simulation/operations_test.go | 30 +-- x/mint/types/msgs.go | 10 +- x/simulation/event_stats.go | 12 +- x/simulation/util.go | 9 +- x/slashing/simulation/operations.go | 20 +- x/slashing/simulation/operations_test.go | 5 +- x/slashing/types/msg.go | 19 +- x/staking/keeper/msg_server.go | 6 +- x/staking/simulation/operations.go | 97 ++++----- x/staking/simulation/operations_test.go | 24 +-- x/staking/types/msg.go | 65 ++---- x/upgrade/types/msgs.go | 12 -- x/upgrade/types/msgs_test.go | 2 - 48 files changed, 409 insertions(+), 769 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ed0ac82b78..c9f4c8b5699a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### 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. * [#14691](https://github.com/cosmos/cosmos-sdk/pull/14691) Change behavior of `sdk.StringifyEvents` to not flatten events attributes by events type. * This change only affects ABCI message logs, and not the actual events. * [#14692](https://github.com/cosmos/cosmos-sdk/pull/14692) Improve RPC queries error message when app is at height 0. @@ -165,6 +166,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (x/simulation) [#14751](https://github.com/cosmos/cosmos-sdk/pull/14751) Remove the `MsgType` field from `simulation.OperationInput` struct. * (crypto/keyring) [#13734](https://github.com/cosmos/cosmos-sdk/pull/13834) The keyring's `Sign` method now takes a new `signMode` argument. It is only used if the signing key is a Ledger hardware device. You can set it to 0 in all other cases. * (x/evidence) [14724](https://github.com/cosmos/cosmos-sdk/pull/14724) Extract Evidence in its own go.mod and rename the package to `cosmossdk.io/x/evidence`. * (x/nft) [#14725](https://github.com/cosmos/cosmos-sdk/pull/14725) Extract NFT in its own go.mod and rename the package to `cosmossdk.io/x/nft`. diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 8a987156cb79..be1837c7d78d 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -835,11 +835,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 15535e5776e2..ba860d3d3203 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 3d659e77d5c8..9b4e081253ff 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -78,8 +78,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 702e6b2e49ca..eeb9c15553f0 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -66,10 +66,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, @@ -78,18 +78,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 d3c2afe28d8d..f96163b7f334 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 481fec1a828b..0a2b7ffb17a6 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 7818ebf1a2b6..25aa67759269 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -62,27 +62,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 @@ -96,27 +97,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 @@ -179,6 +180,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) @@ -200,7 +203,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 @@ -216,7 +219,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 { @@ -254,7 +257,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 @@ -267,6 +270,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 @@ -281,7 +285,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 { @@ -313,7 +317,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 97128ebfa8a2..0988c8d1c42b 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 5f0ad3197f29..8bb09b461adb 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 3d94883a7730..10efaf60d83f 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 d4c8caa61ebe..7f9e61d1d03d 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -91,7 +91,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) @@ -108,7 +108,6 @@ func SimulateMsgSetWithdrawAddress(txConfig client.TxConfig, ak types.AccountKee TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -129,14 +128,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) @@ -150,7 +149,6 @@ func SimulateMsgWithdrawDelegatorReward(txConfig client.TxConfig, ak types.Accou TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -168,19 +166,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) @@ -194,7 +194,6 @@ func SimulateMsgWithdrawValidatorCommission(txConfig client.TxConfig, ak types.A TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -220,7 +219,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 ( @@ -232,7 +231,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 } } @@ -244,7 +243,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 66c43c5cb84e..717b105cbd9f 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -43,10 +43,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 { @@ -84,8 +84,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) } @@ -125,8 +124,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) } @@ -185,8 +183,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) } } @@ -213,8 +210,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 e13d1bdc506e..1bd3edcdcc63 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -5,17 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// distribution message types -const ( - TypeMsgSetWithdrawAddress = "set_withdraw_address" - TypeMsgWithdrawDelegatorReward = "withdraw_delegator_reward" - TypeMsgWithdrawValidatorCommission = "withdraw_validator_commission" - TypeMsgFundCommunityPool = "fund_community_pool" - TypeMsgUpdateParams = "update_params" - TypeMsgCommunityPoolSpend = "community_pool_spend" - TypeMsgDepositValidatorRewardsPool = "deposit_validator_rewards_pool" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // Verify interface at compile time @@ -26,6 +16,13 @@ var ( _ sdk.Msg = (*MsgUpdateParams)(nil) _ sdk.Msg = (*MsgCommunityPoolSpend)(nil) _ 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) ) func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithdrawAddress { @@ -35,9 +32,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) @@ -69,9 +63,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) @@ -101,9 +92,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) @@ -133,12 +121,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 { @@ -164,12 +146,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 { @@ -198,12 +174,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 { @@ -237,12 +207,6 @@ func NewMsgDepositValidatorRewardsPool(depositor sdk.AccAddress, valAddr sdk.Val } } -// Route returns the MsgDepositValidatorRewardsPool message route. -func (msg MsgDepositValidatorRewardsPool) Route() string { return ModuleName } - -// Type returns the MsgDepositValidatorRewardsPool message type. -func (msg MsgDepositValidatorRewardsPool) Type() string { return TypeMsgDepositValidatorRewardsPool } - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes, which is the authority. func (msg MsgDepositValidatorRewardsPool) GetSigners() []sdk.AccAddress { diff --git a/x/evidence/types/genesis_test.go b/x/evidence/types/genesis_test.go index e1738ef47ec0..425aceb8b909 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 c12e140ee074..25a99e6e0575 100644 --- a/x/evidence/types/msgs.go +++ b/x/evidence/types/msgs.go @@ -9,15 +9,12 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// Message types for the evidence module -const ( - TypeMsgSubmitEvidence = "submit_evidence" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( _ sdk.Msg = &MsgSubmitEvidence{} + _ legacytx.LegacyMsg = &MsgSubmitEvidence{} _ types.UnpackInterfacesMessage = MsgSubmitEvidence{} _ exported.MsgSubmitEvidenceI = &MsgSubmitEvidence{} ) @@ -37,12 +34,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 2ca0dd3d0c10..8ffb29981ddc 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 02f8ea611348..2479e832c59f 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -13,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/gov/client/utils" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" @@ -46,7 +45,7 @@ func (mock TxSearchMock) TxSearch(ctx context.Context, query string, prove bool, return nil, err } for _, msg := range sdkTx.GetMsgs() { - if msg.(legacytx.LegacyMsg).Type() == msgType { + if sdk.MsgTypeURL(msg) == msgType { matchingTxs = append(matchingTxs, tx) break } diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 47f81408c7aa..7fb0059bb168 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -169,7 +169,7 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k msg, err := v1.NewMsgSubmitProposal([]sdk.Msg{contentMsg}, deposit, simAccount.Address.String(), "", "Title of proposal", "Short description of proposal") 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) @@ -180,7 +180,7 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *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 } } @@ -197,12 +197,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) @@ -210,7 +210,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 @@ -268,7 +268,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 } } @@ -278,7 +278,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, @@ -328,7 +327,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, @@ -380,7 +378,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, @@ -420,7 +417,6 @@ func SimulateMsgCancelProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 4506314c9aa6..32cdc02ca246 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -142,8 +142,7 @@ func TestSimulateMsgSubmitProposal(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)) } // TestSimulateMsgCancelProposal tests the normal scenario of a valid message of type TypeMsgCancelProposal. @@ -187,8 +186,7 @@ func TestSimulateMsgCancelProposal(t *testing.T) { require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, proposer.String(), msg.Proposer) - require.Equal(t, "gov", msg.Route()) - require.Equal(t, simulation.TypeMsgCancelProposal, msg.Type()) + require.Equal(t, simulation.TypeMsgCancelProposal, sdk.MsgTypeURL(&msg)) } // TestSimulateMsgDeposit tests the normal scenario of a valid message of type TypeMsgDeposit. @@ -234,8 +232,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. @@ -279,8 +276,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. @@ -323,8 +319,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 93d391644de2..a40df3a7b8fd 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -9,6 +9,7 @@ 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" @@ -16,6 +17,7 @@ import ( var ( _, _, _, _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} + _, _, _, _, _, _, _ legacytx.LegacyMsg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} _, _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{}, &MsgExecLegacyContent{} ) @@ -46,12 +48,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 +114,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 +149,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 +180,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 +239,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 +267,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 { @@ -320,12 +298,6 @@ func NewMsgCancelProposal(proposalID uint64, proposer string) *MsgCancelProposal } } -// Route implements Msg -func (msg MsgCancelProposal) Route() string { return types.RouterKey } - -// Type implements Msg -func (msg MsgCancelProposal) Type() string { return sdk.MsgTypeURL(&msg) } - // ValidateBasic implements Msg func (msg MsgCancelProposal) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Proposer); err != nil { diff --git a/x/gov/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index 248f46a30e2d..3bff5eff98db 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -9,6 +9,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" ) @@ -22,8 +23,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. @@ -83,12 +86,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 { @@ -140,12 +137,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 { @@ -180,12 +171,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 { @@ -217,12 +202,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 ced5c0e18460..71d1e7482aee 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" errors "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 1966833a8aab..9b19fd692f46 100644 --- a/x/group/simulation/operations.go +++ b/x/group/simulation/operations.go @@ -279,7 +279,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 @@ -318,7 +318,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) @@ -339,7 +339,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 @@ -400,7 +400,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 @@ -450,7 +450,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), @@ -462,7 +462,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, @@ -476,10 +476,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 } } @@ -512,7 +512,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(), @@ -522,7 +522,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, @@ -536,10 +536,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 } } @@ -563,7 +563,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), @@ -573,7 +573,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, @@ -587,10 +587,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 } } @@ -643,7 +643,7 @@ func SimulateMsgUpdateGroupMembers(cdc *codec.ProtoCodec, ak group.AccountKeeper } } - msg := group.MsgUpdateGroupMembers{ + msg := &group.MsgUpdateGroupMembers{ GroupId: groupID, Admin: acc.Address.String(), MemberUpdates: members, @@ -653,7 +653,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, @@ -667,10 +667,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 } } @@ -703,7 +703,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(), @@ -713,7 +713,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, @@ -727,10 +727,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 } } @@ -789,7 +789,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 } @@ -817,7 +817,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), @@ -827,7 +827,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, @@ -841,10 +841,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 } } @@ -919,7 +919,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(), } @@ -928,7 +928,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, @@ -944,12 +944,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 } } @@ -1023,7 +1023,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, @@ -1033,7 +1033,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, @@ -1049,12 +1049,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 } } @@ -1067,26 +1067,26 @@ 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 } proposalsResult, err := k.ProposalsByGroupPolicy(sdkCtx, &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 @@ -1100,10 +1100,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(), } @@ -1111,7 +1111,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, @@ -1126,12 +1126,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 } } @@ -1187,7 +1187,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 25ffcdcb303b..1a7718543b36 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 939f28766fe5..3abf711d82cf 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 3651ed3e67cd..95574cbbca2b 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 35464a8c1815..21cd788d45b4 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -225,7 +225,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)}, ) @@ -285,7 +285,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)}, ) @@ -344,7 +344,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 bc21d49200ba..d3f11642eae1 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,7 +168,7 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgCreateValidator, msg.Type()) + 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()) @@ -214,7 +214,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) @@ -242,7 +242,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) } @@ -265,7 +265,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) } @@ -305,7 +305,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) } @@ -348,7 +348,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 588e54df52e5..4542f3b821d0 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. @@ -54,12 +51,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 @@ -138,12 +129,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) @@ -193,12 +178,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) @@ -244,12 +223,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) @@ -295,12 +268,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) @@ -344,12 +311,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) @@ -389,13 +350,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") } @@ -403,7 +364,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{})) } }) }