Skip to content

Commit

Permalink
fix: register impls against govtypes.Content interface (#4746)
Browse files Browse the repository at this point in the history
* fix: register impls against govtypes.Content interface

* test: adding codec type registration test to 02-client/types
  • Loading branch information
damiannolan authored Sep 21, 2023
1 parent bef00ef commit 9b595a9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/core/02-client/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand Down Expand Up @@ -46,6 +47,11 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&MsgIBCSoftwareUpgrade{},
&MsgUpdateParams{},
)
registry.RegisterImplementations(
(*govtypesv1beta1.Content)(nil),
&ClientUpdateProposal{},
&UpgradeProposal{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
Expand Down
76 changes: 76 additions & 0 deletions modules/core/02-client/types/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types_test

import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
Expand Down Expand Up @@ -155,3 +156,78 @@ func (suite *TypesTestSuite) TestPackClientMessage() {
}
}
}

func (suite *TypesTestSuite) TestCodecTypeRegistration() {
testCases := []struct {
name string
typeURL string
expPass bool
}{
{
"success: MsgCreateClient",
sdk.MsgTypeURL(&types.MsgCreateClient{}),
true,
},
{
"success: MsgUpdateClient",
sdk.MsgTypeURL(&types.MsgUpdateClient{}),
true,
},
{
"success: MsgUpgradeClient",
sdk.MsgTypeURL(&types.MsgUpgradeClient{}),
true,
},
{
"success: MsgSubmitMisbehaviour",
sdk.MsgTypeURL(&types.MsgSubmitMisbehaviour{}),
true,
},
{
"success: MsgRecoverClient",
sdk.MsgTypeURL(&types.MsgRecoverClient{}),
true,
},
{
"success: MsgIBCSoftwareUpgrade",
sdk.MsgTypeURL(&types.MsgIBCSoftwareUpgrade{}),
true,
},
{
"success: MsgUpdateParams",
sdk.MsgTypeURL(&types.MsgUpdateParams{}),
true,
},
{
"success: ClientUpdateProposal",
sdk.MsgTypeURL(&types.ClientUpdateProposal{}),
true,
},
{
"success: UpgradeProposal",
sdk.MsgTypeURL(&types.UpgradeProposal{}),
true,
},
{
"type not registered on codec",
"ibc.invalid.MsgTypeURL",
false,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
msg, err := suite.chainA.GetSimApp().AppCodec().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 9b595a9

Please sign in to comment.