Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: register impls against govtypes.Content interface #4746

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Member Author

@damiannolan damiannolan Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should replicate this testing to each codec.go of our apps and submodules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
}
})
}
}
Loading