diff --git a/modules/core/03-connection/types/codec_test.go b/modules/core/03-connection/types/codec_test.go new file mode 100644 index 00000000000..ca1d5b7c7c2 --- /dev/null +++ b/modules/core/03-connection/types/codec_test.go @@ -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) + } + }) + } +} diff --git a/modules/core/04-channel/types/codec_test.go b/modules/core/04-channel/types/codec_test.go new file mode 100644 index 00000000000..9122a95df0a --- /dev/null +++ b/modules/core/04-channel/types/codec_test.go @@ -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) + } + }) + } +} diff --git a/modules/core/23-commitment/types/codec_test.go b/modules/core/23-commitment/types/codec_test.go new file mode 100644 index 00000000000..88dc430b997 --- /dev/null +++ b/modules/core/23-commitment/types/codec_test.go @@ -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) + } + }) + } +} diff --git a/modules/light-clients/06-solomachine/codec_test.go b/modules/light-clients/06-solomachine/codec_test.go new file mode 100644 index 00000000000..966ad2365ba --- /dev/null +++ b/modules/light-clients/06-solomachine/codec_test.go @@ -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) + } + }) + } +} diff --git a/modules/light-clients/07-tendermint/codec_test.go b/modules/light-clients/07-tendermint/codec_test.go new file mode 100644 index 00000000000..f139e0ac39f --- /dev/null +++ b/modules/light-clients/07-tendermint/codec_test.go @@ -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) + } + }) + } +} diff --git a/modules/light-clients/09-localhost/codec_test.go b/modules/light-clients/09-localhost/codec_test.go new file mode 100644 index 00000000000..5b90faf2160 --- /dev/null +++ b/modules/light-clients/09-localhost/codec_test.go @@ -0,0 +1,49 @@ +package localhost_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" + localhost "github.com/cosmos/ibc-go/v8/modules/light-clients/09-localhost" +) + +func TestCodecTypeRegistration(t *testing.T) { + testCases := []struct { + name string + typeURL string + expPass bool + }{ + { + "success: ClientState", + sdk.MsgTypeURL(&localhost.ClientState{}), + 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) + } + }) + } +}