Skip to content

Commit 9b595a9

Browse files
authoredSep 21, 2023
fix: register impls against govtypes.Content interface (#4746)
* fix: register impls against govtypes.Content interface * test: adding codec type registration test to 02-client/types
1 parent bef00ef commit 9b595a9

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
 

‎modules/core/02-client/types/codec.go

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
99
sdk "github.com/cosmos/cosmos-sdk/types"
1010
"github.com/cosmos/cosmos-sdk/types/msgservice"
11+
govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
1112

1213
ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors"
1314
"github.com/cosmos/ibc-go/v8/modules/core/exported"
@@ -46,6 +47,11 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
4647
&MsgIBCSoftwareUpgrade{},
4748
&MsgUpdateParams{},
4849
)
50+
registry.RegisterImplementations(
51+
(*govtypesv1beta1.Content)(nil),
52+
&ClientUpdateProposal{},
53+
&UpgradeProposal{},
54+
)
4955

5056
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
5157
}

‎modules/core/02-client/types/codec_test.go

+76
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package types_test
22

33
import (
44
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
5+
sdk "github.com/cosmos/cosmos-sdk/types"
56

67
"github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
78
commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
@@ -155,3 +156,78 @@ func (suite *TypesTestSuite) TestPackClientMessage() {
155156
}
156157
}
157158
}
159+
160+
func (suite *TypesTestSuite) TestCodecTypeRegistration() {
161+
testCases := []struct {
162+
name string
163+
typeURL string
164+
expPass bool
165+
}{
166+
{
167+
"success: MsgCreateClient",
168+
sdk.MsgTypeURL(&types.MsgCreateClient{}),
169+
true,
170+
},
171+
{
172+
"success: MsgUpdateClient",
173+
sdk.MsgTypeURL(&types.MsgUpdateClient{}),
174+
true,
175+
},
176+
{
177+
"success: MsgUpgradeClient",
178+
sdk.MsgTypeURL(&types.MsgUpgradeClient{}),
179+
true,
180+
},
181+
{
182+
"success: MsgSubmitMisbehaviour",
183+
sdk.MsgTypeURL(&types.MsgSubmitMisbehaviour{}),
184+
true,
185+
},
186+
{
187+
"success: MsgRecoverClient",
188+
sdk.MsgTypeURL(&types.MsgRecoverClient{}),
189+
true,
190+
},
191+
{
192+
"success: MsgIBCSoftwareUpgrade",
193+
sdk.MsgTypeURL(&types.MsgIBCSoftwareUpgrade{}),
194+
true,
195+
},
196+
{
197+
"success: MsgUpdateParams",
198+
sdk.MsgTypeURL(&types.MsgUpdateParams{}),
199+
true,
200+
},
201+
{
202+
"success: ClientUpdateProposal",
203+
sdk.MsgTypeURL(&types.ClientUpdateProposal{}),
204+
true,
205+
},
206+
{
207+
"success: UpgradeProposal",
208+
sdk.MsgTypeURL(&types.UpgradeProposal{}),
209+
true,
210+
},
211+
{
212+
"type not registered on codec",
213+
"ibc.invalid.MsgTypeURL",
214+
false,
215+
},
216+
}
217+
218+
for _, tc := range testCases {
219+
tc := tc
220+
221+
suite.Run(tc.name, func() {
222+
msg, err := suite.chainA.GetSimApp().AppCodec().InterfaceRegistry().Resolve(tc.typeURL)
223+
224+
if tc.expPass {
225+
suite.Require().NotNil(msg)
226+
suite.Require().NoError(err)
227+
} else {
228+
suite.Require().Nil(msg)
229+
suite.Require().Error(err)
230+
}
231+
})
232+
}
233+
}

0 commit comments

Comments
 (0)
Please sign in to comment.