Skip to content

Commit

Permalink
test: implement codec registration tests for ibc core and lightclients (
Browse files Browse the repository at this point in the history
#4757)

* test: implement codec registration tests for ibc core and lightclients

* chore: imports
  • Loading branch information
damiannolan committed Sep 25, 2023
1 parent 5174891 commit 2bdb699
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 0 deletions.
79 changes: 79 additions & 0 deletions modules/core/03-connection/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package types_test

import (
"testing"

"github.com/stretchr/testify/require"

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"
"github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
)

func TestCodecTypeRegistration(t *testing.T) {
testCases := []struct {
name string
typeURL string
expPass bool
}{
{
"success: ConnectionEnd",
sdk.MsgTypeURL(&types.ConnectionEnd{}),
true,
},
{
"success: Counterparty",
sdk.MsgTypeURL(&types.Counterparty{}),
true,
},
{
"success: MsgConnectionOpenInit",
sdk.MsgTypeURL(&types.MsgConnectionOpenInit{}),
true,
},
{
"success: MsgConnectionOpenTry",
sdk.MsgTypeURL(&types.MsgConnectionOpenTry{}),
true,
},
{
"success: MsgConnectionOpenAck",
sdk.MsgTypeURL(&types.MsgConnectionOpenAck{}),
true,
},
{
"success: MsgConnectionOpenConfirm",
sdk.MsgTypeURL(&types.MsgConnectionOpenConfirm{}),
true,
},
{
"success: MsgUpdateParams",
sdk.MsgTypeURL(&types.MsgUpdateParams{}),
true,
},
{
"type not registered on codec",
"ibc.invalid.MsgTypeURL",
false,
},
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{})
msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL)

if tc.expPass {
require.NotNil(t, msg)
require.NoError(t, err)
} else {
require.Nil(t, msg)
require.Error(t, err)
}
})
}
}
109 changes: 109 additions & 0 deletions modules/core/04-channel/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package types_test

import (
"testing"

"github.com/stretchr/testify/require"

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"
"github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
)

func TestCodecTypeRegistration(t *testing.T) {
testCases := []struct {
name string
typeURL string
expPass bool
}{
{
"success: Channel",
sdk.MsgTypeURL(&types.Channel{}),
true,
},
{
"success: Counterparty",
sdk.MsgTypeURL(&types.Counterparty{}),
true,
},
{
"success: Packet",
sdk.MsgTypeURL(&types.Packet{}),
true,
},
{
"success: MsgChannelOpenInit",
sdk.MsgTypeURL(&types.MsgChannelOpenInit{}),
true,
},
{
"success: MsgChannelOpenTry",
sdk.MsgTypeURL(&types.MsgChannelOpenTry{}),
true,
},
{
"success: MsgChannelOpenAck",
sdk.MsgTypeURL(&types.MsgChannelOpenAck{}),
true,
},
{
"success: MsgChannelOpenConfirm",
sdk.MsgTypeURL(&types.MsgChannelOpenConfirm{}),
true,
},
{
"success: MsgChannelCloseInit",
sdk.MsgTypeURL(&types.MsgChannelCloseInit{}),
true,
},
{
"success: MsgChannelCloseConfirm",
sdk.MsgTypeURL(&types.MsgChannelCloseConfirm{}),
true,
},
{
"success: MsgRecvPacket",
sdk.MsgTypeURL(&types.MsgRecvPacket{}),
true,
},
{
"success: MsgAcknowledgement",
sdk.MsgTypeURL(&types.MsgAcknowledgement{}),
true,
},
{
"success: MsgTimeout",
sdk.MsgTypeURL(&types.MsgTimeout{}),
true,
},
{
"success: MsgTimeoutOnClose",
sdk.MsgTypeURL(&types.MsgTimeoutOnClose{}),
true,
},
{
"type not registered on codec",
"ibc.invalid.MsgTypeURL",
false,
},
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{})
msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL)

if tc.expPass {
require.NotNil(t, msg)
require.NoError(t, err)
} else {
require.Nil(t, msg)
require.Error(t, err)
}
})
}
}
60 changes: 60 additions & 0 deletions modules/core/23-commitment/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package types_test

import (
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"
"github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
)

func (suite *MerkleTestSuite) TestCodecTypeRegistration() {
testCases := []struct {
name string
typeURL string
expPass bool
}{
{
"success: MerkleRoot",
sdk.MsgTypeURL(&types.MerkleRoot{}),
true,
},
{
"success: MerklePrefix",
sdk.MsgTypeURL(&types.MerklePrefix{}),
true,
},
{
"success: MerklePath",
sdk.MsgTypeURL(&types.MerklePath{}),
true,
},
{
"success: MerkleProof",
sdk.MsgTypeURL(&types.MerkleProof{}),
true,
},
{
"type not registered on codec",
"ibc.invalid.MsgTypeURL",
false,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
encodingCfg := moduletestutil.MakeTestEncodingConfig(ibc.AppModuleBasic{})
msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL)

if tc.expPass {
suite.Require().NotNil(msg)
suite.Require().NoError(err)
} else {
suite.Require().Nil(msg)
suite.Require().Error(err)
}
})
}
}
63 changes: 63 additions & 0 deletions modules/light-clients/06-solomachine/codec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package solomachine_test

import (
"testing"

"github.com/stretchr/testify/require"

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

solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine"
)

func TestCodecTypeRegistration(t *testing.T) {
testCases := []struct {
name string
typeURL string
expPass bool
}{
{
"success: ClientState",
sdk.MsgTypeURL(&solomachine.ClientState{}),
true,
},
{
"success: ConsensusState",
sdk.MsgTypeURL(&solomachine.ConsensusState{}),
true,
},
{
"success: Header",
sdk.MsgTypeURL(&solomachine.Header{}),
true,
},
{
"success: Misbehaviour",
sdk.MsgTypeURL(&solomachine.Misbehaviour{}),
true,
},
{
"type not registered on codec",
"ibc.invalid.MsgTypeURL",
false,
},
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
encodingCfg := moduletestutil.MakeTestEncodingConfig(solomachine.AppModuleBasic{})
msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL)

if tc.expPass {
require.NotNil(t, msg)
require.NoError(t, err)
} else {
require.Nil(t, msg)
require.Error(t, err)
}
})
}
}
63 changes: 63 additions & 0 deletions modules/light-clients/07-tendermint/codec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package tendermint_test

import (
"testing"

"github.com/stretchr/testify/require"

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

tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
)

func TestCodecTypeRegistration(t *testing.T) {
testCases := []struct {
name string
typeURL string
expPass bool
}{
{
"success: ClientState",
sdk.MsgTypeURL(&tendermint.ClientState{}),
true,
},
{
"success: ConsensusState",
sdk.MsgTypeURL(&tendermint.ConsensusState{}),
true,
},
{
"success: Header",
sdk.MsgTypeURL(&tendermint.Header{}),
true,
},
{
"success: Misbehaviour",
sdk.MsgTypeURL(&tendermint.Misbehaviour{}),
true,
},
{
"type not registered on codec",
"ibc.invalid.MsgTypeURL",
false,
},
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
encodingCfg := moduletestutil.MakeTestEncodingConfig(tendermint.AppModuleBasic{})
msg, err := encodingCfg.Codec.InterfaceRegistry().Resolve(tc.typeURL)

if tc.expPass {
require.NotNil(t, msg)
require.NoError(t, err)
} else {
require.Nil(t, msg)
require.Error(t, err)
}
})
}
}
Loading

0 comments on commit 2bdb699

Please sign in to comment.