Skip to content

Commit

Permalink
Add codec registrations tests for apps (#4780)
Browse files Browse the repository at this point in the history
* Add test for type registration for transfer.

* Add test for type registration for fee.

* Add test for type registration for ica.

* Lint this bad boy

* Apply suggestions from code review

Co-authored-by: Damian Nolan <[email protected]>

---------

Co-authored-by: Damian Nolan <[email protected]>
  • Loading branch information
DimitrisJim and damiannolan authored Sep 28, 2023
1 parent 500545b commit 1e4eb1a
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 0 deletions.
59 changes: 59 additions & 0 deletions modules/apps/27-interchain-accounts/controller/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
49 changes: 49 additions & 0 deletions modules/apps/27-interchain-accounts/host/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
64 changes: 64 additions & 0 deletions modules/apps/29-fee/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
48 changes: 48 additions & 0 deletions modules/apps/transfer/types/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
}
})
}
}

0 comments on commit 1e4eb1a

Please sign in to comment.