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

Add missing unpack interfaces functions to IBC (#8359) #8379

Merged
merged 1 commit into from
Jan 19, 2021
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
17 changes: 12 additions & 5 deletions x/ibc/core/02-client/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions x/ibc/core/02-client/types/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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))
}
8 changes: 8 additions & 0 deletions x/ibc/core/03-connection/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
24 changes: 10 additions & 14 deletions x/ibc/core/03-connection/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions x/ibc/core/03-connection/types/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand All @@ -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))
}
8 changes: 8 additions & 0 deletions x/ibc/core/04-channel/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
15 changes: 15 additions & 0 deletions x/ibc/core/04-channel/types/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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,
Expand Down