Skip to content

Commit

Permalink
chores: fix codec tests to use error (#7669)
Browse files Browse the repository at this point in the history
* chores: fix codec tests to use error

* chore: make lint-fix

---------

Co-authored-by: DimitrisJim <[email protected]>
  • Loading branch information
biemoh and DimitrisJim authored Dec 11, 2024
1 parent 13ed268 commit 741d5cb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 61 deletions.
23 changes: 12 additions & 11 deletions modules/core/03-connection/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -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"),
},
}

Expand All @@ -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())
}
})
}
Expand Down
53 changes: 27 additions & 26 deletions modules/core/04-channel/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -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"),
},
}

Expand All @@ -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())
}
})
}
Expand Down
15 changes: 7 additions & 8 deletions modules/light-clients/06-solomachine/codec_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package solomachine_test

import (
"errors"
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -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",
Expand All @@ -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"),
},
}

Expand All @@ -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())
}
})
}
Expand Down
21 changes: 11 additions & 10 deletions modules/light-clients/07-tendermint/codec_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tendermint_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -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"),
},
}

Expand All @@ -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())
}
})
}
Expand Down
11 changes: 5 additions & 6 deletions modules/light-clients/08-wasm/types/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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())
}
})
}
Expand Down

0 comments on commit 741d5cb

Please sign in to comment.