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

ConsensusState is retrieved by light clients in verifyXYZ as necessary #7005

Merged
merged 9 commits into from
Aug 12, 2020
26 changes: 20 additions & 6 deletions x/ibc/07-tendermint/types/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() {
// setup testing conditions
clientA, _, _, connB, _, _ := suite.coordinator.Setup(suite.chainA, suite.chainB)
connection := suite.chainB.GetConnection(connB)

var ok bool
clientStateI := suite.chainA.GetClientState(clientA)
clientState, _ = clientStateI.(*types.ClientState)
clientState, ok = clientStateI.(*types.ClientState)
suite.Require().True(ok)

prefix = suite.chainB.GetPrefix()

Expand Down Expand Up @@ -290,8 +293,11 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() {
// setup testing conditions
clientA, _, _, _, _, channelB := suite.coordinator.Setup(suite.chainA, suite.chainB)
channel := suite.chainB.GetChannel(channelB)

var ok bool
clientStateI := suite.chainA.GetClientState(clientA)
clientState, _ = clientStateI.(*types.ClientState)
clientState, ok = clientStateI.(*types.ClientState)
suite.Require().True(ok)

prefix = suite.chainB.GetPrefix()

Expand Down Expand Up @@ -369,8 +375,10 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() {
err := suite.coordinator.SendPacket(suite.chainB, suite.chainA, packet, clientA)
suite.Require().NoError(err)

var ok bool
clientStateI := suite.chainA.GetClientState(clientA)
clientState, _ = clientStateI.(*types.ClientState)
clientState, ok = clientStateI.(*types.ClientState)
suite.Require().True(ok)

prefix = suite.chainB.GetPrefix()

Expand Down Expand Up @@ -455,8 +463,10 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() {
err = suite.coordinator.PacketExecuted(suite.chainB, suite.chainA, packet, clientA)
suite.Require().NoError(err)

var ok bool
clientStateI := suite.chainA.GetClientState(clientA)
clientState, _ = clientStateI.(*types.ClientState)
clientState, ok = clientStateI.(*types.ClientState)
suite.Require().True(ok)

prefix = suite.chainB.GetPrefix()

Expand Down Expand Up @@ -540,8 +550,10 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgementAbsence() {
// need to update chainA's client representing chainB to prove missing ack
suite.coordinator.UpdateClient(suite.chainA, suite.chainB, clientA, clientexported.Tendermint)

var ok bool
clientStateI := suite.chainA.GetClientState(clientA)
clientState, _ = clientStateI.(*types.ClientState)
clientState, ok = clientStateI.(*types.ClientState)
suite.Require().True(ok)

prefix = suite.chainB.GetPrefix()

Expand Down Expand Up @@ -629,8 +641,10 @@ func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() {
// need to update chainA's client representing chainB
suite.coordinator.UpdateClient(suite.chainA, suite.chainB, clientA, clientexported.Tendermint)

var ok bool
clientStateI := suite.chainA.GetClientState(clientA)
clientState, _ = clientStateI.(*types.ClientState)
clientState, ok = clientStateI.(*types.ClientState)
suite.Require().True(ok)

prefix = suite.chainB.GetPrefix()

Expand Down
73 changes: 73 additions & 0 deletions x/ibc/07-tendermint/types/store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package types_test

import (
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)

func (suite *TendermintTestSuite) TestGetConsensusState() {
var (
height uint64
clientA string
)

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success", func() {}, true,
},
{
"consensus state not found", func() {
// use height with no consensus state set
height = height + 1
}, false,
},
{
"not a consensus state interface", func() {
// marshal an empty client state and set as consensus state
store := suite.chainA.App.IBCKeeper.ClientKeeper.ClientStore(suite.chainA.GetContext(), clientA)
clientStateBz := suite.chainA.App.IBCKeeper.ClientKeeper.MustMarshalClientState(&types.ClientState{})
store.Set(host.KeyConsensusState(height), clientStateBz)
}, false,
},
// TODO: uncomment upon merge of solomachine
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
// {
// "invalid consensus state (solomachine)", func() {
// // marshal and set solomachine consensus state
// store := suite.chainA.App.IBCKeeper.ClientKeeper.ClientStore(suite.chainA.GetContext(), clientA)
// consensusStateBz := suite.chainA.App.IBCKeeper.ClientKeeper.MustMarshalConsensusState(&solomachinetypes.ConsensusState{})
// store.Set(host.KeyConsensusState(height), consensusStateBz)
// }, false,
// },
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest()

clientA, _, _, _, _, _ = suite.coordinator.Setup(suite.chainA, suite.chainB)
clientState := suite.chainA.GetClientState(clientA)
height = clientState.GetLatestHeight()

tc.malleate() // change vars as necessary

store := suite.chainA.App.IBCKeeper.ClientKeeper.ClientStore(suite.chainA.GetContext(), clientA)
consensusState, err := types.GetConsensusState(store, suite.chainA.Codec, height)

if tc.expPass {
suite.Require().NoError(err)
expConsensusState, found := suite.chainA.GetConsensusState(clientA, height)
suite.Require().True(found)
suite.Require().Equal(expConsensusState, consensusState)
} else {
suite.Require().Error(err)
suite.Require().Nil(consensusState)
}
})
}
}