Skip to content

Commit

Permalink
Merge branch 'main' into carlos/fix-broken-links
Browse files Browse the repository at this point in the history
  • Loading branch information
crodriguezvega authored Sep 28, 2023
2 parents c11699d + 7f36e0a commit f7b5db6
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 1 deletion.
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)
}
})
}
}
2 changes: 1 addition & 1 deletion modules/capability/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (k *Keeper) InitMemStore(ctx sdk.Context) {
// IsInitialized returns true if the keeper is properly initialized, and false otherwise.
func (k *Keeper) IsInitialized(ctx sdk.Context) bool {
memStore := ctx.KVStore(k.memKey)
return memStore.Get(types.KeyMemInitialized) != nil
return memStore.Has(types.KeyMemInitialized)
}

// InitializeIndex sets the index to one (or greater) in InitChain according
Expand Down

0 comments on commit f7b5db6

Please sign in to comment.