x/ibc: fix ClientUpdateProposal unpacker (#8170)

* x/ibc: fix ClientUpdateProposal unpacker

* rm duplicate line
This commit is contained in:
Federico Kunze 2020-12-16 06:41:20 -03:00 committed by GitHub
parent 829e068545
commit 1c6881def8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 2 deletions

View File

@ -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"
@ -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) {
@ -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)
}

View File

@ -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"
@ -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)
}

View File

@ -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"
)