Skip to content

Commit

Permalink
x/ibc: fix ClientUpdateProposal unpacker (#8170)
Browse files Browse the repository at this point in the history
* x/ibc: fix ClientUpdateProposal unpacker

* rm duplicate line
  • Loading branch information
fedekunze authored Dec 16, 2020
1 parent 829e068 commit 1c6881d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
12 changes: 11 additions & 1 deletion x/ibc/core/02-client/types/proposal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host"
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
Expand All @@ -11,7 +12,10 @@ const (
ProposalTypeClientUpdate = "ClientUpdate"
)

var _ govtypes.Content = &ClientUpdateProposal{}
var (
_ govtypes.Content = &ClientUpdateProposal{}
_ codectypes.UnpackInterfacesMessage = ClientUpdateProposal{}
)

// NewClientUpdateProposal creates a new client update proposal.
func NewClientUpdateProposal(title, description, clientID string, header exported.Header) (*ClientUpdateProposal, error) {
Expand Down Expand Up @@ -58,3 +62,9 @@ func (cup *ClientUpdateProposal) ValidateBasic() error {

return header.ValidateBasic()
}

// UnpackInterfaces implements the UnpackInterfacesMessage interface.
func (cup ClientUpdateProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var header exported.Header
return unpacker.UnpackAny(cup.Header, &header)
}
34 changes: 34 additions & 0 deletions x/ibc/core/02-client/types/proposal_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types_test

import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/light-clients/07-tendermint/types"
Expand Down Expand Up @@ -71,3 +73,35 @@ func (suite *TypesTestSuite) TestValidateBasic() {
}
}
}

// tests a client update proposal can be marshaled and unmarshaled, and the
// client state can be unpacked
func (suite *TypesTestSuite) TestMarshalClientUpdateProposalProposal() {
_, err := types.PackHeader(&ibctmtypes.Header{})
suite.Require().NoError(err)

// create proposal
header := suite.chainA.CurrentTMClientHeader()
proposal, err := types.NewClientUpdateProposal("update IBC client", "description", "client-id", header)
suite.Require().NoError(err)

// create codec
ir := codectypes.NewInterfaceRegistry()
types.RegisterInterfaces(ir)
govtypes.RegisterInterfaces(ir)
ibctmtypes.RegisterInterfaces(ir)
cdc := codec.NewProtoCodec(ir)

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

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

// unpack client state
_, err = types.UnpackHeader(newProposal.Header)
suite.Require().NoError(err)
}
1 change: 0 additions & 1 deletion x/upgrade/types/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
ibcexported "github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)
Expand Down

0 comments on commit 1c6881d

Please sign in to comment.