Skip to content

Commit cdeceed

Browse files
committed
Test both cases: final in-flight packet and non-final one.
1 parent 7849259 commit cdeceed

File tree

1 file changed

+56
-29
lines changed

1 file changed

+56
-29
lines changed

modules/core/04-channel/keeper/packet_test.go

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
756756
err = path.EndpointA.ChanUpgradeAck()
757757
suite.Require().NoError(err)
758758

759-
// TODO: Manually set until #3928 is implemented.
759+
// TODO: Manually set until #3929 is implemented.
760760
channel := path.EndpointA.GetChannel()
761761
channel.FlushStatus = types.FLUSHCOMPLETE
762762
path.EndpointA.SetChannel(channel)
@@ -956,43 +956,70 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
956956
// TestAcknowledgeFlush tests that Acknowledging the last in-flight packet moves the channel
957957
// state to FLUSHINGCOMPLETE.
958958
func (suite *KeeperTestSuite) TestAcknowledgeFlushStatus() {
959-
var channelCap *capabilitytypes.Capability
959+
var path *ibctesting.Path
960960

961-
suite.SetupTest() // reset
962-
path := ibctesting.NewPath(suite.chainA, suite.chainB)
961+
testCases := []struct {
962+
msg string
963+
malleate func()
964+
expectedFlushStatus types.FlushStatus
965+
}{
966+
{
967+
"success: final packet commitment cleared, flush status set to FLUSHCOMPLETE",
968+
func() {},
969+
types.FLUSHCOMPLETE,
970+
},
971+
{
972+
"success: has in-flight packets, flush status remains FLUSHING",
973+
func() {
974+
// Send an additional packet
975+
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
976+
suite.Require().Equal(uint64(1), sequence)
977+
suite.Require().NoError(err)
978+
},
979+
types.FLUSHING,
980+
},
981+
}
963982

964-
// setup uses an UNORDERED channel
965-
suite.coordinator.Setup(path)
983+
for i, tc := range testCases {
984+
tc := tc
985+
suite.Run(fmt.Sprintf("Case %s, %d/%d tests", tc.msg, i, len(testCases)), func() {
986+
suite.SetupTest() // reset
987+
path = ibctesting.NewPath(suite.chainA, suite.chainB)
988+
suite.coordinator.Setup(path)
966989

967-
// create packet commitment
968-
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
969-
suite.Require().NoError(err)
990+
tc.malleate()
970991

971-
// create packet receipt and acknowledgement
972-
packet := types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
973-
err = path.EndpointB.RecvPacket(packet)
974-
suite.Require().NoError(err)
992+
// create packet commitment
993+
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
994+
suite.Require().NoError(err)
995+
996+
// create packet receipt and acknowledgement
997+
packet := types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp)
998+
err = path.EndpointB.RecvPacket(packet)
999+
suite.Require().NoError(err)
9751000

976-
// Move channel to UPGRADE_ACK, flush status set to flushing due to previous SendPacket
977-
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = ibcmock.UpgradeVersion
1001+
// Move channel to UPGRADE_ACK, flush status set to flushing due to previous SendPacket
1002+
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = ibcmock.UpgradeVersion
9781003

979-
err = path.EndpointA.ChanUpgradeInit()
980-
suite.Require().NoError(err)
1004+
err = path.EndpointA.ChanUpgradeInit()
1005+
suite.Require().NoError(err)
9811006

982-
err = path.EndpointB.ChanUpgradeTry()
983-
suite.Require().NoError(err)
1007+
err = path.EndpointB.ChanUpgradeTry()
1008+
suite.Require().NoError(err)
9841009

985-
err = path.EndpointA.ChanUpgradeAck()
986-
suite.Require().NoError(err)
1010+
err = path.EndpointA.ChanUpgradeAck()
1011+
suite.Require().NoError(err)
9871012

988-
packetKey := host.PacketAcknowledgementKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
989-
proof, proofHeight := path.EndpointB.QueryProof(packetKey)
1013+
packetKey := host.PacketAcknowledgementKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
1014+
proof, proofHeight := path.EndpointB.QueryProof(packetKey)
9901015

991-
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
992-
err = suite.chainA.App.GetIBCKeeper().ChannelKeeper.AcknowledgePacket(suite.chainA.GetContext(), channelCap, packet, ibcmock.MockAcknowledgement.Acknowledgement(), proof, proofHeight)
993-
suite.Require().NoError(err)
1016+
channelCap := suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
1017+
err = suite.chainA.App.GetIBCKeeper().ChannelKeeper.AcknowledgePacket(suite.chainA.GetContext(), channelCap, packet, ibcmock.MockAcknowledgement.Acknowledgement(), proof, proofHeight)
1018+
suite.Require().NoError(err)
9941019

995-
// Check that we've moved to FLUSHCOMPLETE
996-
channelA := path.EndpointA.GetChannel()
997-
suite.Require().Equal(types.FLUSHCOMPLETE, channelA.FlushStatus)
1020+
// Check that we've moved to FLUSHCOMPLETE
1021+
channelA := path.EndpointA.GetChannel()
1022+
suite.Require().Equal(tc.expectedFlushStatus, channelA.FlushStatus)
1023+
})
1024+
}
9981025
}

0 commit comments

Comments
 (0)