From f698099d765e29958781aa1cbc783248f5221d47 Mon Sep 17 00:00:00 2001 From: Nikolas De Giorgis Date: Mon, 19 Aug 2024 09:53:43 +0100 Subject: [PATCH] chore: use expected errors in ica host test. (#7181) * chore: use expected errors in ica host test. * pr feedback --- .../host/ibc_module_test.go | 66 ++++++++--------- .../host/keeper/genesis_test.go | 20 ++--- .../host/keeper/handshake_test.go | 74 +++++++++---------- .../host/keeper/keeper_test.go | 33 +++++---- .../host/keeper/msg_server_test.go | 14 ++-- .../host/types/codec_test.go | 12 +-- .../host/types/msgs_test.go | 36 ++++----- 7 files changed, 128 insertions(+), 127 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index 07699ee0da0..54afc584a83 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -141,10 +141,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { testCases := []struct { name string malleate func() - expPass bool + expErr error }{ { - "success", func() {}, true, + "success", func() {}, nil, }, { "account address generation is block dependent", func() { @@ -155,12 +155,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { // ensure account registration is simulated in a separate block suite.chainB.NextBlock() - }, true, - }, - { - "host submodule disabled", func() { - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) - }, false, + }, nil, }, { "success: ICA auth module callback returns error", func() { @@ -171,7 +166,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { ) (string, error) { return "", fmt.Errorf("mock ica auth fails") } - }, true, + }, nil, + }, + { + "host submodule disabled", func() { + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) + }, types.ErrHostSubModuleDisabled, }, } @@ -217,14 +217,14 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, chanCap, channel.Counterparty, path.EndpointA.ChannelConfig.Version, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) addr, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, counterparty.PortId) suite.Require().True(exists) suite.Require().NotNil(addr) } else { - suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) suite.Require().Equal("", version) } }) @@ -273,15 +273,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() { testCases := []struct { name string malleate func() - expPass bool + expErr error }{ { - "success", func() {}, true, - }, - { - "host submodule disabled", func() { - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) - }, false, + "success", func() {}, nil, }, { "success: ICA auth module callback returns error", func() { @@ -291,7 +286,12 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() { ) error { return fmt.Errorf("mock ica auth fails") } - }, true, + }, nil, + }, + { + "host submodule disabled", func() { + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) + }, types.ErrHostSubModuleDisabled, }, } @@ -323,10 +323,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() { err = cbs.OnChanOpenConfirm(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { - suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -364,10 +364,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() { testCases := []struct { name string malleate func() - expPass bool + expErr error }{ { - "success", func() {}, true, + "success", func() {}, nil, }, } @@ -394,10 +394,10 @@ func (suite *InterchainAccountsTestSuite) TestOnChanCloseConfirm() { err = cbs.OnChanCloseConfirm( suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { - suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -548,10 +548,10 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() { testCases := []struct { name string malleate func() - expPass bool + expErr error }{ { - "ICA OnAcknowledgementPacket fails with ErrInvalidChannelFlow", func() {}, false, + "ICA OnAcknowledgementPacket fails with ErrInvalidChannelFlow", func() {}, icatypes.ErrInvalidChannelFlow, }, } @@ -589,10 +589,10 @@ func (suite *InterchainAccountsTestSuite) TestOnAcknowledgementPacket() { err = cbs.OnAcknowledgementPacket(suite.chainB.GetContext(), path.EndpointB.GetChannel().Version, packet, []byte("ackBytes"), nil) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { - suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -603,10 +603,10 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() { testCases := []struct { name string malleate func() - expPass bool + expErr error }{ { - "ICA OnTimeoutPacket fails with ErrInvalidChannelFlow", func() {}, false, + "ICA OnTimeoutPacket fails with ErrInvalidChannelFlow", func() {}, icatypes.ErrInvalidChannelFlow, }, } @@ -644,10 +644,10 @@ func (suite *InterchainAccountsTestSuite) TestOnTimeoutPacket() { err = cbs.OnTimeoutPacket(suite.chainA.GetContext(), path.EndpointA.GetChannel().Version, packet, nil) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { - suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index 109fb3d2449..101ea1eb8c8 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -54,15 +54,15 @@ func (suite *KeeperTestSuite) TestInitGenesis() { func (suite *KeeperTestSuite) TestGenesisParams() { testCases := []struct { - name string - input types.Params - expPass bool + name string + input types.Params + expPanicMsg string }{ - {"success: set default params", types.DefaultParams(), true}, - {"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), true}, - {"success: set empty byte for allow messages", types.NewParams(true, nil), true}, - {"failure: set empty string for allow messages", types.NewParams(true, []string{""}), false}, - {"failure: set space string for allow messages", types.NewParams(true, []string{" "}), false}, + {"success: set default params", types.DefaultParams(), ""}, + {"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), ""}, + {"success: set empty byte for allow messages", types.NewParams(true, nil), ""}, + {"failure: set empty string for allow messages", types.NewParams(true, []string{""}), "could not set ica host params at genesis: parameter must not contain empty strings: []"}, + {"failure: set space string for allow messages", types.NewParams(true, []string{" "}), "could not set ica host params at genesis: parameter must not contain empty strings: [ ]"}, } for _, tc := range testCases { @@ -89,7 +89,7 @@ func (suite *KeeperTestSuite) TestGenesisParams() { Port: icatypes.HostPortID, Params: tc.input, } - if tc.expPass { + if tc.expPanicMsg == "" { keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) @@ -104,7 +104,7 @@ func (suite *KeeperTestSuite) TestGenesisParams() { params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) suite.Require().Equal(expParams, params) } else { - suite.Require().Panics(func() { + suite.PanicsWithError(tc.expPanicMsg, func() { keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) }) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go index 9140d948695..ab70bcb85b1 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake_test.go @@ -55,12 +55,12 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { testCases := []struct { name string malleate func() - expPass bool + expErr error }{ { "success", func() {}, - true, + nil, }, { "success - reopening closed active channel", @@ -73,7 +73,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { suite.openAndCloseChannel(path) }, - true, + nil, }, { "success - reopening account with new address", @@ -94,7 +94,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { _, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID) suite.Require().False(found) }, - true, + nil, }, { "success - empty host connection ID", @@ -106,7 +106,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { path.EndpointA.ChannelConfig.Version = string(versionBytes) }, - true, + nil, }, { "success - previous metadata is different", @@ -125,7 +125,15 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { channel.Version = string(versionBytes) path.EndpointB.SetChannel(*channel) - }, true, + }, nil, + }, + { + "invalid metadata bytestring", + func() { + // the try step will propose a new valid version + path.EndpointA.ChannelConfig.Version = "invalid-metadata-bytestring" + }, + nil, }, { "reopening account fails - no existing account", @@ -145,7 +153,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { acc := suite.chainB.GetSimApp().AccountKeeper.GetAccount(suite.chainB.GetContext(), sdk.MustAccAddressFromBech32(addr)) suite.chainB.GetSimApp().AccountKeeper.RemoveAccount(suite.chainB.GetContext(), acc) }, - false, + icatypes.ErrInvalidAccountReopening, }, { "reopening account fails - existing account is not interchain account type", @@ -170,7 +178,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { // overwrite existing account with only base account type, not intercahin account type suite.chainB.GetSimApp().AccountKeeper.SetAccount(suite.chainB.GetContext(), icaAcc.BaseAccount) }, - false, + icatypes.ErrInvalidAccountReopening, }, { "account already exists", @@ -180,14 +188,14 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { suite.Require().NoError(err) suite.Require().True(suite.chainB.GetSimApp().AccountKeeper.HasAccount(suite.chainB.GetContext(), interchainAccAddr)) }, - false, + icatypes.ErrAccountAlreadyExist, }, { "invalid port ID", func() { path.EndpointB.ChannelConfig.PortID = "invalid-port-id" //nolint:goconst }, - false, + icatypes.ErrInvalidHostPort, }, { "connection not found", @@ -195,15 +203,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { channel.ConnectionHops = []string{"invalid-connnection-id"} path.EndpointB.SetChannel(*channel) }, - false, - }, - { - "invalid metadata bytestring", - func() { - // the try step will propose a new valid version - path.EndpointA.ChannelConfig.Version = "invalid-metadata-bytestring" - }, - true, + connectiontypes.ErrConnectionNotFound, }, { "unsupported encoding format", @@ -215,7 +215,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { path.EndpointA.ChannelConfig.Version = string(versionBytes) }, - false, + icatypes.ErrInvalidCodec, }, { "unsupported transaction type", @@ -227,7 +227,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { path.EndpointA.ChannelConfig.Version = string(versionBytes) }, - false, + icatypes.ErrUnknownDataType, }, { "invalid controller connection ID", @@ -239,7 +239,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { path.EndpointA.ChannelConfig.Version = string(versionBytes) }, - false, + connectiontypes.ErrInvalidConnection, }, { "invalid counterparty version", @@ -251,7 +251,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { path.EndpointA.ChannelConfig.Version = string(versionBytes) }, - false, + icatypes.ErrInvalidVersion, }, { "capability already claimed", @@ -260,7 +260,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { err := suite.chainB.GetSimApp().ScopedICAHostKeeper.ClaimCapability(suite.chainB.GetContext(), chanCap, host.ChannelCapabilityPath(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)) suite.Require().NoError(err) }, - false, + capabilitytypes.ErrOwnerClaimed, }, { "active channel already set (OPEN state)", @@ -272,7 +272,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { // set the active channelID in state suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, path.EndpointB.ChannelID) }, - false, + icatypes.ErrActiveChannelAlreadySet, }, { "channel is already active (FLUSHING state)", @@ -289,7 +289,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { } suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.SetChannel(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, channel) }, - false, + icatypes.ErrActiveChannelAlreadySet, }, } @@ -334,7 +334,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, chanCap, channel.Counterparty, path.EndpointA.ChannelConfig.Version, ) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) storedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID) @@ -353,7 +353,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { suite.Require().Equal(string(expectedVersionBytes), version) } else { - suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) suite.Require().Equal("", version) } }) @@ -367,10 +367,10 @@ func (suite *KeeperTestSuite) TestOnChanOpenConfirm() { testCases := []struct { name string malleate func() - expPass bool + expErr error }{ { - "success", func() {}, true, + "success", func() {}, nil, }, { "channel not found", @@ -378,7 +378,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenConfirm() { path.EndpointB.ChannelID = "invalid-channel-id" path.EndpointB.ChannelConfig.PortID = "invalid-port-id" }, - false, + channeltypes.ErrChannelNotFound, }, } @@ -406,10 +406,10 @@ func (suite *KeeperTestSuite) TestOnChanOpenConfirm() { err = suite.chainB.GetSimApp().ICAHostKeeper.OnChanOpenConfirm(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { - suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } @@ -422,10 +422,10 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() { testCases := []struct { name string malleate func() - expPass bool + expErr error }{ { - "success", func() {}, true, + "success", func() {}, nil, }, } @@ -445,10 +445,10 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() { err = suite.chainB.GetSimApp().ICAHostKeeper.OnChanCloseConfirm(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) } else { - suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) } }) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 8986311c392..efd201712ae 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -136,7 +136,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { testCases := []struct { name string instantiateFn func() - expPass bool + panicMsg string }{ {"success", func() { keeper.NewKeeper( @@ -152,7 +152,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.chainA.GetSimApp().GRPCQueryRouter(), suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), ) - }, true}, + }, ""}, {"failure: interchain accounts module account does not exist", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), @@ -167,7 +167,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.chainA.GetSimApp().GRPCQueryRouter(), suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), ) - }, false}, + }, "the Interchain Accounts module account has not been set"}, {"failure: empty mock staking keeper", func() { keeper.NewKeeper( suite.chainA.GetSimApp().AppCodec(), @@ -182,7 +182,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.chainA.GetSimApp().GRPCQueryRouter(), "", // authority ) - }, false}, + }, "authority must be non-empty"}, } for _, tc := range testCases { @@ -190,12 +190,13 @@ func (suite *KeeperTestSuite) TestNewKeeper() { suite.SetupTest() suite.Run(tc.name, func() { - if tc.expPass { + if tc.panicMsg == "" { suite.Require().NotPanics( tc.instantiateFn, ) } else { - suite.Require().Panics( + suite.Require().PanicsWithError( + tc.panicMsg, tc.instantiateFn, ) } @@ -369,15 +370,15 @@ func (suite *KeeperTestSuite) TestParams() { suite.Require().Equal(expParams, params) testCases := []struct { - name string - input types.Params - expPass bool + name string + input types.Params + errMsg string }{ - {"success: set default params", types.DefaultParams(), true}, - {"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), true}, - {"success: set empty byte for allow messages", types.NewParams(true, nil), true}, - {"failure: set empty string for allow messages", types.NewParams(true, []string{""}), false}, - {"failure: set space string for allow messages", types.NewParams(true, []string{" "}), false}, + {"success: set default params", types.DefaultParams(), ""}, + {"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), ""}, + {"success: set empty byte for allow messages", types.NewParams(true, nil), ""}, + {"failure: set empty string for allow messages", types.NewParams(true, []string{""}), "parameter must not contain empty strings"}, + {"failure: set space string for allow messages", types.NewParams(true, []string{" "}), "parameter must not contain empty strings"}, } for _, tc := range testCases { @@ -388,13 +389,13 @@ func (suite *KeeperTestSuite) TestParams() { ctx := suite.chainA.GetContext() err := tc.input.Validate() suite.chainA.GetSimApp().ICAHostKeeper.SetParams(ctx, tc.input) - if tc.expPass { + if tc.errMsg == "" { suite.Require().NoError(err) expected := tc.input p := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(ctx) suite.Require().Equal(expected, p) } else { - suite.Require().Error(err) + suite.Require().ErrorContains(err, tc.errMsg) } }) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go index 2af40712f3c..476bf5bf00a 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go @@ -154,19 +154,19 @@ func (suite *KeeperTestSuite) TestModuleQuerySafe() { func (suite *KeeperTestSuite) TestUpdateParams() { testCases := []struct { - name string - msg *types.MsgUpdateParams - expPass bool + name string + msg *types.MsgUpdateParams + expErr error }{ { "success", types.NewMsgUpdateParams(suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), types.DefaultParams()), - true, + nil, }, { "invalid signer address", types.NewMsgUpdateParams("signer", types.DefaultParams()), - false, + ibcerrors.ErrUnauthorized, }, } @@ -180,11 +180,11 @@ func (suite *KeeperTestSuite) TestUpdateParams() { msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAHostKeeper) res, err := msgServer.UpdateParams(ctx, tc.msg) - if tc.expPass { + if tc.expErr == nil { suite.Require().NoError(err) suite.Require().NotNil(res) } else { - suite.Require().Error(err) + suite.Require().ErrorIs(err, tc.expErr) suite.Require().Nil(res) } }) diff --git a/modules/apps/27-interchain-accounts/host/types/codec_test.go b/modules/apps/27-interchain-accounts/host/types/codec_test.go index c334b3034d3..4cc6423d284 100644 --- a/modules/apps/27-interchain-accounts/host/types/codec_test.go +++ b/modules/apps/27-interchain-accounts/host/types/codec_test.go @@ -16,22 +16,22 @@ func TestCodecTypeRegistration(t *testing.T) { testCases := []struct { name string typeURL string - expPass bool + errMsg string }{ { "success: MsgUpdateParams", sdk.MsgTypeURL(&types.MsgUpdateParams{}), - true, + "", }, { "success: MsgModuleQuerySafe", sdk.MsgTypeURL(&types.MsgModuleQuerySafe{}), - true, + "", }, { "type not registered on codec", "ibc.invalid.MsgTypeURL", - false, + "unable to resolve type URL", }, } @@ -42,12 +42,12 @@ func TestCodecTypeRegistration(t *testing.T) { encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL) - if tc.expPass { + if tc.errMsg == "" { require.NotNil(t, msg) require.NoError(t, err) } else { require.Nil(t, msg) - require.Error(t, err) + require.ErrorContains(t, err, tc.errMsg) } }) } 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 dae632245da..59ec90dc6a2 100644 --- a/modules/apps/27-interchain-accounts/host/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/host/types/msgs_test.go @@ -16,26 +16,26 @@ import ( func TestMsgUpdateParamsValidateBasic(t *testing.T) { testCases := []struct { - name string - msg *types.MsgUpdateParams - expPass bool + name string + msg *types.MsgUpdateParams + expErr error }{ { "success: valid signer address", types.NewMsgUpdateParams(sdk.AccAddress(ibctesting.TestAccAddress).String(), types.DefaultParams()), - true, + nil, }, { "failure: invalid signer address", types.NewMsgUpdateParams("signer", types.DefaultParams()), - false, + ibcerrors.ErrInvalidAddress, }, { "failure: invalid allowed message", types.NewMsgUpdateParams("signer", types.Params{ AllowMessages: []string{""}, }), - false, + ibcerrors.ErrInvalidAddress, }, } @@ -43,10 +43,10 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { tc := tc err := tc.msg.ValidateBasic() - if tc.expPass { + if tc.expErr == nil { require.NoError(t, err) } else { - require.Error(t, err) + require.ErrorIs(t, err, tc.expErr) } } } @@ -55,10 +55,10 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress - expPass bool + errMsg string }{ - {"success: valid address", sdk.AccAddress(ibctesting.TestAccAddress), true}, - {"failure: nil address", nil, false}, + {"success: valid address", sdk.AccAddress(ibctesting.TestAccAddress), ""}, + {"failure: nil address", nil, "empty address string is not allowed"}, } for _, tc := range testCases { @@ -67,11 +67,11 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) { msg := types.NewMsgUpdateParams(tc.address.String(), types.DefaultParams()) encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) - if tc.expPass { + if tc.errMsg == "" { require.NoError(t, err) require.Equal(t, tc.address.Bytes(), signers[0]) } else { - require.Error(t, err) + require.ErrorContains(t, err, tc.errMsg) } } } @@ -125,10 +125,10 @@ func TestMsgModuleQuerySafeGetSigners(t *testing.T) { testCases := []struct { name string address sdk.AccAddress - expPass bool + errMsg string }{ - {"success: valid address", sdk.AccAddress(ibctesting.TestAccAddress), true}, - {"failure: nil address", nil, false}, + {"success: valid address", sdk.AccAddress(ibctesting.TestAccAddress), ""}, + {"failure: nil address", nil, "empty address string is not allowed"}, } for _, tc := range testCases { @@ -138,11 +138,11 @@ func TestMsgModuleQuerySafeGetSigners(t *testing.T) { msg := types.NewMsgModuleQuerySafe(tc.address.String(), []types.QueryRequest{}) encodingCfg := moduletestutil.MakeTestEncodingConfig(ica.AppModuleBasic{}) signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg) - if tc.expPass { + if tc.errMsg == "" { require.NoError(t, err) require.Equal(t, tc.address.Bytes(), signers[0]) } else { - require.Error(t, err) + require.ErrorContains(t, err, tc.errMsg) } }) }