Skip to content

Commit

Permalink
chore: update tests to use new SendPacket API
Browse files Browse the repository at this point in the history
  • Loading branch information
crodriguezvega committed Oct 22, 2022
1 parent 54ec2f2 commit 0729a1c
Show file tree
Hide file tree
Showing 8 changed files with 322 additions and 226 deletions.
17 changes: 10 additions & 7 deletions modules/apps/29-fee/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,21 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() {
{
"packet already timed out",
func() {
// try to incentivze a packet which is timed out
packetID := channeltypes.NewPacketID(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, msg.PacketId.Sequence+1)
packet = channeltypes.NewPacket(ibctesting.MockPacketData, packetID.Sequence, packetID.PortId, packetID.ChannelId, suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, clienttypes.GetSelfHeight(suite.chainB.GetContext()), 0)
timeoutHeight := clienttypes.GetSelfHeight(suite.chainB.GetContext())

err := suite.path.EndpointA.SendPacket(packet)
// try to incentivize a packet which is timed out
sequence, err := suite.path.EndpointA.SendPacket(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, timeoutHeight, 0, ibctesting.MockPacketData)
suite.Require().NoError(err)

// need to update chainA's client representing chainB to prove missing ack
err = suite.path.EndpointA.UpdateClient()
suite.Require().NoError(err)

packet = channeltypes.NewPacket(ibctesting.MockPacketData, sequence, suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, timeoutHeight, 0)
err = suite.path.EndpointA.TimeoutPacket(packet)
suite.Require().NoError(err)

packetID := channeltypes.NewPacketID(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, sequence)
msg.PacketId = packetID
},
false,
Expand Down Expand Up @@ -461,11 +462,13 @@ func (suite *KeeperTestSuite) TestPayPacketFeeAsync() {
suite.SetupTest()
suite.coordinator.Setup(suite.path) // setup channel

timeoutHeight := clienttypes.NewHeight(clienttypes.ParseChainID(suite.chainB.ChainID), 100)

// send a packet to incentivize
packetID := channeltypes.NewPacketID(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, 1)
packet = channeltypes.NewPacket(ibctesting.MockPacketData, packetID.Sequence, packetID.PortId, packetID.ChannelId, suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, clienttypes.NewHeight(clienttypes.ParseChainID(suite.chainB.ChainID), 100), 0)
err := suite.path.EndpointA.SendPacket(packet)
sequence, err := suite.path.EndpointA.SendPacket(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, timeoutHeight, 0, ibctesting.MockPacketData)
suite.Require().NoError(err)
packetID := channeltypes.NewPacketID(suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, sequence)
packet = channeltypes.NewPacket(ibctesting.MockPacketData, packetID.Sequence, packetID.PortId, packetID.ChannelId, suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID, timeoutHeight, 0)

fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)
packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), nil)
Expand Down
16 changes: 8 additions & 8 deletions modules/core/03-connection/keeper/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,9 @@ func (suite *KeeperTestSuite) TestVerifyPacketCommitment() {
path = ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.Setup(path)

packet = channeltypes.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, 0)
err := path.EndpointA.SendPacket(packet)
sequence, err := path.EndpointA.SendPacket(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, defaultTimeoutHeight, 0, ibctesting.MockPacketData)
suite.Require().NoError(err)
packet = channeltypes.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, 0)

// reset variables
heightDiff = 0
Expand Down Expand Up @@ -435,14 +435,14 @@ func (suite *KeeperTestSuite) TestVerifyPacketAcknowledgement() {
suite.coordinator.Setup(path)

// send and receive packet
packet := channeltypes.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, 0)
err := path.EndpointA.SendPacket(packet)
sequence, err := path.EndpointA.SendPacket(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, defaultTimeoutHeight, 0, ibctesting.MockPacketData)
suite.Require().NoError(err)

// increment receiving chain's (chainB) time by 2 hour to always pass receive
suite.coordinator.IncrementTimeBy(time.Hour * 2)
suite.coordinator.CommitBlock(suite.chainB)

packet := channeltypes.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, 0)
err = path.EndpointB.RecvPacket(packet)
suite.Require().NoError(err)

Expand Down Expand Up @@ -540,9 +540,9 @@ func (suite *KeeperTestSuite) TestVerifyPacketReceiptAbsence() {
suite.coordinator.Setup(path)

// send, only receive in malleate if applicable
packet = channeltypes.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, 0)
err := path.EndpointA.SendPacket(packet)
sequence, err := path.EndpointA.SendPacket(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, defaultTimeoutHeight, 0, ibctesting.MockPacketData)
suite.Require().NoError(err)
packet = channeltypes.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, 0)

// reset variables
heightDiff = 0
Expand Down Expand Up @@ -640,14 +640,14 @@ func (suite *KeeperTestSuite) TestVerifyNextSequenceRecv() {
suite.coordinator.Setup(path)

// send and receive packet
packet := channeltypes.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, 0)
err := path.EndpointA.SendPacket(packet)
sequence, err := path.EndpointA.SendPacket(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, defaultTimeoutHeight, 0, ibctesting.MockPacketData)
suite.Require().NoError(err)

// increment receiving chain's (chainB) time by 2 hour to always pass receive
suite.coordinator.IncrementTimeBy(time.Hour * 2)
suite.coordinator.CommitBlock(suite.chainB)

packet := channeltypes.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, 0)
err = path.EndpointB.RecvPacket(packet)
suite.Require().NoError(err)

Expand Down
Loading

0 comments on commit 0729a1c

Please sign in to comment.