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

test: add UpdateConnection to endpoint and update usages in tests. #5719

Merged
merged 6 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 2 additions & 9 deletions modules/core/03-connection/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
delayPeriod = uint64(time.Hour.Nanoseconds())

// set delay period on counterparty to non-zero value
conn := path.EndpointA.GetConnection()
conn.DelayPeriod = delayPeriod
suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chainA.GetContext(), path.EndpointA.ConnectionID, conn)
path.EndpointA.UpdateConnection(func(connection *types.ConnectionEnd) { connection.DelayPeriod = delayPeriod })

// commit in order for proof to return correct value
suite.coordinator.CommitBlock(suite.chainA)
Expand Down Expand Up @@ -341,12 +339,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
suite.Require().NoError(err)

// modify connB to set counterparty connection identifier to wrong identifier
connection, found := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetConnection(suite.chainA.GetContext(), path.EndpointA.ConnectionID)
suite.Require().True(found)

connection.Counterparty.ConnectionId = "badconnectionid"

suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chainA.GetContext(), path.EndpointA.ConnectionID, connection)
path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.Counterparty.ConnectionId = "badconnectionid" })

err = path.EndpointA.UpdateClient()
suite.Require().NoError(err)
Expand Down
46 changes: 13 additions & 33 deletions modules/core/03-connection/keeper/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ func (suite *KeeperTestSuite) TestVerifyClientState() {
}{
{"verification success", func() {}, true},
{"client state not found", func() {
connection := path.EndpointA.GetConnection()
connection.ClientId = ibctesting.InvalidID
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID })
}, false},
{"consensus state for proof height not found", func() {
heightDiff = 5
Expand Down Expand Up @@ -95,9 +93,7 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() {
}{
{"verification success", func() {}, true},
{"client state not found", func() {
connection := path.EndpointA.GetConnection()
connection.ClientId = ibctesting.InvalidID
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID })
}, false},
{"consensus state not found", func() {
heightDiff = 5
Expand Down Expand Up @@ -169,17 +165,13 @@ func (suite *KeeperTestSuite) TestVerifyConnectionState() {
}{
{"verification success", func() {}, true},
{"client state not found - changed client ID", func() {
connection := path.EndpointA.GetConnection()
connection.ClientId = ibctesting.InvalidID
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID })
}, false},
{"consensus state not found - increased proof height", func() {
heightDiff = 5
}, false},
{"verification failed - connection state is different than proof", func() {
connection := path.EndpointA.GetConnection()
connection.State = types.TRYOPEN
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.State = types.TRYOPEN })
}, false},
{"client status is not active - client is expired", func() {
clientState := path.EndpointA.GetClientState().(*ibctm.ClientState)
Expand Down Expand Up @@ -234,9 +226,7 @@ func (suite *KeeperTestSuite) TestVerifyChannelState() {
}{
{"verification success", func() {}, true},
{"client state not found- changed client ID", func() {
connection := path.EndpointA.GetConnection()
connection.ClientId = ibctesting.InvalidID
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID })
}, false},
{"consensus state not found - increased proof height", func() {
heightDiff = 5
Expand Down Expand Up @@ -314,9 +304,9 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() {
timePerBlock = 1
}, false},
{"client state not found- changed client ID", func() {
connection := path.EndpointB.GetConnection()
connection.ClientId = ibctesting.InvalidID
path.EndpointB.SetConnection(connection)
path.EndpointB.UpdateConnection(func(c *types.ConnectionEnd) {
c.ClientId = ibctesting.InvalidID
})
}, false},
{"consensus state not found - increased proof height", func() {
heightDiff = 5
Expand Down Expand Up @@ -406,9 +396,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() {
timePerBlock = 1
}, false},
{"client state not found- changed client ID", func() {
connection := path.EndpointA.GetConnection()
connection.ClientId = ibctesting.InvalidID
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID })
}, false},
{"consensus state not found - increased proof height", func() {
heightDiff = 5
Expand Down Expand Up @@ -507,9 +495,7 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() {
timePerBlock = 1
}, false},
{"client state not found - changed client ID", func() {
connection := path.EndpointA.GetConnection()
connection.ClientId = ibctesting.InvalidID
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID })
}, false},
{"consensus state not found - increased proof height", func() {
heightDiff = 5
Expand Down Expand Up @@ -613,9 +599,7 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() {
timePerBlock = 1
}, false},
{"client state not found- changed client ID", func() {
connection := path.EndpointA.GetConnection()
connection.ClientId = ibctesting.InvalidID
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID })
}, false},
{"consensus state not found - increased proof height", func() {
heightDiff = 5
Expand Down Expand Up @@ -709,9 +693,7 @@ func (suite *KeeperTestSuite) TestVerifyUpgradeErrorReceipt() {
{
name: "fails with bad client id",
malleate: func() {
connection := path.EndpointB.GetConnection()
connection.ClientId = ibctesting.InvalidID
path.EndpointB.SetConnection(connection)
path.EndpointB.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID })
},
expPass: false,
},
Expand Down Expand Up @@ -792,9 +774,7 @@ func (suite *KeeperTestSuite) TestVerifyUpgrade() {
{
name: "fails with bad client id",
malleate: func() {
connection := path.EndpointB.GetConnection()
connection.ClientId = ibctesting.InvalidID
path.EndpointB.SetConnection(connection)
path.EndpointB.UpdateConnection(func(c *types.ConnectionEnd) { c.ClientId = ibctesting.InvalidID })
},
expPass: false,
},
Expand Down
44 changes: 12 additions & 32 deletions modules/core/04-channel/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,10 @@ func (suite *KeeperTestSuite) TestChanOpenInit() {
path.SetupConnections()

// modify connA versions
conn := path.EndpointA.GetConnection()
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) {
c.Versions = append(c.Versions, connectiontypes.NewVersion("2", []string{"ORDER_ORDERED", "ORDER_UNORDERED"}))
})

version := connectiontypes.NewVersion("2", []string{"ORDER_ORDERED", "ORDER_UNORDERED"})
conn.Versions = append(conn.Versions, version)

suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetConnection(
suite.chainA.GetContext(),
path.EndpointA.ConnectionID, conn,
)
features = []string{"ORDER_ORDERED", "ORDER_UNORDERED"}
suite.chainA.CreatePortCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort)
portCap = suite.chainA.GetPortCapability(ibctesting.MockPort)
Expand All @@ -72,15 +67,10 @@ func (suite *KeeperTestSuite) TestChanOpenInit() {
path.SetupConnections()

// modify connA versions to only support UNORDERED channels
conn := path.EndpointA.GetConnection()
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) {
c.Versions = []*connectiontypes.Version{connectiontypes.NewVersion("1", []string{"ORDER_UNORDERED"})}
})

version := connectiontypes.NewVersion("1", []string{"ORDER_UNORDERED"})
conn.Versions = []*connectiontypes.Version{version}

suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetConnection(
suite.chainA.GetContext(),
path.EndpointA.ConnectionID, conn,
)
// NOTE: Opening UNORDERED channels is still expected to pass but ORDERED channels should fail
features = []string{"ORDER_UNORDERED"}
suite.chainA.CreatePortCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort)
Expand Down Expand Up @@ -225,15 +215,10 @@ func (suite *KeeperTestSuite) TestChanOpenTry() {
suite.Require().NoError(err)

// modify connB versions
conn := path.EndpointB.GetConnection()
path.EndpointB.UpdateConnection(func(c *connectiontypes.ConnectionEnd) {
c.Versions = append(c.Versions, connectiontypes.NewVersion("2", []string{"ORDER_ORDERED", "ORDER_UNORDERED"}))
})

version := connectiontypes.NewVersion("2", []string{"ORDER_ORDERED", "ORDER_UNORDERED"})
conn.Versions = append(conn.Versions, version)

suite.chainB.App.GetIBCKeeper().ConnectionKeeper.SetConnection(
suite.chainB.GetContext(),
path.EndpointB.ConnectionID, conn,
)
suite.chainB.CreatePortCapability(suite.chainB.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort)
portCap = suite.chainB.GetPortCapability(ibctesting.MockPort)
}, false},
Expand All @@ -244,15 +229,10 @@ func (suite *KeeperTestSuite) TestChanOpenTry() {
suite.Require().NoError(err)

// modify connA versions to only support UNORDERED channels
conn := path.EndpointA.GetConnection()
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) {
c.Versions = []*connectiontypes.Version{connectiontypes.NewVersion("1", []string{"ORDER_UNORDERED"})}
})

version := connectiontypes.NewVersion("1", []string{"ORDER_UNORDERED"})
conn.Versions = []*connectiontypes.Version{version}

suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetConnection(
suite.chainA.GetContext(),
path.EndpointA.ConnectionID, conn,
)
suite.chainA.CreatePortCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, ibctesting.MockPort)
portCap = suite.chainA.GetPortCapability(ibctesting.MockPort)
}, false},
Expand Down
21 changes: 9 additions & 12 deletions modules/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ func (suite *KeeperTestSuite) TestSendPacket() {
solomachine := ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachinesingle", "testing", 1)
path.EndpointA.ClientID = clienttypes.FormatClientIdentifier(exported.Solomachine, 10)
path.EndpointA.SetClientState(solomachine.ClientState())
connection := path.EndpointA.GetConnection()
connection.ClientId = path.EndpointA.ClientID
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.ClientId = path.EndpointA.ClientID })

channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
}, true},
Expand All @@ -78,9 +76,8 @@ func (suite *KeeperTestSuite) TestSendPacket() {
solomachine := ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachinesingle", "testing", 1)
path.EndpointA.ClientID = clienttypes.FormatClientIdentifier(exported.Solomachine, 10)
path.EndpointA.SetClientState(solomachine.ClientState())
connection := path.EndpointA.GetConnection()
connection.ClientId = path.EndpointA.ClientID
path.EndpointA.SetConnection(connection)

path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.ClientId = path.EndpointA.ClientID })

channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
}, true},
Expand Down Expand Up @@ -134,9 +131,7 @@ func (suite *KeeperTestSuite) TestSendPacket() {
sourceChannel = path.EndpointA.ChannelID

// change connection client ID
connection := path.EndpointA.GetConnection()
connection.ClientId = ibctesting.InvalidID
suite.chainA.App.GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chainA.GetContext(), path.EndpointA.ConnectionID, connection)
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.ClientId = ibctesting.InvalidID })

channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
}, false},
Expand Down Expand Up @@ -185,11 +180,13 @@ func (suite *KeeperTestSuite) TestSendPacket() {
solomachine := ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachinesingle", "testing", 1)
path.EndpointA.ClientID = clienttypes.FormatClientIdentifier(exported.Solomachine, 10)
path.EndpointA.SetClientState(solomachine.ClientState())
connection := path.EndpointA.GetConnection()
connection.ClientId = path.EndpointA.ClientID
path.EndpointA.SetConnection(connection)

path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.ClientId = path.EndpointA.ClientID })

clientState := path.EndpointA.GetClientState()
connection, found := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetConnection(suite.chainA.GetContext(), path.EndpointA.ConnectionID)
DimitrisJim marked this conversation as resolved.
Show resolved Hide resolved
suite.Require().True(found)

timestamp, err := suite.chainA.App.GetIBCKeeper().ConnectionKeeper.GetTimestampAtHeight(suite.chainA.GetContext(), connection, clientState.GetLatestHeight())
suite.Require().NoError(err)

Expand Down
47 changes: 14 additions & 33 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeInit() {
{
"invalid proposed channel connection state",
func() {
connectionEnd := path.EndpointA.GetConnection()
connectionEnd.State = connectiontypes.UNINITIALIZED

suite.chainA.GetSimApp().GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chainA.GetContext(), "connection-100", connectionEnd)
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.State = connectiontypes.UNINITIALIZED })
upgradeFields.ConnectionHops = []string{"connection-100"}
},
false,
Expand Down Expand Up @@ -183,9 +180,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeTry() {
{
"invalid connection state",
func() {
connectionEnd := path.EndpointB.GetConnection()
connectionEnd.State = connectiontypes.UNINITIALIZED
suite.chainB.GetSimApp().GetIBCKeeper().ConnectionKeeper.SetConnection(suite.chainB.GetContext(), path.EndpointB.ConnectionID, connectionEnd)
path.EndpointB.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.State = connectiontypes.UNINITIALIZED })
},
connectiontypes.ErrInvalidConnectionState,
},
Expand Down Expand Up @@ -674,9 +669,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeAck() {
{
"invalid connection state",
func() {
connectionEnd := path.EndpointA.GetConnection()
connectionEnd.State = connectiontypes.UNINITIALIZED
path.EndpointA.SetConnection(connectionEnd)
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.State = connectiontypes.UNINITIALIZED })
},
connectiontypes.ErrInvalidConnectionState,
},
Expand Down Expand Up @@ -972,9 +965,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeConfirm() {
{
"invalid connection state",
func() {
connectionEnd := path.EndpointB.GetConnection()
connectionEnd.State = connectiontypes.UNINITIALIZED
path.EndpointB.SetConnection(connectionEnd)
path.EndpointB.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.State = connectiontypes.UNINITIALIZED })
},
connectiontypes.ErrInvalidConnectionState,
},
Expand Down Expand Up @@ -1238,9 +1229,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeOpen() {
{
"invalid connection state",
func() {
connectionEnd := path.EndpointA.GetConnection()
connectionEnd.State = connectiontypes.UNINITIALIZED
path.EndpointA.SetConnection(connectionEnd)
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.State = connectiontypes.UNINITIALIZED })
},
connectiontypes.ErrInvalidConnectionState,
},
Expand Down Expand Up @@ -2023,9 +2012,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeTimeout() {
{
"connection not open",
func() {
connectionEnd := path.EndpointA.GetConnection()
connectionEnd.State = connectiontypes.UNINITIALIZED
path.EndpointA.SetConnection(connectionEnd)
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.State = connectiontypes.UNINITIALIZED })
},
connectiontypes.ErrInvalidConnectionState,
},
Expand Down Expand Up @@ -2214,9 +2201,7 @@ func (suite *KeeperTestSuite) TestStartFlush() {
{
"connection state is not in OPEN state",
func() {
conn := path.EndpointB.GetConnection()
conn.State = connectiontypes.INIT
path.EndpointB.SetConnection(conn)
path.EndpointB.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.State = connectiontypes.INIT })
},
connectiontypes.ErrInvalidConnectionState,
},
Expand Down Expand Up @@ -2321,9 +2306,7 @@ func (suite *KeeperTestSuite) TestValidateUpgradeFields() {
{
name: "fails when connection is not open",
malleate: func() {
connection := path.EndpointA.GetConnection()
connection.State = connectiontypes.UNINITIALIZED
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) { c.State = connectiontypes.UNINITIALIZED })
},
expPass: false,
},
Expand All @@ -2333,9 +2316,9 @@ func (suite *KeeperTestSuite) TestValidateUpgradeFields() {
// update channel version first so that existing channel end is not identical to proposed upgrade
proposedUpgrade.Version = mock.UpgradeVersion

connection := path.EndpointA.GetConnection()
connection.Versions = []*connectiontypes.Version{}
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) {
c.Versions = []*connectiontypes.Version{}
})
},
expPass: false,
},
Expand All @@ -2345,11 +2328,9 @@ func (suite *KeeperTestSuite) TestValidateUpgradeFields() {
// update channel version first so that existing channel end is not identical to proposed upgrade
proposedUpgrade.Version = mock.UpgradeVersion

connection := path.EndpointA.GetConnection()
connection.Versions = []*connectiontypes.Version{
connectiontypes.NewVersion("1", []string{"ORDER_ORDERED"}),
}
path.EndpointA.SetConnection(connection)
path.EndpointA.UpdateConnection(func(c *connectiontypes.ConnectionEnd) {
c.Versions = []*connectiontypes.Version{connectiontypes.NewVersion("1", []string{"ORDER_ORDERED"})}
})
},
expPass: false,
},
Expand Down
Loading
Loading