Add missing unpack interfaces functions to IBC (#8359)

* add missing UnpackInterfaces functions

* fix build

* add tests cc @fedekunze

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
colin axnér 2021-01-18 21:15:25 +01:00 committed by GitHub
parent b771effc6c
commit 99aaa5cd79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 106 additions and 19 deletions

View File

@ -69,9 +69,11 @@ func (suite *KeeperTestSuite) TestQueryClientState() {
if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
expClientState.ClearCachedValue()
suite.Require().Equal(expClientState, res.ClientState)
// ensure UnpackInterfaces is defined
cachedValue := res.ClientState.GetCachedValue()
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
}
@ -255,9 +257,11 @@ func (suite *KeeperTestSuite) TestQueryConsensusState() {
if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
expConsensusState.ClearCachedValue()
suite.Require().Equal(expConsensusState, res.ConsensusState)
// ensure UnpackInterfaces is defined
cachedValue := res.ConsensusState.GetCachedValue()
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
}
@ -356,8 +360,11 @@ func (suite *KeeperTestSuite) TestQueryConsensusStates() {
suite.Require().Equal(len(expConsensusStates), len(res.ConsensusStates))
for i := range expConsensusStates {
suite.Require().NotNil(res.ConsensusStates[i])
expConsensusStates[i].ConsensusState.ClearCachedValue()
suite.Require().Equal(expConsensusStates[i], res.ConsensusStates[i])
// ensure UnpackInterfaces is defined
cachedValue := res.ConsensusStates[i].ConsensusState.GetCachedValue()
suite.Require().NotNil(cachedValue)
}
} else {
suite.Require().Error(err)

View File

@ -2,8 +2,26 @@ package types
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)
var (
_ codectypes.UnpackInterfacesMessage = QueryClientStateResponse{}
_ codectypes.UnpackInterfacesMessage = QueryClientStatesResponse{}
_ codectypes.UnpackInterfacesMessage = QueryConsensusStateResponse{}
_ codectypes.UnpackInterfacesMessage = QueryConsensusStatesResponse{}
)
// UnpackInterfaces implements UnpackInterfacesMesssage.UnpackInterfaces
func (qcsr QueryClientStatesResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
for _, cs := range qcsr.ClientStates {
if err := cs.UnpackInterfaces(unpacker); err != nil {
return err
}
}
return nil
}
// NewQueryClientStateResponse creates a new QueryClientStateResponse instance.
func NewQueryClientStateResponse(
clientStateAny *codectypes.Any, proof []byte, height Height,
@ -15,6 +33,21 @@ func NewQueryClientStateResponse(
}
}
// UnpackInterfaces implements UnpackInterfacesMesssage.UnpackInterfaces
func (qcsr QueryClientStateResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpacker.UnpackAny(qcsr.ClientState, new(exported.ClientState))
}
// UnpackInterfaces implements UnpackInterfacesMesssage.UnpackInterfaces
func (qcsr QueryConsensusStatesResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
for _, cs := range qcsr.ConsensusStates {
if err := cs.UnpackInterfaces(unpacker); err != nil {
return err
}
}
return nil
}
// NewQueryConsensusStateResponse creates a new QueryConsensusStateResponse instance.
func NewQueryConsensusStateResponse(
consensusStateAny *codectypes.Any, proof []byte, height Height,
@ -25,3 +58,8 @@ func NewQueryConsensusStateResponse(
ProofHeight: height,
}
}
// UnpackInterfaces implements UnpackInterfacesMesssage.UnpackInterfaces
func (qcsr QueryConsensusStateResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpacker.UnpackAny(qcsr.ConsensusState, new(exported.ConsensusState))
}

View File

@ -308,6 +308,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionClientState() {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(&expIdentifiedClientState, res.IdentifiedClientState)
// ensure UnpackInterfaces is defined
cachedValue := res.IdentifiedClientState.ClientState.GetCachedValue()
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
}
@ -404,6 +408,10 @@ func (suite *KeeperTestSuite) TestQueryConnectionConsensusState() {
suite.Require().NoError(err)
suite.Require().Equal(expConsensusState, consensusState)
suite.Require().Equal(expClientID, res.ClientId)
// ensure UnpackInterfaces is defined
cachedValue := res.ConsensusState.GetCachedValue()
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
}

View File

@ -10,7 +10,15 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)
var _ sdk.Msg = &MsgConnectionOpenInit{}
var (
_ sdk.Msg = &MsgConnectionOpenInit{}
_ sdk.Msg = &MsgConnectionOpenConfirm{}
_ sdk.Msg = &MsgConnectionOpenAck{}
_ sdk.Msg = &MsgConnectionOpenTry{}
_ codectypes.UnpackInterfacesMessage = MsgConnectionOpenTry{}
_ codectypes.UnpackInterfacesMessage = MsgConnectionOpenAck{}
)
// NewMsgConnectionOpenInit creates a new MsgConnectionOpenInit instance. It sets the
// counterparty connection identifier to be empty.
@ -78,8 +86,6 @@ func (msg MsgConnectionOpenInit) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{accAddr}
}
var _ sdk.Msg = &MsgConnectionOpenTry{}
// NewMsgConnectionOpenTry creates a new MsgConnectionOpenTry instance
//nolint:interfacer
func NewMsgConnectionOpenTry(
@ -175,13 +181,7 @@ func (msg MsgConnectionOpenTry) ValidateBasic() error {
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (msg MsgConnectionOpenTry) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var clientState exported.ClientState
err := unpacker.UnpackAny(msg.ClientState, &clientState)
if err != nil {
return err
}
return nil
return unpacker.UnpackAny(msg.ClientState, new(exported.ClientState))
}
// GetSignBytes implements sdk.Msg. The function will panic since it is used
@ -199,8 +199,6 @@ func (msg MsgConnectionOpenTry) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{accAddr}
}
var _ sdk.Msg = &MsgConnectionOpenAck{}
// NewMsgConnectionOpenAck creates a new MsgConnectionOpenAck instance
//nolint:interfacer
func NewMsgConnectionOpenAck(
@ -298,8 +296,6 @@ func (msg MsgConnectionOpenAck) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{accAddr}
}
var _ sdk.Msg = &MsgConnectionOpenConfirm{}
// NewMsgConnectionOpenConfirm creates a new MsgConnectionOpenConfirm instance
//nolint:interfacer
func NewMsgConnectionOpenConfirm(

View File

@ -6,6 +6,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)
var (
_ codectypes.UnpackInterfacesMessage = QueryConnectionClientStateResponse{}
_ codectypes.UnpackInterfacesMessage = QueryConnectionConsensusStateResponse{}
)
// NewQueryConnectionResponse creates a new QueryConnectionResponse instance
func NewQueryConnectionResponse(
connection ConnectionEnd, proof []byte, height clienttypes.Height,
@ -44,6 +49,11 @@ func NewQueryConnectionClientStateResponse(identifiedClientState clienttypes.Ide
}
}
// UnpackInterfaces implements UnpackInterfacesMesssage.UnpackInterfaces
func (qccsr QueryConnectionClientStateResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return qccsr.IdentifiedClientState.UnpackInterfaces(unpacker)
}
// NewQueryConnectionConsensusStateResponse creates a newQueryConnectionConsensusStateResponse instance
func NewQueryConnectionConsensusStateResponse(clientID string, anyConsensusState *codectypes.Any, consensusStateHeight exported.Height, proof []byte, height clienttypes.Height) *QueryConnectionConsensusStateResponse {
return &QueryConnectionConsensusStateResponse{
@ -53,3 +63,8 @@ func NewQueryConnectionConsensusStateResponse(clientID string, anyConsensusState
ProofHeight: height,
}
}
// UnpackInterfaces implements UnpackInterfacesMesssage.UnpackInterfaces
func (qccsr QueryConnectionConsensusStateResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpacker.UnpackAny(qccsr.ConsensusState, new(exported.ConsensusState))
}

View File

@ -407,6 +407,10 @@ func (suite *KeeperTestSuite) TestQueryChannelClientState() {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(&expIdentifiedClientState, res.IdentifiedClientState)
// ensure UnpackInterfaces is defined
cachedValue := res.IdentifiedClientState.ClientState.GetCachedValue()
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
}
@ -542,6 +546,10 @@ func (suite *KeeperTestSuite) TestQueryChannelConsensusState() {
suite.Require().NoError(err)
suite.Require().Equal(expConsensusState, consensusState)
suite.Require().Equal(expClientID, res.ClientId)
// ensure UnpackInterfaces is defined
cachedValue := res.ConsensusState.GetCachedValue()
suite.Require().NotNil(cachedValue)
} else {
suite.Require().Error(err)
}

View File

@ -6,6 +6,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc/core/exported"
)
var (
_ codectypes.UnpackInterfacesMessage = QueryChannelClientStateResponse{}
_ codectypes.UnpackInterfacesMessage = QueryChannelConsensusStateResponse{}
)
// NewQueryChannelResponse creates a new QueryChannelResponse instance
func NewQueryChannelResponse(channel Channel, proof []byte, height clienttypes.Height) *QueryChannelResponse {
return &QueryChannelResponse{
@ -24,6 +29,11 @@ func NewQueryChannelClientStateResponse(identifiedClientState clienttypes.Identi
}
}
// UnpackInterfaces implements UnpackInterfacesMesssage.UnpackInterfaces
func (qccsr QueryChannelClientStateResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return qccsr.IdentifiedClientState.UnpackInterfaces(unpacker)
}
// NewQueryChannelConsensusStateResponse creates a newQueryChannelConsensusStateResponse instance
func NewQueryChannelConsensusStateResponse(clientID string, anyConsensusState *codectypes.Any, consensusStateHeight exported.Height, proof []byte, height clienttypes.Height) *QueryChannelConsensusStateResponse {
return &QueryChannelConsensusStateResponse{
@ -34,6 +44,11 @@ func NewQueryChannelConsensusStateResponse(clientID string, anyConsensusState *c
}
}
// UnpackInterfaces implements UnpackInterfacesMesssage.UnpackInterfaces
func (qccsr QueryChannelConsensusStateResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpacker.UnpackAny(qccsr.ConsensusState, new(exported.ConsensusState))
}
// NewQueryPacketCommitmentResponse creates a new QueryPacketCommitmentResponse instance
func NewQueryPacketCommitmentResponse(
commitment []byte, proof []byte, height clienttypes.Height,