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

x/ibc: fix ClientUpdateProposal unpacker #8170

Merged
merged 2 commits into from
Dec 16, 2020
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
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