Skip to content

Commit

Permalink
fix connection handshake tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed Nov 20, 2020
1 parent 7a1c317 commit 38f3901
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 77 deletions.
14 changes: 7 additions & 7 deletions x/ibc/core/03-connection/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ func (suite *KeeperTestSuite) TestQueryConnections() {
"success",
func() {
clientA, clientB, connA0, connB0 := suite.coordinator.SetupClientConnections(suite.chainA, suite.chainB, exported.Tendermint)
connA1, connB1, err := suite.coordinator.ConnOpenInit(suite.chainA, suite.chainB, clientA, clientB)
clientA1, clientB1, connA1, connB1 := suite.coordinator.SetupClientConnections(suite.chainA, suite.chainB, exported.Tendermint)
connA2, _, err := suite.coordinator.ConnOpenInit(suite.chainA, suite.chainB, clientA, clientB)
suite.Require().NoError(err)

clientA1, clientB1, connA2, connB2 := suite.coordinator.SetupClientConnections(suite.chainA, suite.chainB, exported.Tendermint)

counterparty1 := types.NewCounterparty(clientB, connB0.ID, suite.chainB.GetPrefix())
counterparty2 := types.NewCounterparty(clientB, connB1.ID, suite.chainB.GetPrefix())
counterparty3 := types.NewCounterparty(clientB1, connB2.ID, suite.chainB.GetPrefix())
counterparty2 := types.NewCounterparty(clientB1, connB1.ID, suite.chainB.GetPrefix())
// counterparty connection id is blank after open init
counterparty3 := types.NewCounterparty(clientB, "", suite.chainB.GetPrefix())

conn1 := types.NewConnectionEnd(types.OPEN, clientA, counterparty1, types.ExportedVersionsToProto(types.GetCompatibleVersions()))
conn2 := types.NewConnectionEnd(types.INIT, clientA, counterparty2, types.ExportedVersionsToProto(types.GetCompatibleVersions()))
conn3 := types.NewConnectionEnd(types.OPEN, clientA1, counterparty3, types.ExportedVersionsToProto(types.GetCompatibleVersions()))
conn2 := types.NewConnectionEnd(types.OPEN, clientA1, counterparty2, types.ExportedVersionsToProto(types.GetCompatibleVersions()))
conn3 := types.NewConnectionEnd(types.INIT, clientA, counterparty3, types.ExportedVersionsToProto(types.GetCompatibleVersions()))

iconn1 := types.NewIdentifiedConnection(connA0.ID, conn1)
iconn2 := types.NewIdentifiedConnection(connA1.ID, conn2)
Expand Down
77 changes: 7 additions & 70 deletions x/ibc/core/03-connection/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,11 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
// the initialization (TRYINIT) of the connection on Chain B (ID #2).
func (suite *KeeperTestSuite) TestConnOpenAck() {
var (
clientA string
clientB string
counterpartyConnectionID string
consensusHeight exported.Height
version *types.Version
counterpartyClient exported.ClientState
clientA string
clientB string
consensusHeight exported.Height
version *types.Version
counterpartyClient exported.ClientState
)

testCases := []struct {
Expand All @@ -310,33 +309,6 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
// retrieve client state of chainB to pass as counterpartyClient
counterpartyClient = suite.chainB.GetClientState(clientB)
}, true},
{"success with empty stored counterparty connection ID", func() {
clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, exported.Tendermint)
connA, connB, err := suite.coordinator.ConnOpenInit(suite.chainA, suite.chainB, clientA, clientB)
suite.Require().NoError(err)

err = suite.coordinator.ConnOpenTry(suite.chainB, suite.chainA, connB, connA)
suite.Require().NoError(err)

// modify connA to set counterparty connection identifier to empty string
connection, found := suite.chainA.App.IBCKeeper.ConnectionKeeper.GetConnection(suite.chainA.GetContext(), connA.ID)
suite.Require().True(found)

connection.Counterparty.ConnectionId = ""
// use some other identifier
counterpartyConnectionID = connB.ID

suite.chainA.App.IBCKeeper.ConnectionKeeper.SetConnection(suite.chainA.GetContext(), connA.ID, connection)

err = suite.coordinator.UpdateClient(suite.chainB, suite.chainA, clientB, exported.Tendermint)
suite.Require().NoError(err)

err = suite.coordinator.UpdateClient(suite.chainA, suite.chainB, clientA, exported.Tendermint)
suite.Require().NoError(err)

// retrieve client state of chainB to pass as counterpartyClient
counterpartyClient = suite.chainB.GetClientState(clientB)
}, true},
{"success from tryopen", func() {
// chainA is in TRYOPEN, chainB is in TRYOPEN
clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, exported.Tendermint)
Expand All @@ -349,6 +321,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
// set chainB to TRYOPEN
connection := suite.chainB.GetConnection(connB)
connection.State = types.TRYOPEN
connection.Counterparty.ConnectionId = connA.ID
suite.chainB.App.IBCKeeper.ConnectionKeeper.SetConnection(suite.chainB.GetContext(), connB.ID, connection)
// update clientB so state change is committed
suite.coordinator.UpdateClient(suite.chainB, suite.chainA, clientB, exported.Tendermint)
Expand All @@ -358,37 +331,6 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
// retrieve client state of chainB to pass as counterpartyClient
counterpartyClient = suite.chainB.GetClientState(clientB)
}, true},
{"success from tryopen with empty stored connection id", func() {
// chainA is in TRYOPEN, chainB is in TRYOPEN
clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, exported.Tendermint)
connB, connA, err := suite.coordinator.ConnOpenInit(suite.chainB, suite.chainA, clientB, clientA)
suite.Require().NoError(err)

err = suite.coordinator.ConnOpenTry(suite.chainA, suite.chainB, connA, connB)
suite.Require().NoError(err)

// set chainB to TRYOPEN
connection := suite.chainB.GetConnection(connB)
connection.State = types.TRYOPEN

suite.chainB.App.IBCKeeper.ConnectionKeeper.SetConnection(suite.chainB.GetContext(), connB.ID, connection)

// set connA to use empty string
connection = suite.chainA.GetConnection(connA)

// set counterparty connection identifier to empty string
connection.Counterparty.ConnectionId = ""

suite.chainA.App.IBCKeeper.ConnectionKeeper.SetConnection(suite.chainA.GetContext(), connA.ID, connection)

// update clientB so state change is committed
suite.coordinator.UpdateClient(suite.chainB, suite.chainA, clientB, exported.Tendermint)

suite.coordinator.UpdateClient(suite.chainA, suite.chainB, clientA, exported.Tendermint)

// retrieve client state of chainB to pass as counterpartyClient
counterpartyClient = suite.chainB.GetClientState(clientB)
}, true},
{"invalid counterparty client", func() {
clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, exported.Tendermint)
connA, connB, err := suite.coordinator.ConnOpenInit(suite.chainA, suite.chainB, clientA, clientB)
Expand Down Expand Up @@ -611,17 +553,12 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
suite.SetupTest() // reset
version = types.ExportedVersionsToProto(types.GetCompatibleVersions())[0] // must be explicitly changed in malleate
consensusHeight = clienttypes.ZeroHeight() // must be explicitly changed in malleate
counterpartyConnectionID = "" // must be explicitly changed in malleate

tc.malleate()

connA := suite.chainA.GetFirstTestConnection(clientA, clientB)
connB := suite.chainB.GetFirstTestConnection(clientB, clientA)

if counterpartyConnectionID == "" {
counterpartyConnectionID = connB.ID
}

connectionKey := host.ConnectionKey(connB.ID)
proofTry, proofHeight := suite.chainB.QueryProof(connectionKey)

Expand All @@ -638,7 +575,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
proofClient, _ := suite.chainB.QueryProof(clientKey)

err := suite.chainA.App.IBCKeeper.ConnectionKeeper.ConnOpenAck(
suite.chainA.GetContext(), connA.ID, counterpartyClient, version, counterpartyConnectionID,
suite.chainA.GetContext(), connA.ID, counterpartyClient, version, connB.ID,
proofTry, proofClient, proofConsensus, proofHeight, consensusHeight,
)

Expand Down

0 comments on commit 38f3901

Please sign in to comment.