From 7b9f45814ae5b1932737fbf0682245db22ccc939 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 14:07:44 +0100 Subject: [PATCH 01/12] refactor: msgs --- testutil/testdata/tx.go | 7 +- types/simulation/types.go | 9 +- types/tx_msg.go | 10 ++ types/tx_msg_test.go | 2 - x/auth/migrations/legacytx/stdsign.go | 4 +- x/auth/vesting/types/msgs.go | 41 ++---- x/authz/msgs.go | 43 +------ x/authz/msgs_test.go | 2 +- x/bank/types/msgs.go | 24 +--- x/consensus/types/msgs.go | 14 +- x/crisis/types/msgs.go | 22 +--- x/distribution/types/msg.go | 51 +------- x/evidence/types/genesis_test.go | 8 -- x/evidence/types/msgs.go | 12 +- x/feegrant/msgs.go | 30 +---- x/feegrant/msgs_test.go | 2 +- x/gov/types/v1/msgs.go | 43 +------ x/gov/types/v1beta1/msgs.go | 38 +----- x/group/msgs.go | 178 ++++++++------------------ x/slashing/types/msg.go | 13 +- x/staking/types/msg.go | 56 ++------ x/upgrade/types/msgs.go | 17 +-- 22 files changed, 141 insertions(+), 485 deletions(-) diff --git a/testutil/testdata/tx.go b/testutil/testdata/tx.go index 3d659e77d5c8..a1b2550b7ca5 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -76,10 +76,11 @@ func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg { } } -var _ sdk.Msg = (*TestMsg)(nil) +var ( + _ sdk.Msg = (*TestMsg)(nil) + _ sdk.HasAminoSigningCapability = (*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..af0c72768b72 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) type WeightedProposalContent interface { @@ -78,13 +77,11 @@ 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()) + if legacyMsg, okType := msg.(sdk.HasAminoSigningCapability); okType { + return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, legacyMsg.GetSignBytes()) } - bz := cdc.MustMarshalJSON(msg) - - return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, bz) + return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, cdc.MustMarshalJSON(msg)) } // NoOpMsg - create a no-operation message diff --git a/types/tx_msg.go b/types/tx_msg.go index 41c647e57de5..dc5991ac77a9 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -25,6 +25,16 @@ type ( GetSigners() []AccAddress } + // Extension interface for Msg that require Amino Signing + // Replaces legacytx.LegacyMsg. + // Deprecated: use Msg instead. + HasAminoSigningCapability interface { + Msg + + // Get the canonical byte representation of the Msg. + GetSignBytes() []byte + } + // Fee defines an interface for an application application-defined concrete // transaction type to be able to set and return the transaction fee. Fee interface { 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..f54bc5186b4c 100644 --- a/x/auth/migrations/legacytx/stdsign.go +++ b/x/auth/migrations/legacytx/stdsign.go @@ -55,9 +55,9 @@ type StdSignDoc struct { func StdSignBytes(chainID string, accnum, sequence, timeout uint64, fee StdFee, msgs []sdk.Msg, memo string, tip *tx.Tip) []byte { msgsBytes := make([]json.RawMessage, 0, len(msgs)) for _, msg := range msgs { - legacyMsg, ok := msg.(LegacyMsg) + legacyMsg, ok := msg.(sdk.HasAminoSigningCapability) if !ok { - panic(fmt.Errorf("expected %T when using amino JSON", (*LegacyMsg)(nil))) + panic(fmt.Errorf("expected %T when using amino JSON", (*sdk.HasAminoSigningCapability)(nil))) } msgsBytes = append(msgsBytes, json.RawMessage(legacyMsg.GetSignBytes())) diff --git a/x/auth/vesting/types/msgs.go b/x/auth/vesting/types/msgs.go index fbce860cede4..74bf0384974b 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -7,20 +7,15 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// TypeMsgCreateVestingAccount defines the type value for a MsgCreateVestingAccount. -const TypeMsgCreateVestingAccount = "msg_create_vesting_account" - -// 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{} +var ( + _ sdk.Msg = &MsgCreateVestingAccount{} + _ sdk.Msg = &MsgCreatePermanentLockedAccount{} + _ sdk.Msg = &MsgCreatePeriodicVestingAccount{} + + _ sdk.HasAminoSigningCapability = &MsgCreateVestingAccount{} + _ sdk.HasAminoSigningCapability = &MsgCreatePermanentLockedAccount{} + _ sdk.HasAminoSigningCapability = &MsgCreatePeriodicVestingAccount{} +) // NewMsgCreateVestingAccount returns a reference to a new MsgCreateVestingAccount. // @@ -35,12 +30,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 +77,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 +121,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..33e0bb63a585 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -10,7 +10,6 @@ import ( cdctypes "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" ) var ( @@ -19,9 +18,9 @@ var ( _ sdk.Msg = &MsgExec{} // For amino support. - _ legacytx.LegacyMsg = &MsgGrant{} - _ legacytx.LegacyMsg = &MsgRevoke{} - _ legacytx.LegacyMsg = &MsgExec{} + _ sdk.HasAminoSigningCapability = &MsgGrant{} + _ sdk.HasAminoSigningCapability = &MsgRevoke{} + _ sdk.HasAminoSigningCapability = &MsgExec{} _ cdctypes.UnpackInterfacesMessage = &MsgGrant{} _ cdctypes.UnpackInterfacesMessage = &MsgExec{} @@ -66,17 +65,7 @@ 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. +// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. func (msg MsgGrant) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } @@ -157,17 +146,7 @@ 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. +// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. func (msg MsgRevoke) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } @@ -235,17 +214,7 @@ 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. +// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. func (msg MsgExec) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } diff --git a/x/authz/msgs_test.go b/x/authz/msgs_test.go index 5d7eb3c39fb9..7a7070916d3f 100644 --- a/x/authz/msgs_test.go +++ b/x/authz/msgs_test.go @@ -165,7 +165,7 @@ func TestMsgGrantGetAuthorization(t *testing.T) { func TestAminoJSON(t *testing.T) { tx := legacytx.StdTx{} - var msg legacytx.LegacyMsg + var msg sdk.HasAminoSigningCapability blockTime := time.Date(1, 1, 1, 1, 1, 1, 1, time.UTC) expiresAt := blockTime.Add(time.Hour) msgSend := banktypes.MsgSend{FromAddress: "cosmos1ghi", ToAddress: "cosmos1jkl"} diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index 5f0ad3197f29..09c63d42ef59 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -5,18 +5,14 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// bank message types -const ( - TypeMsgSend = "send" - TypeMsgMultiSend = "multisend" - TypeMsgSetSendEnabled = "set_send_enabled" - TypeMsgUpdateParams = "update_params" -) - var ( _ sdk.Msg = &MsgSend{} _ sdk.Msg = &MsgMultiSend{} _ sdk.Msg = &MsgUpdateParams{} + + _ sdk.HasAminoSigningCapability = &MsgSend{} + _ sdk.HasAminoSigningCapability = &MsgMultiSend{} + _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} ) // NewMsgSend - construct a msg to send coins from one account to another. @@ -26,12 +22,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 +59,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/consensus/types/msgs.go b/x/consensus/types/msgs.go index 3d94883a7730..7671427c8b78 100644 --- a/x/consensus/types/msgs.go +++ b/x/consensus/types/msgs.go @@ -5,14 +5,16 @@ import ( tmtypes "github.com/tendermint/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) const ( TypeMsgUpdateParams = "update_params" ) -var _ legacytx.LegacyMsg = &MsgUpdateParams{} +var ( + _ sdk.Msg = &MsgUpdateParams{} + _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} +) // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes. @@ -27,14 +29,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..43b379409132 100644 --- a/x/crisis/types/msgs.go +++ b/x/crisis/types/msgs.go @@ -5,13 +5,11 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -const ( - TypeMsgVerifyInvariant = "verify_invariant" - TypeMsgUpdateParams = "update_params" -) - // ensure Msg interface compliance at compile time -var _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} +var ( + _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} + _, _ sdk.HasAminoSigningCapability = &MsgVerifyInvariant{}, &MsgUpdateParams{} +) // NewMsgVerifyInvariant creates a new MsgVerifyInvariant object // @@ -24,12 +22,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 +47,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/types/msg.go b/x/distribution/types/msg.go index e13d1bdc506e..c5da45de29a6 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -7,17 +7,6 @@ import ( 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" -) - // Verify interface at compile time var ( _ sdk.Msg = (*MsgSetWithdrawAddress)(nil) @@ -26,6 +15,13 @@ var ( _ sdk.Msg = (*MsgUpdateParams)(nil) _ sdk.Msg = (*MsgCommunityPoolSpend)(nil) _ sdk.Msg = (*MsgDepositValidatorRewardsPool)(nil) + + _ sdk.HasAminoSigningCapability = (*MsgSetWithdrawAddress)(nil) + _ sdk.HasAminoSigningCapability = (*MsgWithdrawDelegatorReward)(nil) + _ sdk.HasAminoSigningCapability = (*MsgWithdrawValidatorCommission)(nil) + _ sdk.HasAminoSigningCapability = (*MsgUpdateParams)(nil) + _ sdk.HasAminoSigningCapability = (*MsgCommunityPoolSpend)(nil) + _ sdk.HasAminoSigningCapability = (*MsgDepositValidatorRewardsPool)(nil) ) func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithdrawAddress { @@ -35,9 +31,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 +62,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 +91,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 +120,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 +145,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 +173,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 +206,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..79c57ef4c2d6 100644 --- a/x/evidence/types/genesis_test.go +++ b/x/evidence/types/genesis_test.go @@ -160,14 +160,6 @@ type TestEvidence struct{} var _ exported.Evidence = &TestEvidence{} -func (*TestEvidence) Route() string { - return "test-route" -} - -func (*TestEvidence) Type() string { - return "test-type" -} - func (*TestEvidence) String() string { return "test-string" } diff --git a/x/evidence/types/msgs.go b/x/evidence/types/msgs.go index c12e140ee074..4b422f0a2766 100644 --- a/x/evidence/types/msgs.go +++ b/x/evidence/types/msgs.go @@ -11,13 +11,9 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// Message types for the evidence module -const ( - TypeMsgSubmitEvidence = "submit_evidence" -) - var ( _ sdk.Msg = &MsgSubmitEvidence{} + _ sdk.HasAminoSigningCapability = &MsgSubmitEvidence{} _ types.UnpackInterfacesMessage = MsgSubmitEvidence{} _ exported.MsgSubmitEvidenceI = &MsgSubmitEvidence{} ) @@ -37,12 +33,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..24929ddcdda1 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -6,12 +6,12 @@ import ( "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" ) var ( - _, _ sdk.Msg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} - _, _ legacytx.LegacyMsg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} // For amino support. + _, _ sdk.Msg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} + // For amino support. + _, _ sdk.HasAminoSigningCapability = &MsgGrantAllowance{}, &MsgRevokeAllowance{} _ types.UnpackInterfacesMessage = &MsgGrantAllowance{} ) @@ -61,17 +61,7 @@ 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. +// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. func (msg MsgGrantAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } @@ -122,17 +112,7 @@ 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. +// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. func (msg MsgRevokeAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } diff --git a/x/feegrant/msgs_test.go b/x/feegrant/msgs_test.go index f33849557c97..383c08b771c6 100644 --- a/x/feegrant/msgs_test.go +++ b/x/feegrant/msgs_test.go @@ -136,7 +136,7 @@ func TestMsgRevokeAllowance(t *testing.T) { func TestAminoJSON(t *testing.T) { tx := legacytx.StdTx{} - var msg legacytx.LegacyMsg + var msg sdk.HasAminoSigningCapability allowanceAny, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{SpendLimit: sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(100)))}) require.NoError(t, err) diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index 93d391644de2..8b07191e7031 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -16,6 +16,7 @@ import ( var ( _, _, _, _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} + _, _, _, _, _, _, _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} _, _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{}, &MsgExecLegacyContent{} ) @@ -46,12 +47,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 +113,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 +148,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 +179,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 +238,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 +266,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 +297,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..73a440795cab 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -13,17 +13,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" ) -// Governance message types and routes -const ( - TypeMsgDeposit = "deposit" - TypeMsgVote = "vote" - TypeMsgVoteWeighted = "weighted_vote" - TypeMsgSubmitProposal = "submit_proposal" -) - var ( - _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} - _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{} + _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} + _, _, _, _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} + + _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{} ) // NewMsgSubmitProposal creates a new MsgSubmitProposal. @@ -83,12 +77,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 +128,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 +162,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 +193,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..624bbc603680 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -12,13 +12,10 @@ import ( "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{} + _ sdk.HasAminoSigningCapability = &MsgCreateGroup{} +) // GetSignBytes Implements Msg. func (m MsgCreateGroup) GetSignBytes() []byte { @@ -60,15 +57,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{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupAdmin{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupAdmin) GetSignBytes() []byte { @@ -109,15 +101,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{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupMetadata{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupMetadata) GetSignBytes() []byte { @@ -149,15 +136,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{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupMembers{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupMembers) GetSignBytes() []byte { @@ -200,6 +182,8 @@ func (m *MsgUpdateGroupMembers) GetGroupID() uint64 { var ( _ sdk.Msg = &MsgCreateGroupWithPolicy{} + _ sdk.HasAminoSigningCapability = &MsgCreateGroupWithPolicy{} + _ types.UnpackInterfacesMessage = MsgCreateGroupWithPolicy{} ) @@ -244,16 +228,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 +256,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{} + _ sdk.HasAminoSigningCapability = &MsgCreateGroupPolicy{} +) // GetSignBytes Implements Msg. func (m MsgCreateGroupPolicy) GetSignBytes() []byte { @@ -324,15 +293,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{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyAdmin{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyAdmin) GetSignBytes() []byte { @@ -371,6 +335,8 @@ func (m MsgUpdateGroupPolicyAdmin) ValidateBasic() error { var ( _ sdk.Msg = &MsgUpdateGroupPolicyDecisionPolicy{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyDecisionPolicy{} + _ types.UnpackInterfacesMessage = MsgUpdateGroupPolicyDecisionPolicy{} ) @@ -401,16 +367,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 +419,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{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyMetadata{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyMetadata) GetSignBytes() []byte { @@ -502,6 +453,8 @@ func (m MsgUpdateGroupPolicyMetadata) ValidateBasic() error { var ( _ sdk.Msg = &MsgCreateGroupPolicy{} + _ sdk.HasAminoSigningCapability = &MsgCreateGroupPolicy{} + _ types.UnpackInterfacesMessage = MsgCreateGroupPolicy{} ) @@ -559,7 +512,10 @@ func (m MsgCreateGroupPolicy) UnpackInterfaces(unpacker types.AnyUnpacker) error return unpacker.UnpackAny(m.DecisionPolicy, &decisionPolicy) } -var _ sdk.Msg = &MsgSubmitProposal{} +var ( + _ sdk.Msg = &MsgSubmitProposal{} + _ sdk.HasAminoSigningCapability = &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 +534,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 +626,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{} + _ sdk.HasAminoSigningCapability = &MsgWithdrawProposal{} +) // GetSignBytes Implements Msg. func (m MsgWithdrawProposal) GetSignBytes() []byte { @@ -712,15 +657,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{} + _ sdk.HasAminoSigningCapability = &MsgVote{} +) // GetSignBytes Implements Msg. func (m MsgVote) GetSignBytes() []byte { @@ -752,15 +692,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{} + _ sdk.HasAminoSigningCapability = &MsgExec{} +) // GetSignBytes Implements Msg. func (m MsgExec) GetSignBytes() []byte { @@ -786,15 +721,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{} + _ sdk.HasAminoSigningCapability = &MsgLeaveGroup{} +) // GetSignBytes Implements Msg func (m MsgLeaveGroup) GetSignBytes() []byte { diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index 4f958ec1a456..8dafa411530d 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -14,6 +14,9 @@ const ( var ( _ sdk.Msg = &MsgUnjail{} _ sdk.Msg = &MsgUpdateParams{} + + _ sdk.HasAminoSigningCapability = &MsgUnjail{} + _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} ) // NewMsgUnjail creates a new MsgUnjail instance @@ -25,12 +28,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 +54,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/types/msg.go b/x/staking/types/msg.go index 588e54df52e5..ea18e1d8284f 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -8,27 +8,23 @@ import ( 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" -) - 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{} + + _ sdk.HasAminoSigningCapability = &MsgCreateValidator{} + _ sdk.HasAminoSigningCapability = &MsgEditValidator{} + _ sdk.HasAminoSigningCapability = &MsgDelegate{} + _ sdk.HasAminoSigningCapability = &MsgUndelegate{} + _ sdk.HasAminoSigningCapability = &MsgBeginRedelegate{} + _ sdk.HasAminoSigningCapability = &MsgCancelUnbondingDelegation{} + _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} ) // NewMsgCreateValidator creates a new MsgCreateValidator instance. @@ -54,12 +50,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 +128,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 +177,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 +222,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 +267,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 +310,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) diff --git a/x/upgrade/types/msgs.go b/x/upgrade/types/msgs.go index 86dc6a1338b2..85f036c3173a 100644 --- a/x/upgrade/types/msgs.go +++ b/x/upgrade/types/msgs.go @@ -3,20 +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 = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} - _, _ legacytx.LegacyMsg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} + _, _ sdk.Msg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} + _, _ sdk.HasAminoSigningCapability = &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 +34,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)) From afaf035f284a0c115e730e1ca23867f72d58dda3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 14:40:36 +0100 Subject: [PATCH 02/12] renaming --- testutil/testdata/tx.go | 5 +- types/simulation/types.go | 3 +- types/tx_msg.go | 10 -- x/auth/migrations/legacytx/stdsign.go | 16 +--- x/auth/types/msgs.go | 10 +- x/auth/vesting/types/msgs.go | 7 +- x/authz/msgs.go | 7 +- x/authz/msgs_test.go | 2 +- x/bank/simulation/operations.go | 31 ++++--- x/bank/simulation/operations_test.go | 16 ++-- x/bank/types/msgs.go | 7 +- x/bank/types/msgs_test.go | 25 ----- x/consensus/types/msgs.go | 9 +- x/crisis/types/msgs.go | 5 +- x/distribution/simulation/operations.go | 22 ++--- x/distribution/simulation/operations_test.go | 8 +- x/distribution/types/msg.go | 13 +-- x/evidence/types/msgs.go | 3 +- x/feegrant/msgs.go | 3 +- x/feegrant/msgs_test.go | 2 +- x/feegrant/simulation/operations.go | 2 - x/gov/simulation/operations.go | 16 ++-- x/gov/simulation/operations_test.go | 10 +- x/gov/types/v1/msgs.go | 3 +- x/gov/types/v1beta1/msgs.go | 5 +- x/group/msgs.go | 61 ++++++------ x/group/msgs_test.go | 28 +++--- x/group/simulation/operations.go | 90 +++++++++--------- x/mint/types/msgs.go | 10 +- x/simulation/util.go | 9 +- x/slashing/simulation/operations.go | 20 ++-- x/slashing/simulation/operations_test.go | 3 +- x/slashing/types/msg.go | 10 +- x/staking/keeper/msg_server.go | 6 +- x/staking/simulation/operations.go | 97 ++++++++++---------- x/staking/simulation/operations_test.go | 12 +-- x/staking/types/msg.go | 23 ++--- x/upgrade/types/msgs.go | 5 +- x/upgrade/types/msgs_test.go | 2 - 39 files changed, 292 insertions(+), 324 deletions(-) diff --git a/testutil/testdata/tx.go b/testutil/testdata/tx.go index a1b2550b7ca5..6053a903319e 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -13,6 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // AddressGenerator creates and returns a random address generator using rapid. @@ -77,8 +78,8 @@ func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg { } var ( - _ sdk.Msg = (*TestMsg)(nil) - _ sdk.HasAminoSigningCapability = (*TestMsg)(nil) + _ sdk.Msg = (*TestMsg)(nil) + _ legacytx.LegacyMsg = (*TestMsg)(nil) ) func (msg *TestMsg) GetSignBytes() []byte { diff --git a/types/simulation/types.go b/types/simulation/types.go index af0c72768b72..4d6560e22970 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) type WeightedProposalContent interface { @@ -77,7 +78,7 @@ 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.(sdk.HasAminoSigningCapability); okType { + if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType { return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, legacyMsg.GetSignBytes()) } diff --git a/types/tx_msg.go b/types/tx_msg.go index dc5991ac77a9..41c647e57de5 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -25,16 +25,6 @@ type ( GetSigners() []AccAddress } - // Extension interface for Msg that require Amino Signing - // Replaces legacytx.LegacyMsg. - // Deprecated: use Msg instead. - HasAminoSigningCapability interface { - Msg - - // Get the canonical byte representation of the Msg. - GetSignBytes() []byte - } - // Fee defines an interface for an application application-defined concrete // transaction type to be able to set and return the transaction fee. Fee interface { diff --git a/x/auth/migrations/legacytx/stdsign.go b/x/auth/migrations/legacytx/stdsign.go index f54bc5186b4c..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. @@ -55,9 +47,9 @@ type StdSignDoc struct { func StdSignBytes(chainID string, accnum, sequence, timeout uint64, fee StdFee, msgs []sdk.Msg, memo string, tip *tx.Tip) []byte { msgsBytes := make([]json.RawMessage, 0, len(msgs)) for _, msg := range msgs { - legacyMsg, ok := msg.(sdk.HasAminoSigningCapability) + legacyMsg, ok := msg.(LegacyMsg) if !ok { - panic(fmt.Errorf("expected %T when using amino JSON", (*sdk.HasAminoSigningCapability)(nil))) + panic(fmt.Errorf("expected %T when using amino JSON", (*LegacyMsg)(nil))) } msgsBytes = append(msgsBytes, json.RawMessage(legacyMsg.GetSignBytes())) 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 74bf0384974b..f21fe53d1dff 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -5,6 +5,7 @@ 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 ( @@ -12,9 +13,9 @@ var ( _ sdk.Msg = &MsgCreatePermanentLockedAccount{} _ sdk.Msg = &MsgCreatePeriodicVestingAccount{} - _ sdk.HasAminoSigningCapability = &MsgCreateVestingAccount{} - _ sdk.HasAminoSigningCapability = &MsgCreatePermanentLockedAccount{} - _ sdk.HasAminoSigningCapability = &MsgCreatePeriodicVestingAccount{} + _ legacytx.LegacyMsg = &MsgCreateVestingAccount{} + _ legacytx.LegacyMsg = &MsgCreatePermanentLockedAccount{} + _ legacytx.LegacyMsg = &MsgCreatePeriodicVestingAccount{} ) // NewMsgCreateVestingAccount returns a reference to a new MsgCreateVestingAccount. diff --git a/x/authz/msgs.go b/x/authz/msgs.go index 33e0bb63a585..6957c91dcc3a 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -3,6 +3,7 @@ package authz import ( "time" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" "github.com/cosmos/gogoproto/proto" @@ -18,9 +19,9 @@ var ( _ sdk.Msg = &MsgExec{} // For amino support. - _ sdk.HasAminoSigningCapability = &MsgGrant{} - _ sdk.HasAminoSigningCapability = &MsgRevoke{} - _ sdk.HasAminoSigningCapability = &MsgExec{} + _ legacytx.LegacyMsg = &MsgGrant{} + _ legacytx.LegacyMsg = &MsgRevoke{} + _ legacytx.LegacyMsg = &MsgExec{} _ cdctypes.UnpackInterfacesMessage = &MsgGrant{} _ cdctypes.UnpackInterfacesMessage = &MsgExec{} diff --git a/x/authz/msgs_test.go b/x/authz/msgs_test.go index 7a7070916d3f..5d7eb3c39fb9 100644 --- a/x/authz/msgs_test.go +++ b/x/authz/msgs_test.go @@ -165,7 +165,7 @@ func TestMsgGrantGetAuthorization(t *testing.T) { func TestAminoJSON(t *testing.T) { tx := legacytx.StdTx{} - var msg sdk.HasAminoSigningCapability + var msg legacytx.LegacyMsg blockTime := time.Date(1, 1, 1, 1, 1, 1, 1, time.UTC) expiresAt := blockTime.Add(time.Hour) msgSend := banktypes.MsgSend{FromAddress: "cosmos1ghi", ToAddress: "cosmos1jkl"} diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 7818ebf1a2b6..68932910784f 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -62,27 +62,29 @@ 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 +98,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 +181,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 +204,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 +220,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 +258,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 +271,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 +286,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 +318,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..760281b92809 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(types.TypeMsgSend, 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()) + require.Equal(types.TypeMsgMultiSend, 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(types.TypeMsgSend, 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(types.TypeMsgMultiSend, sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index 09c63d42ef59..8bb09b461adb 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -3,6 +3,7 @@ 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 ( @@ -10,9 +11,9 @@ var ( _ sdk.Msg = &MsgMultiSend{} _ sdk.Msg = &MsgUpdateParams{} - _ sdk.HasAminoSigningCapability = &MsgSend{} - _ sdk.HasAminoSigningCapability = &MsgMultiSend{} - _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgSend{} + _ legacytx.LegacyMsg = &MsgMultiSend{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) // NewMsgSend - construct a msg to send coins from one account to another. 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 7671427c8b78..10efaf60d83f 100644 --- a/x/consensus/types/msgs.go +++ b/x/consensus/types/msgs.go @@ -5,15 +5,12 @@ import ( tmtypes "github.com/tendermint/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" -) - -const ( - TypeMsgUpdateParams = "update_params" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( - _ sdk.Msg = &MsgUpdateParams{} - _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} + _ sdk.Msg = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) // GetSigners returns the signer addresses that are expected to sign the result diff --git a/x/crisis/types/msgs.go b/x/crisis/types/msgs.go index 43b379409132..665183b98a5f 100644 --- a/x/crisis/types/msgs.go +++ b/x/crisis/types/msgs.go @@ -3,12 +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" ) // ensure Msg interface compliance at compile time var ( - _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} - _, _ sdk.HasAminoSigningCapability = &MsgVerifyInvariant{}, &MsgUpdateParams{} + _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} + _, _ legacytx.LegacyMsg = &MsgVerifyInvariant{}, &MsgUpdateParams{} ) // NewMsgVerifyInvariant creates a new MsgVerifyInvariant object 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..3e7cf34a8cf6 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -84,7 +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.TypeMsgSetWithdrawAddress, sdk.MsgTypeURL(msg)) suite.Require().Equal(types.ModuleName, msg.Route()) suite.Require().Len(futureOperations, 0) } @@ -125,7 +125,7 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() { suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1l4s054098kk9hmr5753c6k3m2kw65h686d3mhr", msg.ValidatorAddress) suite.Require().Equal("cosmos1d6u7zhjwmsucs678d7qn95uqajd4ucl9jcjt26", msg.DelegatorAddress) - suite.Require().Equal(types.TypeMsgWithdrawDelegatorReward, msg.Type()) + suite.Require().Equal(types.TypeMsgWithdrawDelegatorReward, sdk.MsgTypeURL(msg)) suite.Require().Equal(types.ModuleName, msg.Route()) suite.Require().Len(futureOperations, 0) } @@ -185,7 +185,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.TypeMsgWithdrawValidatorCommission, sdk.MsgTypeURL(msg)) suite.Require().Equal(types.ModuleName, msg.Route()) suite.Require().Len(futureOperations, 0) } @@ -213,7 +213,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.TypeMsgFundCommunityPool, sdk.MsgTypeURL(msg)) suite.Require().Equal(types.ModuleName, msg.Route()) suite.Require().Len(futureOperations, 0) } diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go index c5da45de29a6..1bd3edcdcc63 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // Verify interface at compile time @@ -16,12 +17,12 @@ var ( _ sdk.Msg = (*MsgCommunityPoolSpend)(nil) _ sdk.Msg = (*MsgDepositValidatorRewardsPool)(nil) - _ sdk.HasAminoSigningCapability = (*MsgSetWithdrawAddress)(nil) - _ sdk.HasAminoSigningCapability = (*MsgWithdrawDelegatorReward)(nil) - _ sdk.HasAminoSigningCapability = (*MsgWithdrawValidatorCommission)(nil) - _ sdk.HasAminoSigningCapability = (*MsgUpdateParams)(nil) - _ sdk.HasAminoSigningCapability = (*MsgCommunityPoolSpend)(nil) - _ sdk.HasAminoSigningCapability = (*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 { diff --git a/x/evidence/types/msgs.go b/x/evidence/types/msgs.go index 4b422f0a2766..25a99e6e0575 100644 --- a/x/evidence/types/msgs.go +++ b/x/evidence/types/msgs.go @@ -9,11 +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" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( _ sdk.Msg = &MsgSubmitEvidence{} - _ sdk.HasAminoSigningCapability = &MsgSubmitEvidence{} + _ legacytx.LegacyMsg = &MsgSubmitEvidence{} _ types.UnpackInterfacesMessage = MsgSubmitEvidence{} _ exported.MsgSubmitEvidenceI = &MsgSubmitEvidence{} ) diff --git a/x/feegrant/msgs.go b/x/feegrant/msgs.go index 24929ddcdda1..33af976e41ac 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -6,12 +6,13 @@ import ( "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" ) var ( _, _ sdk.Msg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} // For amino support. - _, _ sdk.HasAminoSigningCapability = &MsgGrantAllowance{}, &MsgRevokeAllowance{} + _, _ legacytx.LegacyMsg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} _ types.UnpackInterfacesMessage = &MsgGrantAllowance{} ) diff --git a/x/feegrant/msgs_test.go b/x/feegrant/msgs_test.go index 383c08b771c6..f33849557c97 100644 --- a/x/feegrant/msgs_test.go +++ b/x/feegrant/msgs_test.go @@ -136,7 +136,7 @@ func TestMsgRevokeAllowance(t *testing.T) { func TestAminoJSON(t *testing.T) { tx := legacytx.StdTx{} - var msg sdk.HasAminoSigningCapability + var msg legacytx.LegacyMsg allowanceAny, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{SpendLimit: sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(100)))}) require.NoError(t, err) 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/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..622293938d03 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -143,7 +143,7 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { 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. @@ -188,7 +188,7 @@ func TestSimulateMsgCancelProposal(t *testing.T) { 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. @@ -235,7 +235,7 @@ func TestSimulateMsgDeposit(t *testing.T) { 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. @@ -280,7 +280,7 @@ func TestSimulateMsgVote(t *testing.T) { 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. @@ -324,7 +324,7 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { 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 8b07191e7031..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,7 +17,7 @@ import ( var ( _, _, _, _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} - _, _, _, _, _, _, _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} + _, _, _, _, _, _, _ legacytx.LegacyMsg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} _, _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{}, &MsgExecLegacyContent{} ) diff --git a/x/gov/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index 73a440795cab..6fb219deea96 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -9,13 +9,14 @@ 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" ) var ( - _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} - _, _, _, _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} + _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} + _, _, _, _ legacytx.LegacyMsg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{} ) diff --git a/x/group/msgs.go b/x/group/msgs.go index 624bbc603680..71d1e7482aee 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -7,14 +7,15 @@ 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{} - _ sdk.HasAminoSigningCapability = &MsgCreateGroup{} + _ sdk.Msg = &MsgCreateGroup{} + _ legacytx.LegacyMsg = &MsgCreateGroup{} ) // GetSignBytes Implements Msg. @@ -58,8 +59,8 @@ func (m MemberRequest) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgUpdateGroupAdmin{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupAdmin{} + _ sdk.Msg = &MsgUpdateGroupAdmin{} + _ legacytx.LegacyMsg = &MsgUpdateGroupAdmin{} ) // GetSignBytes Implements Msg. @@ -102,8 +103,8 @@ func (m *MsgUpdateGroupAdmin) GetGroupID() uint64 { } var ( - _ sdk.Msg = &MsgUpdateGroupMetadata{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupMetadata{} + _ sdk.Msg = &MsgUpdateGroupMetadata{} + _ legacytx.LegacyMsg = &MsgUpdateGroupMetadata{} ) // GetSignBytes Implements Msg. @@ -137,8 +138,8 @@ func (m *MsgUpdateGroupMetadata) GetGroupID() uint64 { } var ( - _ sdk.Msg = &MsgUpdateGroupMembers{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupMembers{} + _ sdk.Msg = &MsgUpdateGroupMembers{} + _ legacytx.LegacyMsg = &MsgUpdateGroupMembers{} ) // GetSignBytes Implements Msg. @@ -181,8 +182,8 @@ func (m *MsgUpdateGroupMembers) GetGroupID() uint64 { } var ( - _ sdk.Msg = &MsgCreateGroupWithPolicy{} - _ sdk.HasAminoSigningCapability = &MsgCreateGroupWithPolicy{} + _ sdk.Msg = &MsgCreateGroupWithPolicy{} + _ legacytx.LegacyMsg = &MsgCreateGroupWithPolicy{} _ types.UnpackInterfacesMessage = MsgCreateGroupWithPolicy{} ) @@ -257,8 +258,8 @@ func (m MsgCreateGroupWithPolicy) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgCreateGroupPolicy{} - _ sdk.HasAminoSigningCapability = &MsgCreateGroupPolicy{} + _ sdk.Msg = &MsgCreateGroupPolicy{} + _ legacytx.LegacyMsg = &MsgCreateGroupPolicy{} ) // GetSignBytes Implements Msg. @@ -294,8 +295,8 @@ func (m MsgCreateGroupPolicy) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgUpdateGroupPolicyAdmin{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyAdmin{} + _ sdk.Msg = &MsgUpdateGroupPolicyAdmin{} + _ legacytx.LegacyMsg = &MsgUpdateGroupPolicyAdmin{} ) // GetSignBytes Implements Msg. @@ -334,8 +335,8 @@ func (m MsgUpdateGroupPolicyAdmin) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgUpdateGroupPolicyDecisionPolicy{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyDecisionPolicy{} + _ sdk.Msg = &MsgUpdateGroupPolicyDecisionPolicy{} + _ legacytx.LegacyMsg = &MsgUpdateGroupPolicyDecisionPolicy{} _ types.UnpackInterfacesMessage = MsgUpdateGroupPolicyDecisionPolicy{} ) @@ -420,8 +421,8 @@ func (m MsgUpdateGroupPolicyDecisionPolicy) UnpackInterfaces(unpacker types.AnyU } var ( - _ sdk.Msg = &MsgUpdateGroupPolicyMetadata{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyMetadata{} + _ sdk.Msg = &MsgUpdateGroupPolicyMetadata{} + _ legacytx.LegacyMsg = &MsgUpdateGroupPolicyMetadata{} ) // GetSignBytes Implements Msg. @@ -452,8 +453,8 @@ func (m MsgUpdateGroupPolicyMetadata) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgCreateGroupPolicy{} - _ sdk.HasAminoSigningCapability = &MsgCreateGroupPolicy{} + _ sdk.Msg = &MsgCreateGroupPolicy{} + _ legacytx.LegacyMsg = &MsgCreateGroupPolicy{} _ types.UnpackInterfacesMessage = MsgCreateGroupPolicy{} ) @@ -513,8 +514,8 @@ func (m MsgCreateGroupPolicy) UnpackInterfaces(unpacker types.AnyUnpacker) error } var ( - _ sdk.Msg = &MsgSubmitProposal{} - _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{} + _ sdk.Msg = &MsgSubmitProposal{} + _ legacytx.LegacyMsg = &MsgSubmitProposal{} ) // NewMsgSubmitProposal creates a new MsgSubmitProposal. @@ -627,8 +628,8 @@ func (m MsgSubmitProposal) UnpackInterfaces(unpacker types.AnyUnpacker) error { } var ( - _ sdk.Msg = &MsgWithdrawProposal{} - _ sdk.HasAminoSigningCapability = &MsgWithdrawProposal{} + _ sdk.Msg = &MsgWithdrawProposal{} + _ legacytx.LegacyMsg = &MsgWithdrawProposal{} ) // GetSignBytes Implements Msg. @@ -658,8 +659,8 @@ func (m MsgWithdrawProposal) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgVote{} - _ sdk.HasAminoSigningCapability = &MsgVote{} + _ sdk.Msg = &MsgVote{} + _ legacytx.LegacyMsg = &MsgVote{} ) // GetSignBytes Implements Msg. @@ -693,8 +694,8 @@ func (m MsgVote) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgExec{} - _ sdk.HasAminoSigningCapability = &MsgExec{} + _ sdk.Msg = &MsgExec{} + _ legacytx.LegacyMsg = &MsgExec{} ) // GetSignBytes Implements Msg. @@ -722,8 +723,8 @@ func (m MsgExec) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgLeaveGroup{} - _ sdk.HasAminoSigningCapability = &MsgLeaveGroup{} + _ sdk.Msg = &MsgLeaveGroup{} + _ legacytx.LegacyMsg = &MsgLeaveGroup{} ) // GetSignBytes Implements Msg 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..f150cdab2395 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 } } @@ -1103,7 +1103,7 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, return simtypes.NoOpMsg(TypeMsgExec, 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/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/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..9f30d44b736f 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -123,7 +123,7 @@ 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 +181,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 8dafa411530d..df9178fd3d6f 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -3,11 +3,7 @@ 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 @@ -15,8 +11,8 @@ var ( _ sdk.Msg = &MsgUnjail{} _ sdk.Msg = &MsgUpdateParams{} - _ sdk.HasAminoSigningCapability = &MsgUnjail{} - _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgUnjail{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) // NewMsgUnjail creates a new MsgUnjail instance 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..f0ea235e8dab 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -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(types.TypeMsgCreateValidator, 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(types.TypeMsgCancelUnbondingDelegation, 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(types.TypeMsgEditValidator, 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(types.TypeMsgDelegate, 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(types.TypeMsgUndelegate, 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(types.TypeMsgBeginRedelegate, 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 ea18e1d8284f..4542f3b821d0 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -6,6 +6,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/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" ) var ( @@ -18,13 +19,13 @@ var ( _ sdk.Msg = &MsgCancelUnbondingDelegation{} _ sdk.Msg = &MsgUpdateParams{} - _ sdk.HasAminoSigningCapability = &MsgCreateValidator{} - _ sdk.HasAminoSigningCapability = &MsgEditValidator{} - _ sdk.HasAminoSigningCapability = &MsgDelegate{} - _ sdk.HasAminoSigningCapability = &MsgUndelegate{} - _ sdk.HasAminoSigningCapability = &MsgBeginRedelegate{} - _ sdk.HasAminoSigningCapability = &MsgCancelUnbondingDelegation{} - _ sdk.HasAminoSigningCapability = &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. @@ -349,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") } @@ -363,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 85f036c3173a..b14255433878 100644 --- a/x/upgrade/types/msgs.go +++ b/x/upgrade/types/msgs.go @@ -3,11 +3,12 @@ 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 = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} - _, _ sdk.HasAminoSigningCapability = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} + _, _ sdk.Msg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} + _, _ legacytx.LegacyMsg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} ) // GetSignBytes implements the LegacyMsg interface. 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{})) } }) } From 5f1eb344082daefeb706bb985c2cd4318fbf7b4c Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 15:54:39 +0100 Subject: [PATCH 03/12] updates --- baseapp/baseapp.go | 7 +-- types/simulation/types.go | 20 +++++--- types/tx_msg.go | 13 ++++++ x/authz/msgs.go | 6 +-- x/bank/simulation/operations_test.go | 24 +++++----- x/distribution/simulation/operations_test.go | 36 +++++++------- x/feegrant/msgs.go | 4 +- x/feegrant/simulation/operations_test.go | 8 ++-- x/gov/simulation/operations_test.go | 25 ++++------ x/group/simulation/operations_test.go | 30 ++++++------ x/simulation/event_stats.go | 12 ++--- x/slashing/simulation/operations_test.go | 4 +- x/staking/simulation/operations_test.go | 49 ++++++++++---------- 13 files changed, 123 insertions(+), 115 deletions(-) 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/types/simulation/types.go b/types/simulation/types.go index 4d6560e22970..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,16 +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 { + msgType := sdk.MsgTypeURL(msg) + moduleName := sdk.GetModuleNameFromTypeURL(msgType) + if moduleName == "" { + moduleName = msgType + } + if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType { - return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, legacyMsg.GetSignBytes()) + return NewOperationMsgBasic(moduleName, msgType, comment, ok, legacyMsg.GetSignBytes()) } - return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, cdc.MustMarshalJSON(msg)) + 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/x/authz/msgs.go b/x/authz/msgs.go index 6957c91dcc3a..792120d6de71 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -66,7 +66,7 @@ func (msg MsgGrant) ValidateBasic() error { return msg.Grant.ValidateBasic() } -// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgGrant) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } @@ -147,7 +147,7 @@ func (msg MsgRevoke) ValidateBasic() error { return nil } -// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgRevoke) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } @@ -215,7 +215,7 @@ func (msg MsgExec) ValidateBasic() error { return nil } -// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgExec) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index 760281b92809..f88e037a2812 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -105,14 +105,14 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("65337742stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.FromAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.ToAddress) - suite.Require().Equal(types.TypeMsgSend, sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } @@ -133,8 +133,8 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() { require := suite.Require() require.NoError(err) - var msg types.MsgMultiSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgMultiSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) require.Len(msg.Inputs, 1) @@ -143,7 +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, sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(msg)) require.Len(futureOperations, 0) } @@ -169,12 +169,12 @@ func (suite *SimTestSuite) TestSimulateModuleAccountMsgSend() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().Error(err) - var msg types.MsgSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().False(operationMsg.OK) suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(types.TypeMsgSend, sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } @@ -197,12 +197,12 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().Error(err) - var msg types.MsgMultiSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgMultiSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) 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, sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 3e7cf34a8cf6..3211dc43d287 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 { @@ -78,14 +78,13 @@ func (suite *SimTestSuite) TestSimulateMsgSetWithdrawAddress() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgSetWithdrawAddress - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgSetWithdrawAddress + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.WithdrawAddress) - suite.Require().Equal(types.TypeMsgSetWithdrawAddress, sdk.MsgTypeURL(msg)) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } @@ -119,14 +118,13 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgWithdrawDelegatorReward - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgWithdrawDelegatorReward + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1l4s054098kk9hmr5753c6k3m2kw65h686d3mhr", msg.ValidatorAddress) suite.Require().Equal("cosmos1d6u7zhjwmsucs678d7qn95uqajd4ucl9jcjt26", msg.DelegatorAddress) - suite.Require().Equal(types.TypeMsgWithdrawDelegatorReward, sdk.MsgTypeURL(msg)) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } @@ -180,13 +178,12 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName } else { suite.Require().NoError(err) - var msg types.MsgWithdrawValidatorCommission - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgWithdrawValidatorCommission + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) - suite.Require().Equal(types.TypeMsgWithdrawValidatorCommission, sdk.MsgTypeURL(msg)) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } } @@ -207,14 +204,13 @@ func (suite *SimTestSuite) TestSimulateMsgFundCommunityPool() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgFundCommunityPool - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgFundCommunityPool + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("4896096stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Depositor) - suite.Require().Equal(types.TypeMsgFundCommunityPool, sdk.MsgTypeURL(msg)) - 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/feegrant/msgs.go b/x/feegrant/msgs.go index 33af976e41ac..13f9a09ccd09 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -62,7 +62,7 @@ func (msg MsgGrantAllowance) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{granter} } -// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgGrantAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } @@ -113,7 +113,7 @@ func (msg MsgRevokeAllowance) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{granter} } -// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgRevokeAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } 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/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 622293938d03..29c97a8ece08 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -132,8 +132,8 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg v1.MsgSubmitProposal - err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *v1.MsgSubmitProposal + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -142,7 +142,6 @@ 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, sdk.MsgTypeURL(msg)) } @@ -180,14 +179,13 @@ func TestSimulateMsgCancelProposal(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg v1.MsgCancelProposal - err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *v1.MsgCancelProposal + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.NoError(t, err) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, proposer.String(), msg.Proposer) - require.Equal(t, "gov", msg.Route()) require.Equal(t, simulation.TypeMsgCancelProposal, sdk.MsgTypeURL(msg)) } @@ -225,8 +223,8 @@ func TestSimulateMsgDeposit(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg v1.MsgDeposit - err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *v1.MsgDeposit + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -234,7 +232,6 @@ 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, sdk.MsgTypeURL(msg)) } @@ -272,14 +269,13 @@ func TestSimulateMsgVote(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg v1.MsgVote - govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *v1.MsgVote + govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(t, operationMsg.OK) 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, sdk.MsgTypeURL(msg)) } @@ -316,14 +312,13 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg v1.MsgVoteWeighted - govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *v1.MsgVoteWeighted + govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(t, operationMsg.OK) 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, sdk.MsgTypeURL(msg)) } 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/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/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 9f30d44b736f..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, sdk.MsgTypeURL(&types.MsgUnjail{})}} + }{ + {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 { diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index f0ea235e8dab..ff52bd293106 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 { @@ -147,7 +147,6 @@ func (s *SimTestSuite) TestWeightedOperations() { // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail require.Equal(expected[i].weight, w.Weight(), "weight should be the same") - require.Equal(expected[i].opMsgRoute, operationMsg.Route, "route should be the same") require.Equal(expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same") } } @@ -164,11 +163,11 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, s.ctx, s.accounts[1:], "") require.NoError(err) - var msg types.MsgCreateValidator - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgCreateValidator + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgCreateValidator, sdk.MsgTypeURL(msg)) + 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()) @@ -210,11 +209,11 @@ func (s *SimTestSuite) TestSimulateMsgCancelUnbondingDelegation() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, accounts, "") require.NoError(err) - var msg types.MsgCancelUnbondingDelegation - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgCancelUnbondingDelegation + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgCancelUnbondingDelegation, sdk.MsgTypeURL(msg)) + 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) @@ -238,11 +237,11 @@ func (s *SimTestSuite) TestSimulateMsgEditValidator() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts, "") require.NoError(err) - var msg types.MsgEditValidator - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgEditValidator + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgEditValidator, sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgEditValidator{}), sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -259,13 +258,13 @@ func (s *SimTestSuite) TestSimulateMsgDelegate() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts[1:], "") require.NoError(err) - var msg types.MsgDelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgDelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgDelegate, sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgDelegate{}), sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -298,14 +297,14 @@ func (s *SimTestSuite) TestSimulateMsgUndelegate() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts, "") require.NoError(err) - var msg types.MsgUndelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgUndelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) require.Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) require.Equal("1646627814093010272", msg.Amount.Amount.String()) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgUndelegate, sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgUndelegate{}), sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -342,13 +341,13 @@ func (s *SimTestSuite) TestSimulateMsgBeginRedelegate() { s.T().Logf("operation message: %v", operationMsg) require.NoError(err) - var msg types.MsgBeginRedelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgBeginRedelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) require.Equal("cosmos1ua0fwyws7vzjrry3pqkklvf8mny93l9s9zg0h4", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgBeginRedelegate, sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgBeginRedelegate{}), sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1ghekyjucln7y67ntx7cf27m9dpuxxemnsvnaes", msg.ValidatorDstAddress) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorSrcAddress) require.Len(futureOperations, 0) From 3ce49dc13d39823edaad08bf8d9b5cbc6412ffd7 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:18:48 +0100 Subject: [PATCH 04/12] updates --- docs/docs/building-modules/02-messages-and-queries.md | 2 -- docs/docs/core/08-events.md | 1 - x/gov/client/utils/query_test.go | 3 +-- x/gov/types/v1beta1/msgs.go | 8 ++++++++ 4 files changed, 9 insertions(+), 5 deletions(-) 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/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/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index 6fb219deea96..3bff5eff98db 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -14,6 +14,14 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" ) +// Governance message types and routes +const ( + TypeMsgDeposit = "deposit" + TypeMsgVote = "vote" + TypeMsgVoteWeighted = "weighted_vote" + TypeMsgSubmitProposal = "submit_proposal" +) + var ( _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} _, _, _, _ legacytx.LegacyMsg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} From 9c0f1113908aa1c65c10e6b0db11c2df21fa4e85 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:22:28 +0100 Subject: [PATCH 05/12] updates --- testutil/testdata/tx.go | 6 +----- x/staking/simulation/operations_test.go | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/testutil/testdata/tx.go b/testutil/testdata/tx.go index 6053a903319e..9b4e081253ff 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -13,7 +13,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // AddressGenerator creates and returns a random address generator using rapid. @@ -77,10 +76,7 @@ func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg { } } -var ( - _ sdk.Msg = (*TestMsg)(nil) - _ legacytx.LegacyMsg = (*TestMsg)(nil) -) +var _ sdk.Msg = (*TestMsg)(nil) func (msg *TestMsg) GetSignBytes() []byte { bz, err := json.Marshal(msg.Signers) diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index ff52bd293106..362751278551 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -147,6 +147,7 @@ func (s *SimTestSuite) TestWeightedOperations() { // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail require.Equal(expected[i].weight, w.Weight(), "weight should be the same") + require.Equal(expected[i].opMsgRoute, operationMsg.Route, "route should be the same") require.Equal(expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same") } } From de280320ecce8f8a658dbddf9566d454f1470436 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:25:12 +0100 Subject: [PATCH 06/12] add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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`. From 29300e8a7962089f87b6856b77128563f51b3893 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:32:54 +0100 Subject: [PATCH 07/12] revert --- x/evidence/types/genesis_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/x/evidence/types/genesis_test.go b/x/evidence/types/genesis_test.go index 79c57ef4c2d6..425aceb8b909 100644 --- a/x/evidence/types/genesis_test.go +++ b/x/evidence/types/genesis_test.go @@ -164,6 +164,14 @@ func (*TestEvidence) String() string { return "test-string" } +func (*TestEvidence) Route() string { + return "test-route" +} + +func (*TestEvidence) Type() string { + return "test-type" +} + func (*TestEvidence) ProtoMessage() {} func (*TestEvidence) Reset() {} From a7dee1e3054adf6b8fd9d352152cd81e2db2ba49 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:42:05 +0100 Subject: [PATCH 08/12] updates --- x/bank/simulation/operations.go | 1 - x/bank/simulation/operations_test.go | 24 ++++++------- x/distribution/simulation/operations_test.go | 24 ++++++------- x/staking/simulation/operations_test.go | 36 ++++++++++---------- 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 68932910784f..25aa67759269 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -62,7 +62,6 @@ 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) diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index f88e037a2812..0988c8d1c42b 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -105,14 +105,14 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg *types.MsgSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("65337742stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.FromAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.ToAddress) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -133,8 +133,8 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() { require := suite.Require() require.NoError(err) - var msg *types.MsgMultiSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgMultiSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) require.Len(msg.Inputs, 1) @@ -143,7 +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()) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(&msg)) require.Len(futureOperations, 0) } @@ -169,12 +169,12 @@ func (suite *SimTestSuite) TestSimulateModuleAccountMsgSend() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().Error(err) - var msg *types.MsgSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().False(operationMsg.OK) suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -197,12 +197,12 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().Error(err) - var msg *types.MsgMultiSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgMultiSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().False(operationMsg.OK) // sending tokens to a module account should fail suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 3211dc43d287..717b105cbd9f 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -78,13 +78,13 @@ func (suite *SimTestSuite) TestSimulateMsgSetWithdrawAddress() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg *types.MsgSetWithdrawAddress - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgSetWithdrawAddress + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.WithdrawAddress) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -118,13 +118,13 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg *types.MsgWithdrawDelegatorReward - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgWithdrawDelegatorReward + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1l4s054098kk9hmr5753c6k3m2kw65h686d3mhr", msg.ValidatorAddress) suite.Require().Equal("cosmos1d6u7zhjwmsucs678d7qn95uqajd4ucl9jcjt26", msg.DelegatorAddress) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -178,12 +178,12 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName } else { suite.Require().NoError(err) - var msg *types.MsgWithdrawValidatorCommission - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgWithdrawValidatorCommission + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } } @@ -204,13 +204,13 @@ func (suite *SimTestSuite) TestSimulateMsgFundCommunityPool() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg *types.MsgFundCommunityPool - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgFundCommunityPool + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("4896096stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Depositor) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index 362751278551..d3f11642eae1 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -164,11 +164,11 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, s.ctx, s.accounts[1:], "") require.NoError(err) - var msg *types.MsgCreateValidator - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgCreateValidator + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(sdk.MsgTypeURL(&types.MsgCreateValidator{}), sdk.MsgTypeURL(msg)) + 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()) @@ -210,11 +210,11 @@ func (s *SimTestSuite) TestSimulateMsgCancelUnbondingDelegation() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, accounts, "") require.NoError(err) - var msg *types.MsgCancelUnbondingDelegation - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgCancelUnbondingDelegation + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{}), sdk.MsgTypeURL(msg)) + 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) @@ -238,11 +238,11 @@ func (s *SimTestSuite) TestSimulateMsgEditValidator() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts, "") require.NoError(err) - var msg *types.MsgEditValidator - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgEditValidator + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(sdk.MsgTypeURL(&types.MsgEditValidator{}), sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgEditValidator{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -259,13 +259,13 @@ func (s *SimTestSuite) TestSimulateMsgDelegate() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts[1:], "") require.NoError(err) - var msg *types.MsgDelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgDelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(sdk.MsgTypeURL(&types.MsgDelegate{}), sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgDelegate{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -298,14 +298,14 @@ func (s *SimTestSuite) TestSimulateMsgUndelegate() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts, "") require.NoError(err) - var msg *types.MsgUndelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgUndelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) require.Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) require.Equal("1646627814093010272", msg.Amount.Amount.String()) require.Equal("stake", msg.Amount.Denom) - require.Equal(sdk.MsgTypeURL(&types.MsgUndelegate{}), sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgUndelegate{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -342,13 +342,13 @@ func (s *SimTestSuite) TestSimulateMsgBeginRedelegate() { s.T().Logf("operation message: %v", operationMsg) require.NoError(err) - var msg *types.MsgBeginRedelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgBeginRedelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) require.Equal("cosmos1ua0fwyws7vzjrry3pqkklvf8mny93l9s9zg0h4", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(sdk.MsgTypeURL(&types.MsgBeginRedelegate{}), sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgBeginRedelegate{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1ghekyjucln7y67ntx7cf27m9dpuxxemnsvnaes", msg.ValidatorDstAddress) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorSrcAddress) require.Len(futureOperations, 0) From 305ea9fee121108def1ed26cae780b099679fcc3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:58:03 +0100 Subject: [PATCH 09/12] improvements --- x/authz/simulation/operations_test.go | 16 +++++++--------- x/group/simulation/operations.go | 12 ++++++------ 2 files changed, 13 insertions(+), 15 deletions(-) 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/group/simulation/operations.go b/x/group/simulation/operations.go index f150cdab2395..9b19fd692f46 100644 --- a/x/group/simulation/operations.go +++ b/x/group/simulation/operations.go @@ -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,7 +1100,7 @@ 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{ From 598d1c632262bae1927c090a2f78393d5327cf3a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 17:05:40 +0100 Subject: [PATCH 10/12] last fix --- x/gov/simulation/operations_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 29c97a8ece08..d652e672b448 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -132,8 +132,8 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg *v1.MsgSubmitProposal - err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg v1.MsgSubmitProposal + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -142,7 +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, simulation.TypeMsgSubmitProposal, sdk.MsgTypeURL(msg)) + require.Equal(t, simulation.TypeMsgSubmitProposal, sdk.MsgTypeURL(&msg)) } // TestSimulateMsgCancelProposal tests the normal scenario of a valid message of type TypeMsgCancelProposal. From b6c33de118b5b549e7baa0a6a1e6e8a6a2f5908d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 17:26:54 +0100 Subject: [PATCH 11/12] typo --- x/authz/msgs.go | 2 +- x/gov/simulation/operations_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x/authz/msgs.go b/x/authz/msgs.go index 792120d6de71..f96163b7f334 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -3,7 +3,6 @@ package authz import ( "time" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" "github.com/cosmos/gogoproto/proto" @@ -11,6 +10,7 @@ import ( cdctypes "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" ) var ( diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index d652e672b448..06111376312b 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -179,14 +179,14 @@ func TestSimulateMsgCancelProposal(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg *v1.MsgCancelProposal - err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg v1.MsgCancelProposal + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.NoError(t, err) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, proposer.String(), msg.Proposer) - require.Equal(t, simulation.TypeMsgCancelProposal, sdk.MsgTypeURL(msg)) + require.Equal(t, simulation.TypeMsgCancelProposal, sdk.MsgTypeURL(&msg)) } // TestSimulateMsgDeposit tests the normal scenario of a valid message of type TypeMsgDeposit. @@ -223,8 +223,8 @@ func TestSimulateMsgDeposit(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg *v1.MsgDeposit - err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg v1.MsgDeposit + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -232,7 +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, simulation.TypeMsgDeposit, sdk.MsgTypeURL(msg)) + require.Equal(t, simulation.TypeMsgDeposit, sdk.MsgTypeURL(&msg)) } // TestSimulateMsgVote tests the normal scenario of a valid message of type TypeMsgVote. From 67502e92eeadf664187788e22aedd4c56c70e04e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 17:42:00 +0100 Subject: [PATCH 12/12] fix failing tests --- x/gov/simulation/operations_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 06111376312b..32cdc02ca246 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -269,14 +269,14 @@ func TestSimulateMsgVote(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg *v1.MsgVote - govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg v1.MsgVote + govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Voter) require.Equal(t, v1.OptionYes, msg.Option) - require.Equal(t, simulation.TypeMsgVote, sdk.MsgTypeURL(msg)) + require.Equal(t, simulation.TypeMsgVote, sdk.MsgTypeURL(&msg)) } // TestSimulateMsgVoteWeighted tests the normal scenario of a valid message of type TypeMsgVoteWeighted. @@ -312,14 +312,14 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg *v1.MsgVoteWeighted - govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg v1.MsgVoteWeighted + govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Voter) require.True(t, len(msg.Options) >= 1) - require.Equal(t, simulation.TypeMsgVoteWeighted, sdk.MsgTypeURL(msg)) + require.Equal(t, simulation.TypeMsgVoteWeighted, sdk.MsgTypeURL(&msg)) } type suite struct {