From 61d2ff9f8f1812d98147f23c368e07f6564135c0 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Wed, 27 Sep 2023 16:43:21 +0300 Subject: [PATCH 1/5] Add test for type registration for transfer. --- modules/apps/transfer/types/codec_test.go | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/modules/apps/transfer/types/codec_test.go b/modules/apps/transfer/types/codec_test.go index 591f1748094..ceb7f96d986 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: Header", + 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) + } + }) + } +} From f0f470d01337ea13f714723b3e30d65979177647 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Wed, 27 Sep 2023 16:48:05 +0300 Subject: [PATCH 2/5] Add test for type registration for fee. --- modules/apps/29-fee/types/codec_test.go | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 modules/apps/29-fee/types/codec_test.go 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..e5134cb2c4f --- /dev/null +++ b/modules/apps/29-fee/types/codec_test.go @@ -0,0 +1,64 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + 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) + } + }) + } +} From ac3950463c805c71b7a3679ce5e97cd8d258c7ce Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Wed, 27 Sep 2023 16:53:50 +0300 Subject: [PATCH 3/5] Add test for type registration for ica. --- .../controller/types/codec_test.go | 57 +++++++++++++++++++ .../host/types/codec_test.go | 47 +++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 modules/apps/27-interchain-accounts/controller/types/codec_test.go create mode 100644 modules/apps/27-interchain-accounts/host/types/codec_test.go 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..5cde4729a3c --- /dev/null +++ b/modules/apps/27-interchain-accounts/controller/types/codec_test.go @@ -0,0 +1,57 @@ +package types_test + +import ( + "testing" + + 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" + "github.com/stretchr/testify/require" +) + +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..3210ad64ba7 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/codec_test.go @@ -0,0 +1,47 @@ +package types_test + +import ( + "testing" + + 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" + "github.com/stretchr/testify/require" +) + +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) + } + }) + } +} From b1e7983d85e1c138e1917bf12a972cabd2bc1cf5 Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Wed, 27 Sep 2023 16:54:40 +0300 Subject: [PATCH 4/5] Lint this bad boy --- .../27-interchain-accounts/controller/types/codec_test.go | 4 +++- modules/apps/27-interchain-accounts/host/types/codec_test.go | 4 +++- modules/apps/29-fee/types/codec_test.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/types/codec_test.go b/modules/apps/27-interchain-accounts/controller/types/codec_test.go index 5cde4729a3c..3b6e13a25f9 100644 --- a/modules/apps/27-interchain-accounts/controller/types/codec_test.go +++ b/modules/apps/27-interchain-accounts/controller/types/codec_test.go @@ -3,11 +3,13 @@ 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" - "github.com/stretchr/testify/require" ) func TestCodecTypeRegistration(t *testing.T) { diff --git a/modules/apps/27-interchain-accounts/host/types/codec_test.go b/modules/apps/27-interchain-accounts/host/types/codec_test.go index 3210ad64ba7..6fb2591cf47 100644 --- a/modules/apps/27-interchain-accounts/host/types/codec_test.go +++ b/modules/apps/27-interchain-accounts/host/types/codec_test.go @@ -3,11 +3,13 @@ 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" - "github.com/stretchr/testify/require" ) func TestCodecTypeRegistration(t *testing.T) { diff --git a/modules/apps/29-fee/types/codec_test.go b/modules/apps/29-fee/types/codec_test.go index e5134cb2c4f..a6ce0edb292 100644 --- a/modules/apps/29-fee/types/codec_test.go +++ b/modules/apps/29-fee/types/codec_test.go @@ -3,9 +3,9 @@ package types_test import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "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" From 996634d0b7e8c8950430b2e75ceb55388fd8ec21 Mon Sep 17 00:00:00 2001 From: Jim Fasarakis-Hilliard Date: Thu, 28 Sep 2023 11:33:34 +0300 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Damian Nolan --- modules/apps/transfer/types/codec_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/transfer/types/codec_test.go b/modules/apps/transfer/types/codec_test.go index ceb7f96d986..f1de06ef3d7 100644 --- a/modules/apps/transfer/types/codec_test.go +++ b/modules/apps/transfer/types/codec_test.go @@ -43,7 +43,7 @@ func (suite *TypesTestSuite) TestCodecTypeRegistration() { true, }, { - "success: Header", + "success: TransferAuthorization", sdk.MsgTypeURL(&types.TransferAuthorization{}), true, },