Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: add unpack inerfaces message assertion to ibc software upgrade msg #4588

Merged
merged 1 commit into from
Sep 6, 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/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
_ codectypes.UnpackInterfacesMessage = (*MsgUpdateClient)(nil)
_ codectypes.UnpackInterfacesMessage = (*MsgSubmitMisbehaviour)(nil)
_ codectypes.UnpackInterfacesMessage = (*MsgUpgradeClient)(nil)
_ codectypes.UnpackInterfacesMessage = (*MsgIBCSoftwareUpgrade)(nil)
)

// NewMsgCreateClient creates a new MsgCreateClient instance
Expand Down Expand Up @@ -329,6 +330,11 @@ func (msg *MsgIBCSoftwareUpgrade) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{accAddr}
}

// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (msg *MsgIBCSoftwareUpgrade) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpacker.UnpackAny(msg.UpgradedClientState, new(exported.ClientState))
}

// NewMsgRecoverClient creates a new MsgRecoverClient instance
func NewMsgRecoverClient(signer, subjectClientID, substituteClientID string) *MsgRecoverClient {
return &MsgRecoverClient{
Expand Down
28 changes: 28 additions & 0 deletions modules/core/02-client/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,3 +923,31 @@ func (suite *TypesTestSuite) TestMsgIBCSoftwareUpgrade_ValidateBasic() {
}
}
}

// tests a MsgIBCSoftwareUpgrade can be marshaled and unmarshaled, and the
// client state can be unpacked
func (suite *TypesTestSuite) TestMarshalMsgIBCSoftwareUpgrade() {
cdc := suite.chainA.App.AppCodec()

// create proposal
plan := upgradetypes.Plan{
Name: "upgrade ibc",
Height: 1000,
}

msg, err := types.NewMsgIBCSoftwareUpgrade(ibctesting.TestAccAddress, plan, &ibctm.ClientState{})
suite.Require().NoError(err)

// marshal message
bz, err := cdc.MarshalJSON(msg)
suite.Require().NoError(err)

// unmarshal proposal
newMsg := &types.MsgIBCSoftwareUpgrade{}
err = cdc.UnmarshalJSON(bz, newMsg)
suite.Require().NoError(err)

// unpack client state
_, err = types.UnpackClientState(newMsg.UpgradedClientState)
suite.Require().NoError(err)
}