Skip to content

Commit

Permalink
Remove GetSigners from sdk.Msg implementations (cosmos#5305)
Browse files Browse the repository at this point in the history
* remove GetSigners from module transfer

* remove GetSigners from module ica

* remove GetSigners from module fee

* remove GetSigners from module 02-client

* remove GetSigners from module 03-connection

* remove GetSigners from module 04-channel

* lint

* update with damiannolan's suggestion

* update with damiannolan's suggestion

* lint

* remove suite

* update with DimitrisJim's suggestion
  • Loading branch information
ThanhNhann authored Dec 6, 2023
1 parent d373879 commit b04b843
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 351 deletions.
4 changes: 2 additions & 2 deletions e2e/tests/wasm/grandpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
"github.com/strangelove-ventures/interchaintest/v8/testutil"
testifysuite "github.com/stretchr/testify/suite"

cmtjson "github.com/cometbft/cometbft/libs/json"

"cosmossdk.io/math"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"

cmtjson "github.com/cometbft/cometbft/libs/json"

"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testvalues"
wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
Expand Down
30 changes: 0 additions & 30 deletions modules/apps/27-interchain-accounts/controller/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ func (msg MsgRegisterInterchainAccount) ValidateBasic() error {
return nil
}

// GetSigners implements sdk.Msg
func (msg MsgRegisterInterchainAccount) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Owner)
if err != nil {
panic(err)
}

return []sdk.AccAddress{accAddr}
}

// NewMsgSendTx creates a new instance of MsgSendTx
func NewMsgSendTx(owner, connectionID string, relativeTimeoutTimestamp uint64, packetData icatypes.InterchainAccountPacketData) *MsgSendTx {
return &MsgSendTx{
Expand Down Expand Up @@ -95,16 +85,6 @@ func (msg MsgSendTx) ValidateBasic() error {
return nil
}

// GetSigners implements sdk.Msg
func (msg MsgSendTx) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Owner)
if err != nil {
panic(err)
}

return []sdk.AccAddress{accAddr}
}

// NewMsgUpdateParams creates a new MsgUpdateParams instance
func NewMsgUpdateParams(signer string, params Params) *MsgUpdateParams {
return &MsgUpdateParams{
Expand All @@ -122,13 +102,3 @@ func (msg MsgUpdateParams) ValidateBasic() error {

return nil
}

// GetSigners implements sdk.Msg
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{accAddr}
}
20 changes: 14 additions & 6 deletions modules/apps/27-interchain-accounts/controller/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) {
require.NoError(t, err)

msg := types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "")
require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners())
encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
require.NoError(t, err)
require.Equal(t, expSigner.Bytes(), signers[0])
}

func TestMsgSendTxValidateBasic(t *testing.T) {
Expand Down Expand Up @@ -214,7 +217,9 @@ func TestMsgSendTxGetSigners(t *testing.T) {
100000,
packetData,
)
require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners())
signers, _, err := encodingConfig.Codec.GetMsgV1Signers(msg)
require.NoError(t, err)
require.Equal(t, expSigner.Bytes(), signers[0])
}

// TestMsgUpdateParamsValidateBasic tests ValidateBasic for MsgUpdateParams
Expand Down Expand Up @@ -259,12 +264,15 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) {
Signer: tc.address.String(),
Params: types.DefaultParams(),
}

encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(&msg)
if tc.expPass {
require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners())
require.NoError(t, err)
require.Equal(t, tc.address.Bytes(), signers[0])
} else {
require.Panics(t, func() {
msg.GetSigners()
})
require.Error(t, err)
}

}
}
10 changes: 0 additions & 10 deletions modules/apps/27-interchain-accounts/host/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,3 @@ func (msg MsgUpdateParams) ValidateBasic() error {

return msg.Params.Validate()
}

// GetSigners implements sdk.Msg
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{accAddr}
}
11 changes: 7 additions & 4 deletions modules/apps/27-interchain-accounts/host/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"

ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)
Expand Down Expand Up @@ -62,12 +64,13 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) {
tc := tc

msg := types.NewMsgUpdateParams(tc.address.String(), types.DefaultParams())
encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
if tc.expPass {
require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners())
require.NoError(t, err)
require.Equal(t, tc.address.Bytes(), signers[0])
} else {
require.Panics(t, func() {
msg.GetSigners()
})
require.Error(t, err)
}
}
}
39 changes: 0 additions & 39 deletions modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ func (msg MsgRegisterPayee) ValidateBasic() error {
return nil
}

// GetSigners implements sdk.Msg
func (msg MsgRegisterPayee) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Relayer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{signer}
}

// NewMsgRegisterCounterpartyPayee creates a new instance of MsgRegisterCounterpartyPayee
func NewMsgRegisterCounterpartyPayee(portID, channelID, relayerAddr, counterpartyPayeeAddr string) *MsgRegisterCounterpartyPayee {
return &MsgRegisterCounterpartyPayee{
Expand Down Expand Up @@ -109,16 +99,6 @@ func (msg MsgRegisterCounterpartyPayee) ValidateBasic() error {
return nil
}

// GetSigners implements sdk.Msg
func (msg MsgRegisterCounterpartyPayee) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Relayer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{signer}
}

// NewMsgPayPacketFee creates a new instance of MsgPayPacketFee
func NewMsgPayPacketFee(fee Fee, sourcePortID, sourceChannelID, signer string, relayers []string) *MsgPayPacketFee {
return &MsgPayPacketFee{
Expand Down Expand Up @@ -155,15 +135,6 @@ func (msg MsgPayPacketFee) ValidateBasic() error {
return msg.Fee.Validate()
}

// GetSigners implements sdk.Msg
func (msg MsgPayPacketFee) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}
return []sdk.AccAddress{signer}
}

// NewMsgPayPacketAsync creates a new instance of MsgPayPacketFee
func NewMsgPayPacketFeeAsync(packetID channeltypes.PacketId, packetFee PacketFee) *MsgPayPacketFeeAsync {
return &MsgPayPacketFeeAsync{
Expand All @@ -180,13 +151,3 @@ func (msg MsgPayPacketFeeAsync) ValidateBasic() error {

return msg.PacketFee.Validate()
}

// GetSigners implements sdk.Msg
// The signer of the fee message must be the refund address
func (msg MsgPayPacketFeeAsync) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.PacketFee.RefundAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{signer}
}
25 changes: 20 additions & 5 deletions modules/apps/29-fee/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"

"github.com/cometbft/cometbft/crypto/secp256k1"

modulefee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee"
"github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
Expand Down Expand Up @@ -88,7 +90,11 @@ func TestMsgRegisterPayeeValidation(t *testing.T) {
func TestRegisterPayeeGetSigners(t *testing.T) {
accAddress := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
msg := types.NewMsgRegisterPayee(ibctesting.MockPort, ibctesting.FirstChannelID, accAddress.String(), defaultAccAddress)
require.Equal(t, []sdk.AccAddress{accAddress}, msg.GetSigners())

encodingCfg := moduletestutil.MakeTestEncodingConfig(modulefee.AppModuleBasic{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
require.NoError(t, err)
require.Equal(t, accAddress.Bytes(), signers[0])
}

func TestMsgRegisterCountepartyPayeeValidation(t *testing.T) {
Expand Down Expand Up @@ -168,7 +174,11 @@ func TestMsgRegisterCountepartyPayeeValidation(t *testing.T) {
func TestRegisterCountepartyAddressGetSigners(t *testing.T) {
accAddress := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
msg := types.NewMsgRegisterCounterpartyPayee(ibctesting.MockPort, ibctesting.FirstChannelID, accAddress.String(), defaultAccAddress)
require.Equal(t, []sdk.AccAddress{accAddress}, msg.GetSigners())

encodingCfg := moduletestutil.MakeTestEncodingConfig(modulefee.AppModuleBasic{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
require.NoError(t, err)
require.Equal(t, accAddress.Bytes(), signers[0])
}

func TestMsgPayPacketFeeValidation(t *testing.T) {
Expand Down Expand Up @@ -244,7 +254,10 @@ func TestPayPacketFeeGetSigners(t *testing.T) {
fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)
msg := types.NewMsgPayPacketFee(fee, ibctesting.MockFeePort, ibctesting.FirstChannelID, refundAddr.String(), nil)

require.Equal(t, []sdk.AccAddress{refundAddr}, msg.GetSigners())
encodingCfg := moduletestutil.MakeTestEncodingConfig(modulefee.AppModuleBasic{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
require.NoError(t, err)
require.Equal(t, refundAddr.Bytes(), signers[0])
}

func TestMsgPayPacketFeeAsyncValidation(t *testing.T) {
Expand Down Expand Up @@ -378,8 +391,10 @@ func TestPayPacketFeeAsyncGetSigners(t *testing.T) {
packetID := channeltypes.NewPacketID(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1)
fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)
packetFee := types.NewPacketFee(fee, refundAddr.String(), nil)

msg := types.NewMsgPayPacketFeeAsync(packetID, packetFee)

require.Equal(t, []sdk.AccAddress{refundAddr}, msg.GetSigners())
encodingCfg := moduletestutil.MakeTestEncodingConfig(modulefee.AppModuleBasic{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
require.NoError(t, err)
require.Equal(t, refundAddr.Bytes(), signers[0])
}
21 changes: 1 addition & 20 deletions modules/apps/transfer/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ func (msg MsgUpdateParams) ValidateBasic() error {
return nil
}

// GetSigners implements sdk.Msg
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
accAddr, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
panic(err)
}

return []sdk.AccAddress{accAddr}
}

// NewMsgTransfer creates a new MsgTransfer instance
func NewMsgTransfer(
sourcePort, sourceChannel string,
Expand Down Expand Up @@ -88,7 +78,7 @@ func (msg MsgTransfer) ValidateBasic() error {
if !msg.Token.IsPositive() {
return errorsmod.Wrap(ibcerrors.ErrInsufficientFunds, msg.Token.String())
}
// NOTE: sender format must be validated as it is required by the GetSigners function.

_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
Expand All @@ -104,12 +94,3 @@ func (msg MsgTransfer) ValidateBasic() error {
}
return ValidateIBCDenom(msg.Token.Denom)
}

// GetSigners implements sdk.Msg
func (msg MsgTransfer) GetSigners() []sdk.AccAddress {
signer, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{signer}
}
19 changes: 12 additions & 7 deletions modules/apps/transfer/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"

"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
Expand Down Expand Up @@ -85,11 +87,12 @@ func TestMsgTransferValidation(t *testing.T) {
// TestMsgTransferGetSigners tests GetSigners for MsgTransfer
func TestMsgTransferGetSigners(t *testing.T) {
addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())

msg := types.NewMsgTransfer(validPort, validChannel, coin, addr.String(), receiver, timeoutHeight, 0, "")
res := msg.GetSigners()

require.Equal(t, []sdk.AccAddress{addr}, res)
encodingCfg := moduletestutil.MakeTestEncodingConfig(transfer.AppModuleBasic{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
require.NoError(t, err)
require.Equal(t, addr.Bytes(), signers[0])
}

// TestMsgUpdateParamsValidateBasic tests ValidateBasic for MsgUpdateParams
Expand Down Expand Up @@ -134,12 +137,14 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) {
Signer: tc.address.String(),
Params: types.DefaultParams(),
}

encodingCfg := moduletestutil.MakeTestEncodingConfig(transfer.AppModuleBasic{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(&msg)
if tc.expPass {
require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners())
require.NoError(t, err)
require.Equal(t, tc.address.Bytes(), signers[0])
} else {
require.Panics(t, func() {
msg.GetSigners()
})
require.Error(t, err)
}
}
}
Loading

0 comments on commit b04b843

Please sign in to comment.