diff --git a/modules/apps/27-interchain-accounts/controller/types/codec_test.go b/modules/apps/27-interchain-accounts/controller/types/codec_test.go new file mode 100644 index 00000000000..3b6e13a25f9 --- /dev/null +++ b/modules/apps/27-interchain-accounts/controller/types/codec_test.go @@ -0,0 +1,59 @@ +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" + + ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" + "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" +) + +func TestCodecTypeRegistration(t *testing.T) { + testCases := []struct { + name string + typeURL string + expPass bool + }{ + { + "success: MsgRegisterInterchainAccount", + sdk.MsgTypeURL(&types.MsgRegisterInterchainAccount{}), + true, + }, + { + "success: MsgSendTx", + sdk.MsgTypeURL(&types.MsgSendTx{}), + 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(ica.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/apps/27-interchain-accounts/host/types/codec_test.go b/modules/apps/27-interchain-accounts/host/types/codec_test.go new file mode 100644 index 00000000000..6fb2591cf47 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/codec_test.go @@ -0,0 +1,49 @@ +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" + + ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" + "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" +) + +func TestCodecTypeRegistration(t *testing.T) { + testCases := []struct { + name string + typeURL string + expPass bool + }{ + { + "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(ica.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/apps/29-fee/types/codec_test.go b/modules/apps/29-fee/types/codec_test.go new file mode 100644 index 00000000000..a6ce0edb292 --- /dev/null +++ b/modules/apps/29-fee/types/codec_test.go @@ -0,0 +1,64 @@ +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" + + fee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" + "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" +) + +func TestCodecTypeRegistration(t *testing.T) { + testCases := []struct { + name string + typeURL string + expPass bool + }{ + { + "success: MsgPayPacketFee", + sdk.MsgTypeURL(&types.MsgPayPacketFee{}), + true, + }, + { + "success: MsgPayPacketFeeAsync", + sdk.MsgTypeURL(&types.MsgPayPacketFeeAsync{}), + true, + }, + { + "success: MsgRegisterPayee", + sdk.MsgTypeURL(&types.MsgRegisterPayee{}), + true, + }, + { + "success: MsgRegisterCounterpartyPayee", + sdk.MsgTypeURL(&types.MsgRegisterCounterpartyPayee{}), + 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(fee.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/apps/transfer/types/codec_test.go b/modules/apps/transfer/types/codec_test.go index 591f1748094..f1de06ef3d7 100644 --- a/modules/apps/transfer/types/codec_test.go +++ b/modules/apps/transfer/types/codec_test.go @@ -4,7 +4,9 @@ import ( "strings" sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer" "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ) @@ -23,3 +25,49 @@ func (suite *TypesTestSuite) TestMustMarshalProtoJSON() { exists = strings.Contains(string(bz), memo) suite.Require().False(exists) } + +func (suite *TypesTestSuite) TestCodecTypeRegistration() { + testCases := []struct { + name string + typeURL string + expPass bool + }{ + { + "success: MsgTransfer", + sdk.MsgTypeURL(&types.MsgTransfer{}), + true, + }, + { + "success: MsgUpdateParams", + sdk.MsgTypeURL(&types.MsgUpdateParams{}), + true, + }, + { + "success: TransferAuthorization", + sdk.MsgTypeURL(&types.TransferAuthorization{}), + true, + }, + { + "type not registered on codec", + "ibc.invalid.MsgTypeURL", + false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + encodingCfg := moduletestutil.MakeTestEncodingConfig(transfer.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) + } + }) + } +}