Skip to content

Commit

Permalink
chore: update tests to use new SendPacket API (#2567)
Browse files Browse the repository at this point in the history
* chore: update tests to use new SendPacket API

* add changelog

* remove source port and source channel from parameter list of SendPacket

Co-authored-by: Carlos Rodriguez <crodveg@gmail.com>
  • Loading branch information
crodriguezvega and Carlos Rodriguez authored Oct 25, 2022
1 parent da618d7 commit 8ce603d
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 226 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (04-channel) [\#2024](https://github.com/cosmos/ibc-go/pull/2024) Channel Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper.
* (core/04-channel)[\#1703](https://github.com/cosmos/ibc-go/pull/1703) Update `SendPacket` API to take in necessary arguments and construct rest of packet rather than taking in entire packet. The generated packet sequence is returned by the `SendPacket` function.
* (modules/apps/27-interchain-accounts) [\#2433](https://github.com/cosmos/ibc-go/pull/2450) Renamed icatypes.PortPrefix to icatypes.ControllerPortPrefix & icatypes.PortID to icatypes.HostPortID
* (testing) [\#2567](https://github.com/cosmos/ibc-go/pull/2567) Modify `SendPacket` API of `Endpoint` to match the API of `SendPacket` in 04-channel.

### State Machine Breaking

Expand Down
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(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(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(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(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(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(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 8ce603d

Please sign in to comment.