From 65136d4d1a3a053f67529d069890238fcea21ff0 Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Fri, 1 Dec 2023 18:04:44 +0700 Subject: [PATCH 01/12] remove GetSigners from module transfer --- modules/apps/transfer/types/msgs.go | 21 +------------- modules/apps/transfer/types/msgs_test.go | 37 +++++++++++++----------- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/modules/apps/transfer/types/msgs.go b/modules/apps/transfer/types/msgs.go index ad126d149c7..2b045fee47e 100644 --- a/modules/apps/transfer/types/msgs.go +++ b/modules/apps/transfer/types/msgs.go @@ -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, @@ -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) @@ -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} -} diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index 6dc2dedc31a..37da96864f9 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -83,13 +83,13 @@ func TestMsgTransferValidation(t *testing.T) { } // TestMsgTransferGetSigners tests GetSigners for MsgTransfer -func TestMsgTransferGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestMsgTransferGetSigners() { 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) + signers, _, err := suite.chainA.GetSimApp().AppCodec().GetMsgV1Signers(msg) + suite.Require().NoError(err) + suite.Require().Equal(addr.Bytes(), signers[0]) } // TestMsgUpdateParamsValidateBasic tests ValidateBasic for MsgUpdateParams @@ -117,7 +117,7 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { } // TestMsgUpdateParamsGetSigners tests GetSigners for MsgUpdateParams -func TestMsgUpdateParamsGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { testCases := []struct { name string address sdk.AccAddress @@ -129,17 +129,20 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { for _, tc := range testCases { tc := tc - - msg := types.MsgUpdateParams{ - Signer: tc.address.String(), - Params: types.DefaultParams(), - } - if tc.expPass { - require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners()) - } else { - require.Panics(t, func() { - msg.GetSigners() - }) - } + suite.Run(tc.name, func () { + address := tc.address + msg := types.MsgUpdateParams{ + Signer: tc.address.String(), + Params: types.DefaultParams(), + } + signers, _, err := suite.chainA.GetSimApp().AppCodec().GetMsgV1Signers(&msg) + if tc.expPass { + suite.Require().NoError(err) + suite.Require().Equal(address.Bytes(), signers[0]) + } else { + suite.Require().Error(err) + } + }) + } } From 899948242efc03f5c800b48d3f5408c5e269eb1b Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Sat, 2 Dec 2023 22:04:41 +0700 Subject: [PATCH 02/12] remove GetSigners from module ica --- .../controller/types/msgs.go | 30 ----------- .../controller/types/msgs_test.go | 52 ++++++++++++------- .../27-interchain-accounts/host/types/msgs.go | 10 ---- .../host/types/msgs_test.go | 28 ++++++---- 4 files changed, 50 insertions(+), 70 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs.go b/modules/apps/27-interchain-accounts/controller/types/msgs.go index 213fcbfbc04..1afa45929cb 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs.go @@ -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{ @@ -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{ @@ -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} -} diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go index 541f3830fb6..df87a7678c2 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" + testifysuite "github.com/stretchr/testify/suite" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -17,6 +18,12 @@ import ( ibctesting "github.com/cosmos/ibc-go/v8/testing" ) +type TypesTestSuite struct { + testifysuite.Suite + + chainA *ibctesting.TestChain +} + func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) { var msg *types.MsgRegisterInterchainAccount @@ -93,12 +100,14 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) { } } -func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestMsgRegisterInterchainAccountGetSigners() { expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress) - require.NoError(t, err) + suite.Require().NoError(err) msg := types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") - require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners()) + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) + suite.Require().NoError(err) + suite.Require().Equal(expSigner.Bytes(), signers[0]) } func TestMsgSendTxValidateBasic(t *testing.T) { @@ -188,9 +197,9 @@ func TestMsgSendTxValidateBasic(t *testing.T) { } } -func TestMsgSendTxGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestMsgSendTxGetSigners() { expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress) - require.NoError(t, err) + suite.Require().NoError(err) msgBankSend := &banktypes.MsgSend{ FromAddress: ibctesting.TestAccAddress, @@ -201,7 +210,7 @@ func TestMsgSendTxGetSigners(t *testing.T) { encodingConfig := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) data, err := icatypes.SerializeCosmosTx(encodingConfig.Codec, []proto.Message{msgBankSend}, icatypes.EncodingProtobuf) - require.NoError(t, err) + suite.Require().NoError(err) packetData := icatypes.InterchainAccountPacketData{ Type: icatypes.EXECUTE_TX, @@ -214,7 +223,9 @@ func TestMsgSendTxGetSigners(t *testing.T) { 100000, packetData, ) - require.Equal(t, []sdk.AccAddress{expSigner}, msg.GetSigners()) + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) + suite.Require().NoError(err) + suite.Require().Equal(expSigner.Bytes(), signers[0]) } // TestMsgUpdateParamsValidateBasic tests ValidateBasic for MsgUpdateParams @@ -242,7 +253,7 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { } // TestMsgUpdateParamsGetSigners tests GetSigners for MsgUpdateParams -func TestMsgUpdateParamsGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress @@ -254,17 +265,18 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { for _, tc := range testCases { tc := tc - - msg := types.MsgUpdateParams{ - Signer: tc.address.String(), - Params: types.DefaultParams(), - } - if tc.expPass { - require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners()) - } else { - require.Panics(t, func() { - msg.GetSigners() - }) - } + suite.Run(tc.name, func() { + msg := types.MsgUpdateParams{ + Signer: tc.address.String(), + Params: types.DefaultParams(), + } + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(&msg) + if tc.expPass { + suite.Require().NoError(err) + suite.Require().Equal(tc.address.Bytes(), signers[0]) + } else { + suite.Require().Error(err) + } + }) } } diff --git a/modules/apps/27-interchain-accounts/host/types/msgs.go b/modules/apps/27-interchain-accounts/host/types/msgs.go index 845139a4a34..8b23b5040e1 100644 --- a/modules/apps/27-interchain-accounts/host/types/msgs.go +++ b/modules/apps/27-interchain-accounts/host/types/msgs.go @@ -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} -} diff --git a/modules/apps/27-interchain-accounts/host/types/msgs_test.go b/modules/apps/27-interchain-accounts/host/types/msgs_test.go index 1170f82b895..e7b8dd9bf0f 100644 --- a/modules/apps/27-interchain-accounts/host/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/host/types/msgs_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + testifysuite "github.com/stretchr/testify/suite" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,6 +12,12 @@ import ( ibctesting "github.com/cosmos/ibc-go/v8/testing" ) +type TypesTestSuite struct { + testifysuite.Suite + + chainA *ibctesting.TestChain +} + func TestMsgUpdateParamsValidateBasic(t *testing.T) { testCases := []struct { name string @@ -48,7 +55,7 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { } } -func TestMsgUpdateParamsGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { testCases := []struct { name string address sdk.AccAddress @@ -60,14 +67,15 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { for _, tc := range testCases { tc := tc - - msg := types.NewMsgUpdateParams(tc.address.String(), types.DefaultParams()) - if tc.expPass { - require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners()) - } else { - require.Panics(t, func() { - msg.GetSigners() - }) - } + suite.Run(tc.name, func() { + msg := types.NewMsgUpdateParams(tc.address.String(), types.DefaultParams()) + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) + if tc.expPass { + suite.Require().NoError(err) + suite.Require().Equal(tc.address.Bytes(), signers[0]) + } else { + suite.Require().Error(err) + } + }) } } From 5a4540153cbdfda777d2179db049d08388d0811e Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Sat, 2 Dec 2023 22:21:09 +0700 Subject: [PATCH 03/12] remove GetSigners from module fee --- modules/apps/29-fee/types/msgs.go | 39 -------------------------- modules/apps/29-fee/types/msgs_test.go | 32 ++++++++++++++------- 2 files changed, 22 insertions(+), 49 deletions(-) diff --git a/modules/apps/29-fee/types/msgs.go b/modules/apps/29-fee/types/msgs.go index af2a9287a65..be3a3c5f860 100644 --- a/modules/apps/29-fee/types/msgs.go +++ b/modules/apps/29-fee/types/msgs.go @@ -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{ @@ -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{ @@ -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{ @@ -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} -} diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index 6f1d2bce4eb..9ea9ffa8e7f 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + testifysuite "github.com/stretchr/testify/suite" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,6 +15,11 @@ import ( ibctesting "github.com/cosmos/ibc-go/v8/testing" ) +type TypesTestSuite struct { + testifysuite.Suite + + chainA *ibctesting.TestChain +} func TestMsgRegisterPayeeValidation(t *testing.T) { var msg *types.MsgRegisterPayee @@ -85,10 +91,12 @@ func TestMsgRegisterPayeeValidation(t *testing.T) { } } -func TestRegisterPayeeGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestRegisterPayeeGetSigners() { 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()) + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) + suite.Require().NoError(err) + suite.Require().Equal(accAddress.Bytes(), signers[0]) } func TestMsgRegisterCountepartyPayeeValidation(t *testing.T) { @@ -165,10 +173,12 @@ func TestMsgRegisterCountepartyPayeeValidation(t *testing.T) { } } -func TestRegisterCountepartyAddressGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestRegisterCountepartyAddressGetSigners() { 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()) + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) + suite.Require().NoError(err) + suite.Require().Equal(accAddress.Bytes(), signers[0]) } func TestMsgPayPacketFeeValidation(t *testing.T) { @@ -239,12 +249,13 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { } } -func TestPayPacketFeeGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestPayPacketFeeGetSigners() { refundAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) 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()) + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) + suite.Require().NoError(err) + suite.Require().Equal(refundAddr.Bytes(), signers[0]) } func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { @@ -373,13 +384,14 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { } } -func TestPayPacketFeeAsyncGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestPayPacketFeeAsyncGetSigners() { refundAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) 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()) + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) + suite.Require().NoError(err) + suite.Require().Equal(refundAddr.Bytes(), signers[0]) } From 2d0b06eec5cc9852dd28ae3c15d963ce33992258 Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Mon, 4 Dec 2023 16:15:02 +0700 Subject: [PATCH 04/12] remove GetSigners from module 02-client --- modules/core/02-client/types/msgs.go | 63 ----------------------- modules/core/02-client/types/msgs_test.go | 30 ++++++----- 2 files changed, 16 insertions(+), 77 deletions(-) diff --git a/modules/core/02-client/types/msgs.go b/modules/core/02-client/types/msgs.go index 1eb5472ca87..77aee0828ee 100644 --- a/modules/core/02-client/types/msgs.go +++ b/modules/core/02-client/types/msgs.go @@ -83,15 +83,6 @@ func (msg MsgCreateClient) ValidateBasic() error { return consensusState.ValidateBasic() } -// GetSigners implements sdk.Msg -func (msg MsgCreateClient) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (msg MsgCreateClient) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { var clientState exported.ClientState @@ -134,15 +125,6 @@ func (msg MsgUpdateClient) ValidateBasic() error { return host.ClientIdentifierValidator(msg.ClientId) } -// GetSigners implements sdk.Msg -func (msg MsgUpdateClient) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (msg MsgUpdateClient) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { var clientMsg exported.ClientMessage @@ -204,15 +186,6 @@ func (msg MsgUpgradeClient) ValidateBasic() error { return host.ClientIdentifierValidator(msg.ClientId) } -// GetSigners implements sdk.Msg -func (msg MsgUpgradeClient) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (msg MsgUpgradeClient) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { var ( @@ -256,15 +229,6 @@ func (msg MsgSubmitMisbehaviour) ValidateBasic() error { return host.ClientIdentifierValidator(msg.ClientId) } -// GetSigners returns the single expected signer for a MsgSubmitMisbehaviour. -func (msg MsgSubmitMisbehaviour) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (msg MsgSubmitMisbehaviour) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { var misbehaviour exported.ClientMessage @@ -301,15 +265,6 @@ func (msg *MsgRecoverClient) ValidateBasic() error { return nil } -// GetSigners returns the expected signers for a MsgRecoverClient message. -func (msg *MsgRecoverClient) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // NewMsgIBCSoftwareUpgrade creates a new MsgIBCSoftwareUpgrade instance func NewMsgIBCSoftwareUpgrade(signer string, plan upgradetypes.Plan, upgradedClientState exported.ClientState) (*MsgIBCSoftwareUpgrade, error) { anyClient, err := PackClientState(upgradedClientState) @@ -343,15 +298,6 @@ func (msg *MsgIBCSoftwareUpgrade) ValidateBasic() error { return msg.Plan.ValidateBasic() } -// GetSigners returns the expected signers for a MsgIBCSoftwareUpgrade message. -func (msg *MsgIBCSoftwareUpgrade) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (msg *MsgIBCSoftwareUpgrade) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { return unpacker.UnpackAny(msg.UpgradedClientState, new(exported.ClientState)) @@ -365,15 +311,6 @@ func NewMsgUpdateParams(signer string, params Params) *MsgUpdateParams { } } -// GetSigners returns the expected signers for a MsgUpdateParams message. -func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // ValidateBasic performs basic checks on a MsgUpdateParams. func (msg *MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { diff --git a/modules/core/02-client/types/msgs_test.go b/modules/core/02-client/types/msgs_test.go index f051492780c..498b3f11d58 100644 --- a/modules/core/02-client/types/msgs_test.go +++ b/modules/core/02-client/types/msgs_test.go @@ -6,7 +6,6 @@ import ( "time" "github.com/golang/protobuf/proto" //nolint:staticcheck - "github.com/stretchr/testify/require" testifysuite "github.com/stretchr/testify/suite" upgradetypes "cosmossdk.io/x/upgrade/types" @@ -686,7 +685,7 @@ func (suite *TypesTestSuite) TestMsgRecoverClientValidateBasic() { } // TestMsgRecoverClientGetSigners tests GetSigners for MsgRecoverClient -func TestMsgRecoverClientGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestMsgRecoverClientGetSigners() { testCases := []struct { name string address sdk.AccAddress @@ -701,12 +700,12 @@ func TestMsgRecoverClientGetSigners(t *testing.T) { msg := types.MsgRecoverClient{ Signer: tc.address.String(), } + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(&msg) if tc.expPass { - require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners()) + suite.Require().NoError(err) + suite.Require().Equal(tc.address.Bytes(), signers[0]) } else { - require.Panics(t, func() { - msg.GetSigners() - }) + suite.Require().Error(err) } } } @@ -786,10 +785,12 @@ func (suite *TypesTestSuite) TestMsgIBCSoftwareUpgrade_GetSigners() { ) suite.Require().NoError(err) + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) if tc.expPass { - suite.Require().Equal([]sdk.AccAddress{tc.address}, msg.GetSigners()) + suite.Require().NoError(err) + suite.Require().Equal(tc.address.Bytes(), signers[0]) } else { - suite.Require().Panics(func() { msg.GetSigners() }) + suite.Require().Error(err) } } } @@ -937,7 +938,7 @@ func (suite *TypesTestSuite) TestMsgUpdateParamsValidateBasic() { } // TestMsgUpdateParamsGetSigners tests GetSigners for MsgUpdateParams -func TestMsgUpdateParamsGetSigners(t *testing.T) { +func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { testCases := []struct { name string address sdk.AccAddress @@ -949,17 +950,18 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { for _, tc := range testCases { tc := tc - t.Run(tc.name, func(t *testing.T) { + suite.T().Run(tc.name, func(t *testing.T) { msg := types.MsgUpdateParams{ Signer: tc.address.String(), Params: types.DefaultParams(), } + + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(&msg) if tc.expPass { - require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners()) + suite.Require().NoError(err) + suite.Require().Equal(tc.address.Bytes(), signers[0]) } else { - require.Panics(t, func() { - msg.GetSigners() - }) + suite.Require().Error(err) } }) } From 796a69ee4dbbc6cc732d197560a96e90e5d354be Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Mon, 4 Dec 2023 16:18:07 +0700 Subject: [PATCH 05/12] remove GetSigners from module 03-connection --- modules/core/03-connection/types/msgs.go | 45 ------------------- modules/core/03-connection/types/msgs_test.go | 12 ++--- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/modules/core/03-connection/types/msgs.go b/modules/core/03-connection/types/msgs.go index c46c783767e..cac392c49ee 100644 --- a/modules/core/03-connection/types/msgs.go +++ b/modules/core/03-connection/types/msgs.go @@ -74,15 +74,6 @@ func (msg MsgConnectionOpenInit) ValidateBasic() error { return msg.Counterparty.ValidateBasic() } -// GetSigners implements sdk.Msg -func (msg MsgConnectionOpenInit) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // NewMsgConnectionOpenTry creates a new MsgConnectionOpenTry instance func NewMsgConnectionOpenTry( clientID, counterpartyConnectionID, counterpartyClientID string, @@ -167,15 +158,6 @@ func (msg MsgConnectionOpenTry) UnpackInterfaces(unpacker codectypes.AnyUnpacker return unpacker.UnpackAny(msg.ClientState, new(exported.ClientState)) } -// GetSigners implements sdk.Msg -func (msg MsgConnectionOpenTry) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // NewMsgConnectionOpenAck creates a new MsgConnectionOpenAck instance func NewMsgConnectionOpenAck( connectionID, counterpartyConnectionID string, counterpartyClient exported.ClientState, @@ -244,15 +226,6 @@ func (msg MsgConnectionOpenAck) ValidateBasic() error { return nil } -// GetSigners implements sdk.Msg -func (msg MsgConnectionOpenAck) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // NewMsgConnectionOpenConfirm creates a new MsgConnectionOpenConfirm instance func NewMsgConnectionOpenConfirm( connectionID string, proofAck []byte, proofHeight clienttypes.Height, @@ -281,15 +254,6 @@ func (msg MsgConnectionOpenConfirm) ValidateBasic() error { return nil } -// GetSigners implements sdk.Msg -func (msg MsgConnectionOpenConfirm) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // NewMsgUpdateParams creates a new MsgUpdateParams instance func NewMsgUpdateParams(signer string, params Params) *MsgUpdateParams { return &MsgUpdateParams{ @@ -298,15 +262,6 @@ func NewMsgUpdateParams(signer string, params Params) *MsgUpdateParams { } } -// GetSigners returns the expected signers for a MsgUpdateParams message. -func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { - accAddr, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{accAddr} -} - // ValidateBasic performs basic checks on a MsgUpdateParams. func (msg *MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil { diff --git a/modules/core/03-connection/types/msgs_test.go b/modules/core/03-connection/types/msgs_test.go index ba26c117c0e..f264d904227 100644 --- a/modules/core/03-connection/types/msgs_test.go +++ b/modules/core/03-connection/types/msgs_test.go @@ -6,7 +6,6 @@ import ( "time" dbm "github.com/cosmos/cosmos-db" - "github.com/stretchr/testify/require" testifysuite "github.com/stretchr/testify/suite" log "cosmossdk.io/log" @@ -282,7 +281,7 @@ func (suite *MsgTestSuite) TestMsgUpdateParamsValidateBasic() { } // TestMsgUpdateParamsGetSigners tests GetSigners for MsgUpdateParams -func TestMsgUpdateParamsGetSigners(t *testing.T) { +func (suite *MsgTestSuite) TestMsgUpdateParamsGetSigners() { testCases := []struct { name string address sdk.AccAddress @@ -299,12 +298,13 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { Signer: tc.address.String(), Params: types.DefaultParams(), } + + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(&msg) if tc.expPass { - require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners()) + suite.Require().NoError(err) + suite.Require().Equal(tc.address.Bytes(), signers[0]) } else { - require.Panics(t, func() { - msg.GetSigners() - }) + suite.Require().Error(err) } } } From 8783849524e6b0c54cefe4d0fe6914de116e7122 Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Tue, 5 Dec 2023 01:24:37 +0700 Subject: [PATCH 06/12] remove GetSigners from module 04-channel --- modules/core/04-channel/types/msgs.go | 90 ---------------------- modules/core/04-channel/types/msgs_test.go | 18 +++-- 2 files changed, 12 insertions(+), 96 deletions(-) diff --git a/modules/core/04-channel/types/msgs.go b/modules/core/04-channel/types/msgs.go index 812829307c0..02f6c43777b 100644 --- a/modules/core/04-channel/types/msgs.go +++ b/modules/core/04-channel/types/msgs.go @@ -73,15 +73,6 @@ func (msg MsgChannelOpenInit) ValidateBasic() error { return msg.Channel.ValidateBasic() } -// GetSigners implements sdk.Msg -func (msg MsgChannelOpenInit) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{signer} -} - // NewMsgChannelOpenTry creates a new MsgChannelOpenTry instance // The version string is deprecated and will be ignored by core IBC. // It is left as an argument for go API backwards compatibility. @@ -131,15 +122,6 @@ func (msg MsgChannelOpenTry) ValidateBasic() error { return msg.Channel.ValidateBasic() } -// GetSigners implements sdk.Msg -func (msg MsgChannelOpenTry) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{signer} -} - // NewMsgChannelOpenAck creates a new MsgChannelOpenAck instance func NewMsgChannelOpenAck( portID, channelID, counterpartyChannelID string, cpv string, proofTry []byte, proofHeight clienttypes.Height, @@ -177,15 +159,6 @@ func (msg MsgChannelOpenAck) ValidateBasic() error { return nil } -// GetSigners implements sdk.Msg -func (msg MsgChannelOpenAck) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{signer} -} - // NewMsgChannelOpenConfirm creates a new MsgChannelOpenConfirm instance func NewMsgChannelOpenConfirm( portID, channelID string, proofAck []byte, proofHeight clienttypes.Height, @@ -218,15 +191,6 @@ func (msg MsgChannelOpenConfirm) ValidateBasic() error { return nil } -// GetSigners implements sdk.Msg -func (msg MsgChannelOpenConfirm) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{signer} -} - // NewMsgChannelCloseInit creates a new MsgChannelCloseInit instance func NewMsgChannelCloseInit( portID string, channelID string, signer string, @@ -253,15 +217,6 @@ func (msg MsgChannelCloseInit) ValidateBasic() error { return nil } -// GetSigners implements sdk.Msg -func (msg MsgChannelCloseInit) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{signer} -} - // NewMsgChannelCloseConfirm creates a new MsgChannelCloseConfirm instance func NewMsgChannelCloseConfirm( portID, channelID string, proofInit []byte, proofHeight clienttypes.Height, @@ -294,15 +249,6 @@ func (msg MsgChannelCloseConfirm) ValidateBasic() error { return nil } -// GetSigners implements sdk.Msg -func (msg MsgChannelCloseConfirm) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{signer} -} - // NewMsgRecvPacket constructs new MsgRecvPacket func NewMsgRecvPacket( packet Packet, proofCommitment []byte, proofHeight clienttypes.Height, @@ -335,15 +281,6 @@ func (msg MsgRecvPacket) GetDataSignBytes() []byte { return []byte(s) } -// GetSigners implements sdk.Msg -func (msg MsgRecvPacket) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{signer} -} - // NewMsgTimeout constructs new MsgTimeout func NewMsgTimeout( packet Packet, nextSequenceRecv uint64, proofUnreceived []byte, @@ -373,15 +310,6 @@ func (msg MsgTimeout) ValidateBasic() error { return msg.Packet.ValidateBasic() } -// GetSigners implements sdk.Msg -func (msg MsgTimeout) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{signer} -} - // NewMsgTimeoutOnClose constructs new MsgTimeoutOnClose func NewMsgTimeoutOnClose( packet Packet, nextSequenceRecv uint64, @@ -416,15 +344,6 @@ func (msg MsgTimeoutOnClose) ValidateBasic() error { return msg.Packet.ValidateBasic() } -// GetSigners implements sdk.Msg -func (msg MsgTimeoutOnClose) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{signer} -} - // NewMsgAcknowledgement constructs a new MsgAcknowledgement func NewMsgAcknowledgement( packet Packet, @@ -455,12 +374,3 @@ func (msg MsgAcknowledgement) ValidateBasic() error { } return msg.Packet.ValidateBasic() } - -// GetSigners implements sdk.Msg -func (msg MsgAcknowledgement) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(msg.Signer) - if err != nil { - panic(err) - } - return []sdk.AccAddress{signer} -} diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 8570ad59065..150bfd635ae 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -18,6 +18,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + ibctesting "github.com/cosmos/ibc-go/v8/testing" "github.com/cosmos/ibc-go/v8/testing/simapp" ) @@ -71,15 +72,19 @@ var ( type TypesTestSuite struct { testifysuite.Suite - proof []byte + coordinator *ibctesting.Coordinator + chainA *ibctesting.TestChain + proof []byte } func (suite *TypesTestSuite) SetupTest() { + suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) + suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) + app := simapp.Setup(suite.T(), false) db := dbm.NewMemDB() store := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) storeKey := storetypes.NewKVStoreKey("iavlStoreKey") - store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil) err := store.LoadVersion(0) suite.Require().NoError(err) @@ -339,11 +344,12 @@ func (suite *TypesTestSuite) TestMsgRecvPacketValidateBasic() { } func (suite *TypesTestSuite) TestMsgRecvPacketGetSigners() { - msg := types.NewMsgRecvPacket(packet, suite.proof, height, addr) - res := msg.GetSigners() + signer := sdk.AccAddress(ibctesting.TestAccAddress) + msg := types.NewMsgRecvPacket(packet, suite.proof, height, signer.String()) + signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) - expected := "[7465737461646472313131313131313131313131]" - suite.Equal(expected, fmt.Sprintf("%v", res)) + suite.Require().NoError(err) + suite.Require().Equal(signer.Bytes(), signers[0]) } func (suite *TypesTestSuite) TestMsgTimeoutValidateBasic() { From 34728b7e5fa53cfc2bfed5a35a0f4938f2f87a40 Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Tue, 5 Dec 2023 01:47:18 +0700 Subject: [PATCH 07/12] lint --- modules/apps/29-fee/types/msgs_test.go | 1 + modules/apps/transfer/types/msgs_test.go | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index 9ea9ffa8e7f..e6674838fd6 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -20,6 +20,7 @@ type TypesTestSuite struct { chainA *ibctesting.TestChain } + func TestMsgRegisterPayeeValidation(t *testing.T) { var msg *types.MsgRegisterPayee diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index 37da96864f9..540111360da 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -87,7 +87,7 @@ func (suite *TypesTestSuite) TestMsgTransferGetSigners() { addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) msg := types.NewMsgTransfer(validPort, validChannel, coin, addr.String(), receiver, timeoutHeight, 0, "") - signers, _, err := suite.chainA.GetSimApp().AppCodec().GetMsgV1Signers(msg) + signers, _, err := suite.chainA.GetSimApp().AppCodec().GetMsgV1Signers(msg) suite.Require().NoError(err) suite.Require().Equal(addr.Bytes(), signers[0]) } @@ -129,7 +129,7 @@ func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { for _, tc := range testCases { tc := tc - suite.Run(tc.name, func () { + suite.Run(tc.name, func() { address := tc.address msg := types.MsgUpdateParams{ Signer: tc.address.String(), @@ -143,6 +143,5 @@ func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { suite.Require().Error(err) } }) - } } From ad67aee70f9f6c2bc16acfcc517062d1d61d33e3 Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Wed, 6 Dec 2023 16:46:31 +0700 Subject: [PATCH 08/12] update with damiannolan's suggestion --- .../controller/types/msgs_test.go | 60 +++++++++---------- .../host/types/msgs_test.go | 31 ++++------ modules/apps/29-fee/types/msgs_test.go | 50 ++++++++-------- modules/core/04-channel/types/msgs_test.go | 14 ++--- 4 files changed, 74 insertions(+), 81 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go index df87a7678c2..17bf0d98e0c 100644 --- a/modules/apps/27-interchain-accounts/controller/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/controller/types/msgs_test.go @@ -5,7 +5,6 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" - testifysuite "github.com/stretchr/testify/suite" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -18,12 +17,6 @@ import ( ibctesting "github.com/cosmos/ibc-go/v8/testing" ) -type TypesTestSuite struct { - testifysuite.Suite - - chainA *ibctesting.TestChain -} - func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) { var msg *types.MsgRegisterInterchainAccount @@ -100,14 +93,15 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) { } } -func (suite *TypesTestSuite) TestMsgRegisterInterchainAccountGetSigners() { +func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) { expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress) - suite.Require().NoError(err) + require.NoError(t, err) msg := types.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, ibctesting.TestAccAddress, "") - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) - suite.Require().NoError(err) - suite.Require().Equal(expSigner.Bytes(), signers[0]) + 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) { @@ -197,9 +191,9 @@ func TestMsgSendTxValidateBasic(t *testing.T) { } } -func (suite *TypesTestSuite) TestMsgSendTxGetSigners() { +func TestMsgSendTxGetSigners(t *testing.T) { expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress) - suite.Require().NoError(err) + require.NoError(t, err) msgBankSend := &banktypes.MsgSend{ FromAddress: ibctesting.TestAccAddress, @@ -210,7 +204,7 @@ func (suite *TypesTestSuite) TestMsgSendTxGetSigners() { encodingConfig := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) data, err := icatypes.SerializeCosmosTx(encodingConfig.Codec, []proto.Message{msgBankSend}, icatypes.EncodingProtobuf) - suite.Require().NoError(err) + require.NoError(t, err) packetData := icatypes.InterchainAccountPacketData{ Type: icatypes.EXECUTE_TX, @@ -223,9 +217,9 @@ func (suite *TypesTestSuite) TestMsgSendTxGetSigners() { 100000, packetData, ) - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) - suite.Require().NoError(err) - suite.Require().Equal(expSigner.Bytes(), signers[0]) + signers, _, err := encodingConfig.Codec.GetMsgV1Signers(msg) + require.NoError(t, err) + require.Equal(t, expSigner.Bytes(), signers[0]) } // TestMsgUpdateParamsValidateBasic tests ValidateBasic for MsgUpdateParams @@ -253,7 +247,7 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { } // TestMsgUpdateParamsGetSigners tests GetSigners for MsgUpdateParams -func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners(t *testing.T) { +func TestMsgUpdateParamsGetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress @@ -265,18 +259,20 @@ func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners(t *testing.T) { for _, tc := range testCases { tc := tc - suite.Run(tc.name, func() { - msg := types.MsgUpdateParams{ - Signer: tc.address.String(), - Params: types.DefaultParams(), - } - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(&msg) - if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(tc.address.Bytes(), signers[0]) - } else { - suite.Require().Error(err) - } - }) + + msg := types.MsgUpdateParams{ + Signer: tc.address.String(), + Params: types.DefaultParams(), + } + + encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) + signers, _, err := encodingCfg.Codec.GetMsgV1Signers(&msg) + if tc.expPass { + require.NoError(t, err) + require.Equal(t, tc.address.Bytes(), signers[0]) + } else { + require.Error(t, err) + } + } } diff --git a/modules/apps/27-interchain-accounts/host/types/msgs_test.go b/modules/apps/27-interchain-accounts/host/types/msgs_test.go index e7b8dd9bf0f..b9d1d96e2bc 100644 --- a/modules/apps/27-interchain-accounts/host/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/host/types/msgs_test.go @@ -4,20 +4,15 @@ import ( "testing" "github.com/stretchr/testify/require" - testifysuite "github.com/stretchr/testify/suite" 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" ) -type TypesTestSuite struct { - testifysuite.Suite - - chainA *ibctesting.TestChain -} - func TestMsgUpdateParamsValidateBasic(t *testing.T) { testCases := []struct { name string @@ -55,7 +50,7 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { } } -func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { +func TestMsgUpdateParamsGetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress @@ -67,15 +62,15 @@ func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { for _, tc := range testCases { tc := tc - suite.Run(tc.name, func() { - msg := types.NewMsgUpdateParams(tc.address.String(), types.DefaultParams()) - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) - if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(tc.address.Bytes(), signers[0]) - } else { - suite.Require().Error(err) - } - }) + + msg := types.NewMsgUpdateParams(tc.address.String(), types.DefaultParams()) + encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) + signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) + if tc.expPass { + require.NoError(t, err) + require.Equal(t, tc.address.Bytes(), signers[0]) + } else { + require.Error(t, err) + } } } diff --git a/modules/apps/29-fee/types/msgs_test.go b/modules/apps/29-fee/types/msgs_test.go index e6674838fd6..68195180ba0 100644 --- a/modules/apps/29-fee/types/msgs_test.go +++ b/modules/apps/29-fee/types/msgs_test.go @@ -4,23 +4,18 @@ import ( "testing" "github.com/stretchr/testify/require" - testifysuite "github.com/stretchr/testify/suite" 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" ) -type TypesTestSuite struct { - testifysuite.Suite - - chainA *ibctesting.TestChain -} - func TestMsgRegisterPayeeValidation(t *testing.T) { var msg *types.MsgRegisterPayee @@ -92,12 +87,14 @@ func TestMsgRegisterPayeeValidation(t *testing.T) { } } -func (suite *TypesTestSuite) TestRegisterPayeeGetSigners() { +func TestRegisterPayeeGetSigners(t *testing.T) { accAddress := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) msg := types.NewMsgRegisterPayee(ibctesting.MockPort, ibctesting.FirstChannelID, accAddress.String(), defaultAccAddress) - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) - suite.Require().NoError(err) - suite.Require().Equal(accAddress.Bytes(), signers[0]) + + 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) { @@ -174,12 +171,14 @@ func TestMsgRegisterCountepartyPayeeValidation(t *testing.T) { } } -func (suite *TypesTestSuite) TestRegisterCountepartyAddressGetSigners() { +func TestRegisterCountepartyAddressGetSigners(t *testing.T) { accAddress := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) msg := types.NewMsgRegisterCounterpartyPayee(ibctesting.MockPort, ibctesting.FirstChannelID, accAddress.String(), defaultAccAddress) - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) - suite.Require().NoError(err) - suite.Require().Equal(accAddress.Bytes(), signers[0]) + + 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) { @@ -250,13 +249,15 @@ func TestMsgPayPacketFeeValidation(t *testing.T) { } } -func (suite *TypesTestSuite) TestPayPacketFeeGetSigners() { +func TestPayPacketFeeGetSigners(t *testing.T) { refundAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee) msg := types.NewMsgPayPacketFee(fee, ibctesting.MockFeePort, ibctesting.FirstChannelID, refundAddr.String(), nil) - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) - suite.Require().NoError(err) - suite.Require().Equal(refundAddr.Bytes(), signers[0]) + + 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) { @@ -385,14 +386,15 @@ func TestMsgPayPacketFeeAsyncValidation(t *testing.T) { } } -func (suite *TypesTestSuite) TestPayPacketFeeAsyncGetSigners() { +func TestPayPacketFeeAsyncGetSigners(t *testing.T) { refundAddr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) 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) - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) - suite.Require().NoError(err) - suite.Require().Equal(refundAddr.Bytes(), signers[0]) + + encodingCfg := moduletestutil.MakeTestEncodingConfig(modulefee.AppModuleBasic{}) + signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) + require.NoError(t, err) + require.Equal(t, refundAddr.Bytes(), signers[0]) } diff --git a/modules/core/04-channel/types/msgs_test.go b/modules/core/04-channel/types/msgs_test.go index 150bfd635ae..e5c027120bb 100644 --- a/modules/core/04-channel/types/msgs_test.go +++ b/modules/core/04-channel/types/msgs_test.go @@ -14,7 +14,9 @@ import ( storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + ibc "github.com/cosmos/ibc-go/v8/modules/core" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" @@ -72,19 +74,15 @@ var ( type TypesTestSuite struct { testifysuite.Suite - coordinator *ibctesting.Coordinator - chainA *ibctesting.TestChain - proof []byte + proof []byte } func (suite *TypesTestSuite) SetupTest() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - app := simapp.Setup(suite.T(), false) db := dbm.NewMemDB() store := rootmulti.NewStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) storeKey := storetypes.NewKVStoreKey("iavlStoreKey") + store.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, nil) err := store.LoadVersion(0) suite.Require().NoError(err) @@ -346,7 +344,9 @@ func (suite *TypesTestSuite) TestMsgRecvPacketValidateBasic() { func (suite *TypesTestSuite) TestMsgRecvPacketGetSigners() { signer := sdk.AccAddress(ibctesting.TestAccAddress) msg := types.NewMsgRecvPacket(packet, suite.proof, height, signer.String()) - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) + + encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{}) + signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) suite.Require().NoError(err) suite.Require().Equal(signer.Bytes(), signers[0]) From 7d5f942f06b448cd1f1dacf45a4a2a594dca9f8f Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Wed, 6 Dec 2023 17:54:53 +0700 Subject: [PATCH 09/12] update with damiannolan's suggestion --- e2e/tests/wasm/grandpa_test.go | 4 +- modules/apps/transfer/types/msgs_test.go | 13 +++--- modules/core/02-client/types/msgs_test.go | 43 +++++++++++-------- modules/core/03-connection/types/msgs_test.go | 16 ++++--- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/e2e/tests/wasm/grandpa_test.go b/e2e/tests/wasm/grandpa_test.go index 6aa250b1885..a35ae853638 100644 --- a/e2e/tests/wasm/grandpa_test.go +++ b/e2e/tests/wasm/grandpa_test.go @@ -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" diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index 540111360da..eae9277a7c5 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -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" @@ -83,13 +85,14 @@ func TestMsgTransferValidation(t *testing.T) { } // TestMsgTransferGetSigners tests GetSigners for MsgTransfer -func (suite *TypesTestSuite) TestMsgTransferGetSigners() { +func TestMsgTransferGetSigners(t *testing.T) { addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - msg := types.NewMsgTransfer(validPort, validChannel, coin, addr.String(), receiver, timeoutHeight, 0, "") - signers, _, err := suite.chainA.GetSimApp().AppCodec().GetMsgV1Signers(msg) - suite.Require().NoError(err) - suite.Require().Equal(addr.Bytes(), signers[0]) + + 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 diff --git a/modules/core/02-client/types/msgs_test.go b/modules/core/02-client/types/msgs_test.go index 498b3f11d58..5c42cc304bf 100644 --- a/modules/core/02-client/types/msgs_test.go +++ b/modules/core/02-client/types/msgs_test.go @@ -6,6 +6,9 @@ import ( "time" "github.com/golang/protobuf/proto" //nolint:staticcheck + + "github.com/golang/protobuf/proto" //nolint:staticcheck + "github.com/stretchr/testify/require" testifysuite "github.com/stretchr/testify/suite" upgradetypes "cosmossdk.io/x/upgrade/types" @@ -13,7 +16,9 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + ibc "github.com/cosmos/ibc-go/v8/modules/core" "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" @@ -685,7 +690,7 @@ func (suite *TypesTestSuite) TestMsgRecoverClientValidateBasic() { } // TestMsgRecoverClientGetSigners tests GetSigners for MsgRecoverClient -func (suite *TypesTestSuite) TestMsgRecoverClientGetSigners() { +func TestMsgRecoverClientGetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress @@ -700,12 +705,13 @@ func (suite *TypesTestSuite) TestMsgRecoverClientGetSigners() { msg := types.MsgRecoverClient{ Signer: tc.address.String(), } - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(&msg) + encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{}) + signers, _, err := encodingCfg.Codec.GetMsgV1Signers(&msg) if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(tc.address.Bytes(), signers[0]) + require.NoError(t, err) + require.Equal(t, tc.address.Bytes(), signers[0]) } else { - suite.Require().Error(err) + require.Error(t, err) } } } @@ -938,7 +944,7 @@ func (suite *TypesTestSuite) TestMsgUpdateParamsValidateBasic() { } // TestMsgUpdateParamsGetSigners tests GetSigners for MsgUpdateParams -func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { +func TestMsgUpdateParamsGetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress @@ -950,19 +956,18 @@ func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { for _, tc := range testCases { tc := tc - suite.T().Run(tc.name, func(t *testing.T) { - msg := types.MsgUpdateParams{ - Signer: tc.address.String(), - Params: types.DefaultParams(), - } - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(&msg) - if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(tc.address.Bytes(), signers[0]) - } else { - suite.Require().Error(err) - } - }) + msg := types.MsgUpdateParams{ + Signer: tc.address.String(), + Params: types.DefaultParams(), + } + encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{}) + signers, _, err := encodingCfg.Codec.GetMsgV1Signers(&msg) + if tc.expPass { + require.NoError(t, err) + require.Equal(t, tc.address.Bytes(), signers[0]) + } else { + require.Error(t, err) + } } } diff --git a/modules/core/03-connection/types/msgs_test.go b/modules/core/03-connection/types/msgs_test.go index f264d904227..c3d01c0e0b6 100644 --- a/modules/core/03-connection/types/msgs_test.go +++ b/modules/core/03-connection/types/msgs_test.go @@ -6,6 +6,9 @@ import ( "time" dbm "github.com/cosmos/cosmos-db" + + dbm "github.com/cosmos/cosmos-db" + "github.com/stretchr/testify/require" testifysuite "github.com/stretchr/testify/suite" log "cosmossdk.io/log" @@ -15,7 +18,9 @@ import ( storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + ibc "github.com/cosmos/ibc-go/v8/modules/core" clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" @@ -281,7 +286,7 @@ func (suite *MsgTestSuite) TestMsgUpdateParamsValidateBasic() { } // TestMsgUpdateParamsGetSigners tests GetSigners for MsgUpdateParams -func (suite *MsgTestSuite) TestMsgUpdateParamsGetSigners() { +func TestMsgUpdateParamsGetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress @@ -299,12 +304,13 @@ func (suite *MsgTestSuite) TestMsgUpdateParamsGetSigners() { Params: types.DefaultParams(), } - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(&msg) + encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{}) + signers, _, err := encodingCfg.Codec.GetMsgV1Signers(&msg) if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(tc.address.Bytes(), signers[0]) + require.NoError(t, err) + require.Equal(t, tc.address.Bytes(), signers[0]) } else { - suite.Require().Error(err) + require.Error(t, err) } } } From c736274885626644ab13f447568b40040bfd69c1 Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Wed, 6 Dec 2023 17:59:27 +0700 Subject: [PATCH 10/12] lint --- modules/core/02-client/types/msgs_test.go | 2 -- modules/core/03-connection/types/msgs_test.go | 2 -- 2 files changed, 4 deletions(-) diff --git a/modules/core/02-client/types/msgs_test.go b/modules/core/02-client/types/msgs_test.go index 5c42cc304bf..db4be87a315 100644 --- a/modules/core/02-client/types/msgs_test.go +++ b/modules/core/02-client/types/msgs_test.go @@ -5,8 +5,6 @@ import ( "testing" "time" - "github.com/golang/protobuf/proto" //nolint:staticcheck - "github.com/golang/protobuf/proto" //nolint:staticcheck "github.com/stretchr/testify/require" testifysuite "github.com/stretchr/testify/suite" diff --git a/modules/core/03-connection/types/msgs_test.go b/modules/core/03-connection/types/msgs_test.go index c3d01c0e0b6..b125baa6e56 100644 --- a/modules/core/03-connection/types/msgs_test.go +++ b/modules/core/03-connection/types/msgs_test.go @@ -5,8 +5,6 @@ import ( "testing" "time" - dbm "github.com/cosmos/cosmos-db" - dbm "github.com/cosmos/cosmos-db" "github.com/stretchr/testify/require" testifysuite "github.com/stretchr/testify/suite" From 9dfff4172aa8f5791bfefb50ada12428d0523f8a Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Wed, 6 Dec 2023 18:08:50 +0700 Subject: [PATCH 11/12] remove suite --- modules/apps/transfer/types/msgs_test.go | 31 ++++++++++++----------- modules/core/02-client/types/msgs_test.go | 15 ++++++----- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index eae9277a7c5..50fc84f9f41 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -120,7 +120,7 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { } // TestMsgUpdateParamsGetSigners tests GetSigners for MsgUpdateParams -func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { +func TestMsgUpdateParamsGetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress @@ -132,19 +132,20 @@ func (suite *TypesTestSuite) TestMsgUpdateParamsGetSigners() { for _, tc := range testCases { tc := tc - suite.Run(tc.name, func() { - address := tc.address - msg := types.MsgUpdateParams{ - Signer: tc.address.String(), - Params: types.DefaultParams(), - } - signers, _, err := suite.chainA.GetSimApp().AppCodec().GetMsgV1Signers(&msg) - if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(address.Bytes(), signers[0]) - } else { - suite.Require().Error(err) - } - }) + + address := tc.address + msg := types.MsgUpdateParams{ + Signer: tc.address.String(), + Params: types.DefaultParams(), + } + + encodingCfg := moduletestutil.MakeTestEncodingConfig(transfer.AppModuleBasic{}) + signers, _, err := encodingCfg.Codec.GetMsgV1Signers(&msg) + if tc.expPass { + require.NoError(t, err) + require.Equal(t, address.Bytes(), signers[0]) + } else { + require.Error(t, err) + } } } diff --git a/modules/core/02-client/types/msgs_test.go b/modules/core/02-client/types/msgs_test.go index db4be87a315..ccbd90e3ead 100644 --- a/modules/core/02-client/types/msgs_test.go +++ b/modules/core/02-client/types/msgs_test.go @@ -758,7 +758,7 @@ func (suite *TypesTestSuite) TestMsgIBCSoftwareUpgrade_NewMsgIBCSoftwareUpgrade( } // TestMsgIBCSoftwareUpgrade_GetSigners tests GetSigners for MsgIBCSoftwareUpgrade -func (suite *TypesTestSuite) TestMsgIBCSoftwareUpgrade_GetSigners() { +func TestMsgIBCSoftwareUpgrade_GetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress @@ -777,7 +777,7 @@ func (suite *TypesTestSuite) TestMsgIBCSoftwareUpgrade_GetSigners() { } for _, tc := range testCases { - clientState := ibctm.NewClientState(suite.chainA.ChainID, ibctesting.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) + clientState := ibctm.NewClientState("testchain1-1", ibctesting.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clientHeight, commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) plan := upgradetypes.Plan{ Name: "upgrade IBC clients", Height: 1000, @@ -787,14 +787,15 @@ func (suite *TypesTestSuite) TestMsgIBCSoftwareUpgrade_GetSigners() { plan, clientState, ) - suite.Require().NoError(err) + require.NoError(t, err) - signers, _, err := suite.chainA.Codec.GetMsgV1Signers(msg) + encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{}) + signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(tc.address.Bytes(), signers[0]) + require.NoError(t, err) + require.Equal(t, tc.address.Bytes(), signers[0]) } else { - suite.Require().Error(err) + require.Error(t, err) } } } From d1fa9e75b93bbe6e6c3c36d1060642653e028dcd Mon Sep 17 00:00:00 2001 From: ThanhNhann Date: Wed, 6 Dec 2023 19:55:19 +0700 Subject: [PATCH 12/12] update with DimitrisJim's suggestion --- modules/apps/transfer/types/msgs_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/apps/transfer/types/msgs_test.go b/modules/apps/transfer/types/msgs_test.go index 50fc84f9f41..e9bb11cac54 100644 --- a/modules/apps/transfer/types/msgs_test.go +++ b/modules/apps/transfer/types/msgs_test.go @@ -133,7 +133,6 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { for _, tc := range testCases { tc := tc - address := tc.address msg := types.MsgUpdateParams{ Signer: tc.address.String(), Params: types.DefaultParams(), @@ -143,7 +142,7 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { signers, _, err := encodingCfg.Codec.GetMsgV1Signers(&msg) if tc.expPass { require.NoError(t, err) - require.Equal(t, address.Bytes(), signers[0]) + require.Equal(t, tc.address.Bytes(), signers[0]) } else { require.Error(t, err) }