Skip to content

Commit

Permalink
Merge branch 'main' into cap-gas-save
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim authored Sep 28, 2023
2 parents ea8dff7 + 1e4eb1a commit 9b0c938
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 9b0c938

Please sign in to comment.