diff --git a/modules/core/03-connection/types/codec_test.go b/modules/core/03-connection/types/codec_test.go index 2559e1b9889..3bd87924fc3 100644 --- a/modules/core/03-connection/types/codec_test.go +++ b/modules/core/03-connection/types/codec_test.go @@ -1,6 +1,7 @@ package types_test import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -14,39 +15,39 @@ import ( func TestCodecTypeRegistration(t *testing.T) { testCases := []struct { - name string - typeURL string - expPass bool + name string + typeURL string + expError error }{ { "success: MsgConnectionOpenInit", sdk.MsgTypeURL(&types.MsgConnectionOpenInit{}), - true, + nil, }, { "success: MsgConnectionOpenTry", sdk.MsgTypeURL(&types.MsgConnectionOpenTry{}), - true, + nil, }, { "success: MsgConnectionOpenAck", sdk.MsgTypeURL(&types.MsgConnectionOpenAck{}), - true, + nil, }, { "success: MsgConnectionOpenConfirm", sdk.MsgTypeURL(&types.MsgConnectionOpenConfirm{}), - true, + nil, }, { "success: MsgUpdateParams", sdk.MsgTypeURL(&types.MsgUpdateParams{}), - true, + nil, }, { "type not registered on codec", "ibc.invalid.MsgTypeURL", - false, + fmt.Errorf("unable to resolve type URL ibc.invalid.MsgTypeURL"), }, } @@ -57,12 +58,12 @@ func TestCodecTypeRegistration(t *testing.T) { encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{}) msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL) - if tc.expPass { + if tc.expError == nil { require.NotNil(t, msg) require.NoError(t, err) } else { require.Nil(t, msg) - require.Error(t, err) + require.ErrorContains(t, err, tc.expError.Error()) } }) } diff --git a/modules/core/04-channel/types/codec_test.go b/modules/core/04-channel/types/codec_test.go index 8663e5de195..78289ea949f 100644 --- a/modules/core/04-channel/types/codec_test.go +++ b/modules/core/04-channel/types/codec_test.go @@ -1,6 +1,7 @@ package types_test import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -14,114 +15,114 @@ import ( func TestCodecTypeRegistration(t *testing.T) { testCases := []struct { - name string - typeURL string - expPass bool + name string + typeURL string + expError error }{ { "success: Packet", sdk.MsgTypeURL(&types.Packet{}), - true, + nil, }, { "success: MsgChannelOpenInit", sdk.MsgTypeURL(&types.MsgChannelOpenInit{}), - true, + nil, }, { "success: MsgChannelOpenTry", sdk.MsgTypeURL(&types.MsgChannelOpenTry{}), - true, + nil, }, { "success: MsgChannelOpenAck", sdk.MsgTypeURL(&types.MsgChannelOpenAck{}), - true, + nil, }, { "success: MsgChannelOpenConfirm", sdk.MsgTypeURL(&types.MsgChannelOpenConfirm{}), - true, + nil, }, { "success: MsgChannelCloseInit", sdk.MsgTypeURL(&types.MsgChannelCloseInit{}), - true, + nil, }, { "success: MsgChannelCloseConfirm", sdk.MsgTypeURL(&types.MsgChannelCloseConfirm{}), - true, + nil, }, { "success: MsgRecvPacket", sdk.MsgTypeURL(&types.MsgRecvPacket{}), - true, + nil, }, { "success: MsgAcknowledgement", sdk.MsgTypeURL(&types.MsgAcknowledgement{}), - true, + nil, }, { "success: MsgTimeout", sdk.MsgTypeURL(&types.MsgTimeout{}), - true, + nil, }, { "success: MsgTimeoutOnClose", sdk.MsgTypeURL(&types.MsgTimeoutOnClose{}), - true, + nil, }, { "success: MsgChannelUpgradeInit", sdk.MsgTypeURL(&types.MsgChannelUpgradeInit{}), - true, + nil, }, { "success: MsgChannelUpgradeTry", sdk.MsgTypeURL(&types.MsgChannelUpgradeTry{}), - true, + nil, }, { "success: MsgChannelUpgradeAck", sdk.MsgTypeURL(&types.MsgChannelUpgradeAck{}), - true, + nil, }, { "success: MsgChannelUpgradeConfirm", sdk.MsgTypeURL(&types.MsgChannelUpgradeConfirm{}), - true, + nil, }, { "success: MsgChannelUpgradeOpen", sdk.MsgTypeURL(&types.MsgChannelUpgradeOpen{}), - true, + nil, }, { "success: MsgChannelUpgradeTimeout", sdk.MsgTypeURL(&types.MsgChannelUpgradeTimeout{}), - true, + nil, }, { "success: MsgChannelUpgradeCancel", sdk.MsgTypeURL(&types.MsgChannelUpgradeCancel{}), - true, + nil, }, { "success: MsgPruneAcknowledgements", sdk.MsgTypeURL(&types.MsgPruneAcknowledgements{}), - true, + nil, }, { "success: MsgUpdateParams", sdk.MsgTypeURL(&types.MsgUpdateParams{}), - true, + nil, }, { "type not registered on codec", "ibc.invalid.MsgTypeURL", - false, + fmt.Errorf("unable to resolve type URL ibc.invalid.MsgTypeURL"), }, } @@ -132,12 +133,12 @@ func TestCodecTypeRegistration(t *testing.T) { encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{}) msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL) - if tc.expPass { + if tc.expError == nil { require.NotNil(t, msg) require.NoError(t, err) } else { require.Nil(t, msg) - require.Error(t, err) + require.ErrorContains(t, err, tc.expError.Error()) } }) } diff --git a/modules/light-clients/06-solomachine/codec_test.go b/modules/light-clients/06-solomachine/codec_test.go index f683f91fd7c..744a4b1537c 100644 --- a/modules/light-clients/06-solomachine/codec_test.go +++ b/modules/light-clients/06-solomachine/codec_test.go @@ -1,7 +1,7 @@ package solomachine_test import ( - "errors" + "fmt" "testing" "github.com/stretchr/testify/require" @@ -14,9 +14,9 @@ import ( func TestCodecTypeRegistration(t *testing.T) { testCases := []struct { - name string - typeURL string - expErr error + name string + typeURL string + expError error }{ { "success: ClientState", @@ -41,7 +41,7 @@ func TestCodecTypeRegistration(t *testing.T) { { "type not registered on codec", "ibc.invalid.MsgTypeURL", - errors.New("unable to resolve type URL ibc.invalid.MsgTypeURL"), + fmt.Errorf("unable to resolve type URL ibc.invalid.MsgTypeURL"), }, } @@ -52,13 +52,12 @@ func TestCodecTypeRegistration(t *testing.T) { encodingCfg := moduletestutil.MakeTestEncodingConfig(solomachine.AppModuleBasic{}) msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL) - if tc.expErr == nil { + if tc.expError == nil { require.NotNil(t, msg) require.NoError(t, err) } else { require.Nil(t, msg) - require.Error(t, err) - require.Contains(t, err.Error(), tc.expErr.Error()) + require.ErrorContains(t, err, tc.expError.Error()) } }) } diff --git a/modules/light-clients/07-tendermint/codec_test.go b/modules/light-clients/07-tendermint/codec_test.go index 87b96483177..6e3f07e33ff 100644 --- a/modules/light-clients/07-tendermint/codec_test.go +++ b/modules/light-clients/07-tendermint/codec_test.go @@ -1,6 +1,7 @@ package tendermint_test import ( + "fmt" "testing" "github.com/stretchr/testify/require" @@ -13,34 +14,34 @@ import ( func TestCodecTypeRegistration(t *testing.T) { testCases := []struct { - name string - typeURL string - expPass bool + name string + typeURL string + expError error }{ { "success: ClientState", sdk.MsgTypeURL(&tendermint.ClientState{}), - true, + nil, }, { "success: ConsensusState", sdk.MsgTypeURL(&tendermint.ConsensusState{}), - true, + nil, }, { "success: Header", sdk.MsgTypeURL(&tendermint.Header{}), - true, + nil, }, { "success: Misbehaviour", sdk.MsgTypeURL(&tendermint.Misbehaviour{}), - true, + nil, }, { "type not registered on codec", "ibc.invalid.MsgTypeURL", - false, + fmt.Errorf("unable to resolve type URL ibc.invalid.MsgTypeURL"), }, } @@ -51,12 +52,12 @@ func TestCodecTypeRegistration(t *testing.T) { encodingCfg := moduletestutil.MakeTestEncodingConfig(tendermint.AppModuleBasic{}) msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL) - if tc.expPass { + if tc.expError == nil { require.NotNil(t, msg) require.NoError(t, err) } else { require.Nil(t, msg) - require.Error(t, err) + require.ErrorContains(t, err, tc.expError.Error()) } }) } diff --git a/modules/light-clients/08-wasm/types/codec_test.go b/modules/light-clients/08-wasm/types/codec_test.go index a5ec44d2123..bde7f1beb3b 100644 --- a/modules/light-clients/08-wasm/types/codec_test.go +++ b/modules/light-clients/08-wasm/types/codec_test.go @@ -15,9 +15,9 @@ import ( func TestCodecTypeRegistration(t *testing.T) { testCases := []struct { - name string - typeURL string - expErr error + name string + typeURL string + expError error }{ { "success: ClientState", @@ -63,13 +63,12 @@ func TestCodecTypeRegistration(t *testing.T) { encodingCfg := moduletestutil.MakeTestEncodingConfig(wasm.AppModuleBasic{}) msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL) - if tc.expErr == nil { + if tc.expError == nil { require.NotNil(t, msg) require.NoError(t, err) } else { require.Nil(t, msg) - require.Error(t, err) - require.Equal(t, err.Error(), tc.expErr.Error()) + require.ErrorContains(t, err, tc.expError.Error()) } }) }