Skip to content

Commit

Permalink
feat: add unpacket inerfaces message assertion (#4588)
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner authored Sep 6, 2023
1 parent 611e69a commit 7f3dd42
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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)
}

0 comments on commit 7f3dd42

Please sign in to comment.