From 717b3f87d30f36251250ae7bb6f44103d1644577 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Wed, 6 Sep 2023 14:32:56 +0200 Subject: [PATCH] add newPacketFromConsumer/Provider helper funcs --- tests/integration/common.go | 27 +++++++++------ tests/integration/slashing.go | 10 ++---- tests/integration/throttle.go | 51 ++++++----------------------- tests/integration/throttle_retry.go | 10 ++---- tests/integration/valset_update.go | 4 +-- 5 files changed, 33 insertions(+), 69 deletions(-) diff --git a/tests/integration/common.go b/tests/integration/common.go index 78a8ba334d..18e5e6022a 100644 --- a/tests/integration/common.go +++ b/tests/integration/common.go @@ -215,15 +215,26 @@ func redelegate(s *CCVTestSuite, delAddr sdk.AccAddress, valSrcAddr sdk.ValAddre } } +func (s *CCVTestSuite) newPacketFromProvider(data []byte, sequence uint64, path *ibctesting.Path, timeoutHeight clienttypes.Height, timeoutTimestamp uint64) channeltypes.Packet { + return channeltypes.NewPacket(data, sequence, + path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, + timeoutHeight, timeoutTimestamp) +} + +func (s *CCVTestSuite) newPacketFromConsumer(data []byte, sequence uint64, path *ibctesting.Path, timeoutHeight clienttypes.Height, timeoutTimestamp uint64) channeltypes.Packet { + return channeltypes.NewPacket(data, sequence, + path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, + path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, + timeoutHeight, timeoutTimestamp) +} + // sendOnProviderRecvOnConsumer sends a packet from the provider chain and receives it on the consumer chain func sendOnProviderRecvOnConsumer(s *CCVTestSuite, path *ibctesting.Path, timeoutHeight clienttypes.Height, timeoutTimestamp uint64, data []byte) channeltypes.Packet { sequence, err := path.EndpointB.SendPacket(timeoutHeight, timeoutTimestamp, data) s.Require().NoError(err) - packet := channeltypes.NewPacket(data, sequence, - path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromProvider(data, sequence, path, timeoutHeight, timeoutTimestamp) err = path.EndpointA.RecvPacket(packet) s.Require().NoError(err) @@ -235,10 +246,7 @@ func sendOnConsumerRecvOnProvider(s *CCVTestSuite, path *ibctesting.Path, timeou sequence, err := path.EndpointA.SendPacket(timeoutHeight, timeoutTimestamp, data) s.Require().NoError(err) - packet := channeltypes.NewPacket(data, sequence, - path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, - path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, sequence, path, timeoutHeight, timeoutTimestamp) err = path.EndpointB.RecvPacket(packet) s.Require().NoError(err) @@ -410,8 +418,7 @@ func (suite *CCVTestSuite) commitConsumerPacket(ctx sdk.Context, packetData ccv. oldBlockTime := ctx.BlockTime() timeout := uint64(oldBlockTime.Add(ccv.DefaultCCVTimeoutPeriod).UnixNano()) - packet := channeltypes.NewPacket(packetData.GetBytes(), 1, ccv.ConsumerPortID, suite.path.EndpointA.ChannelID, - ccv.ProviderPortID, suite.path.EndpointB.ChannelID, clienttypes.Height{}, timeout) + packet := suite.newPacketFromConsumer(packetData.GetBytes(), 1, suite.path, clienttypes.Height{}, timeout) return channeltypes.CommitPacket(suite.consumerChain.App.AppCodec(), packet) } diff --git a/tests/integration/slashing.go b/tests/integration/slashing.go index c3fdfdc0c1..3b825fb612 100644 --- a/tests/integration/slashing.go +++ b/tests/integration/slashing.go @@ -90,10 +90,7 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() { valsetUpdateIdN := providerKeeper.GetValidatorSetUpdateId(s.providerCtx()) // receive the slash packet on the provider chain. RecvPacket() calls the provider endblocker twice - packet := channeltypes.NewPacket(data, sequence, - s.getFirstBundle().Path.EndpointA.ChannelConfig.PortID, s.getFirstBundle().Path.EndpointA.ChannelID, - s.getFirstBundle().Path.EndpointB.ChannelConfig.PortID, s.getFirstBundle().Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, sequence, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp) err = s.path.EndpointB.RecvPacket(packet) s.Require().NoError(err) @@ -266,9 +263,8 @@ func (s *CCVTestSuite) TestSlashPacketAcknowledgement() { SlashPacketData: &spd, }, ) - packet := channeltypes.NewPacket(cpd.GetBytes(), // Consumer always sends v1 packet data - 1, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, - ccv.ProviderPortID, s.path.EndpointB.ChannelID, clienttypes.Height{}, 0) + packet := s.newPacketFromConsumer(cpd.GetBytes(), // Consumer always sends v1 packet data + 1, s.path, clienttypes.Height{}, 0) // Map infraction height on provider so validation passes and provider returns valid ack result providerKeeper.SetValsetUpdateBlockHeight(s.providerCtx(), spd.ValsetUpdateId, 47923) diff --git a/tests/integration/throttle.go b/tests/integration/throttle.go index 48b26cec55..dc32ae7799 100644 --- a/tests/integration/throttle.go +++ b/tests/integration/throttle.go @@ -4,7 +4,6 @@ import ( "time" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -331,10 +330,7 @@ func (s *CCVTestSuite) TestPacketSpam() { for sequence, data := range packetsData { consumerPacketData, err := provider.UnmarshalConsumerPacketData(data) // Same func used by provider's OnRecvPacket s.Require().NoError(err) - packet := channeltypes.NewPacket(data, uint64(sequence), - firstBundle.Path.EndpointA.ChannelConfig.PortID, firstBundle.Path.EndpointA.ChannelID, - firstBundle.Path.EndpointB.ChannelConfig.PortID, firstBundle.Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, uint64(sequence), firstBundle.Path, timeoutHeight, timeoutTimestamp) providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *consumerPacketData.GetSlashPacketData()) } @@ -393,10 +389,7 @@ func (s *CCVTestSuite) TestDoubleSignDoesNotAffectThrottling() { for sequence, data := range packetsData { consumerPacketData, err := provider.UnmarshalConsumerPacketData(data) // Same func used by provider's OnRecvPacket s.Require().NoError(err) - packet := channeltypes.NewPacket(data, uint64(sequence), - firstBundle.Path.EndpointA.ChannelConfig.PortID, firstBundle.Path.EndpointA.ChannelID, - firstBundle.Path.EndpointB.ChannelConfig.PortID, firstBundle.Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, uint64(sequence), firstBundle.Path, timeoutHeight, timeoutTimestamp) providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *consumerPacketData.GetSlashPacketData()) } @@ -501,10 +494,7 @@ func (s *CCVTestSuite) TestQueueOrdering() { for i, data := range packetsData { consumerPacketData, err := provider.UnmarshalConsumerPacketData(data) // Same func used by provider's OnRecvPacket s.Require().NoError(err) - packet := channeltypes.NewPacket(data, ibcSeqs[i], - firstBundle.Path.EndpointA.ChannelConfig.PortID, firstBundle.Path.EndpointA.ChannelID, - firstBundle.Path.EndpointB.ChannelConfig.PortID, firstBundle.Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, ibcSeqs[i], firstBundle.Path, timeoutHeight, timeoutTimestamp) // Type depends on index packets were appended from above if (i+5)%10 == 0 { vscMaturedPacketData := consumerPacketData.GetVscMaturedPacketData() @@ -727,10 +717,7 @@ func (s *CCVTestSuite) TestSlashSameValidator() { for i, data := range packetsData { consumerPacketData, err := provider.UnmarshalConsumerPacketData(data) // Same func used by provider's OnRecvPacket s.Require().NoError(err) - packet := channeltypes.NewPacket(data, uint64(i), - s.getFirstBundle().Path.EndpointA.ChannelConfig.PortID, s.getFirstBundle().Path.EndpointA.ChannelID, - s.getFirstBundle().Path.EndpointB.ChannelConfig.PortID, s.getFirstBundle().Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, uint64(i), s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp) providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *consumerPacketData.GetSlashPacketData()) } @@ -792,10 +779,7 @@ func (s CCVTestSuite) TestSlashAllValidators() { //nolint:govet // this is a tes ibcSeqNum := uint64(i) consumerPacketData, err := provider.UnmarshalConsumerPacketData(data) // Same func used by provider's OnRecvPacket s.Require().NoError(err) - packet := channeltypes.NewPacket(data, ibcSeqNum, - s.getFirstBundle().Path.EndpointA.ChannelConfig.PortID, s.getFirstBundle().Path.EndpointA.ChannelID, - s.getFirstBundle().Path.EndpointB.ChannelConfig.PortID, s.getFirstBundle().Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, ibcSeqNum, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp) providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *consumerPacketData.GetSlashPacketData()) } @@ -834,10 +818,7 @@ func (s *CCVTestSuite) TestLeadingVSCMaturedAreDequeued() { data := s.constructVSCMaturedPacketFromConsumer(*bundle) packetData, err := provider.UnmarshalConsumerPacketData(data) // Same func used by provider's OnRecvPacket s.Require().NoError(err) - packet := channeltypes.NewPacket(data, ibcSeqNum, - ccvtypes.ConsumerPortID, bundle.Path.EndpointA.ChannelID, - ccvtypes.ProviderPortID, bundle.Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, ibcSeqNum, bundle.Path, timeoutHeight, timeoutTimestamp) providerKeeper.OnRecvVSCMaturedPacket(s.providerCtx(), packet, *packetData.GetVscMaturedPacketData()) } @@ -851,10 +832,7 @@ func (s *CCVTestSuite) TestLeadingVSCMaturedAreDequeued() { *s.providerChain.Vals.Validators[0], stakingtypes.Infraction_INFRACTION_DOWNTIME) packetData, err := provider.UnmarshalConsumerPacketData(data) // Same func used by provider's OnRecvPacket s.Require().NoError(err) - packet := channeltypes.NewPacket(data, ibcSeqNum, - ccvtypes.ConsumerPortID, bundle.Path.EndpointA.ChannelID, - ccvtypes.ProviderPortID, bundle.Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, ibcSeqNum, bundle.Path, timeoutHeight, timeoutTimestamp) providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *packetData.GetSlashPacketData()) } @@ -867,10 +845,7 @@ func (s *CCVTestSuite) TestLeadingVSCMaturedAreDequeued() { data := s.constructVSCMaturedPacketFromConsumer(*bundle) packetData := ccvtypes.ConsumerPacketData{} ccvtypes.ModuleCdc.MustUnmarshalJSON(data, &packetData) - packet := channeltypes.NewPacket(data, ibcSeqNum, - ccvtypes.ConsumerPortID, bundle.Path.EndpointA.ChannelID, - ccvtypes.ProviderPortID, bundle.Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, ibcSeqNum, bundle.Path, timeoutHeight, timeoutTimestamp) providerKeeper.OnRecvVSCMaturedPacket(s.providerCtx(), packet, *packetData.GetVscMaturedPacketData()) } @@ -941,10 +916,7 @@ func (s *CCVTestSuite) TestVscMaturedHandledPerBlockLimit() { data := s.constructVSCMaturedPacketFromConsumer(*bundle) packetData := ccvtypes.ConsumerPacketData{} ccvtypes.ModuleCdc.MustUnmarshalJSON(data, &packetData) - packet := channeltypes.NewPacket(data, ibcSeqNum, - ccvtypes.ConsumerPortID, bundle.Path.EndpointA.ChannelID, - ccvtypes.ProviderPortID, bundle.Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, ibcSeqNum, bundle.Path, timeoutHeight, timeoutTimestamp) providerKeeper.OnRecvVSCMaturedPacket(s.providerCtx(), packet, *packetData.GetVscMaturedPacketData()) } @@ -958,10 +930,7 @@ func (s *CCVTestSuite) TestVscMaturedHandledPerBlockLimit() { *s.providerChain.Vals.Validators[0], stakingtypes.Infraction_INFRACTION_DOWNTIME) consumderPacketData, err := provider.UnmarshalConsumerPacketData(data) // Same func used by provider's OnRecvPacket s.Require().NoError(err) - packet := channeltypes.NewPacket(data, ibcSeqNum, - ccvtypes.ConsumerPortID, bundle.Path.EndpointA.ChannelID, - ccvtypes.ProviderPortID, bundle.Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet := s.newPacketFromConsumer(data, ibcSeqNum, bundle.Path, timeoutHeight, timeoutTimestamp) providerKeeper.OnRecvSlashPacket(s.providerCtx(), packet, *consumderPacketData.GetSlashPacketData()) } } diff --git a/tests/integration/throttle_retry.go b/tests/integration/throttle_retry.go index b907800bb5..366a83f8cf 100644 --- a/tests/integration/throttle_retry.go +++ b/tests/integration/throttle_retry.go @@ -58,10 +58,7 @@ func (s *CCVTestSuite) TestSlashRetries() { timeoutHeight = clienttypes.Height{} timeoutTimestamp = uint64(s.getFirstBundle().GetCtx().BlockTime().Add(ccvtypes.DefaultCCVTimeoutPeriod).UnixNano()) ) - packet1 := channeltypes.NewPacket(packetData1, 1, - s.getFirstBundle().Path.EndpointA.ChannelConfig.PortID, s.getFirstBundle().Path.EndpointA.ChannelID, - s.getFirstBundle().Path.EndpointB.ChannelConfig.PortID, s.getFirstBundle().Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet1 := s.newPacketFromConsumer(packetData1, 1, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp) // Mock the sending of the packet on consumer consumerKeeper.AppendPendingPacket(s.consumerCtx(), ccvtypes.SlashPacket, &ccvtypes.ConsumerPacketData_SlashPacketData{ @@ -114,10 +111,7 @@ func (s *CCVTestSuite) TestSlashRetries() { // Construct and mock the sending of a second packet on consumer tmval2 := s.providerChain.Vals.Validators[2] packetData2 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.Infraction_INFRACTION_DOWNTIME) - packet2 := channeltypes.NewPacket(packetData2, 1, - s.getFirstBundle().Path.EndpointA.ChannelConfig.PortID, s.getFirstBundle().Path.EndpointA.ChannelID, - s.getFirstBundle().Path.EndpointB.ChannelConfig.PortID, s.getFirstBundle().Path.EndpointB.ChannelID, - timeoutHeight, timeoutTimestamp) + packet2 := s.newPacketFromConsumer(packetData2, 1, s.getFirstBundle().Path, timeoutHeight, timeoutTimestamp) consumerKeeper.AppendPendingPacket(s.consumerCtx(), ccvtypes.SlashPacket, &ccvtypes.ConsumerPacketData_SlashPacketData{ diff --git a/tests/integration/valset_update.go b/tests/integration/valset_update.go index 955261aa79..b12066afa8 100644 --- a/tests/integration/valset_update.go +++ b/tests/integration/valset_update.go @@ -4,7 +4,6 @@ import ( "time" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -71,8 +70,7 @@ func (suite *CCVTestSuite) TestQueueAndSendVSCMaturedPackets() { ) // send first packet - packet := channeltypes.NewPacket(pd.GetBytes(), 1, ccv.ProviderPortID, suite.path.EndpointB.ChannelID, ccv.ConsumerPortID, suite.path.EndpointA.ChannelID, - clienttypes.NewHeight(1, 0), 0) + packet := suite.newPacketFromProvider(pd.GetBytes(), 1, suite.path, clienttypes.NewHeight(1, 0), 0) ack := consumerKeeper.OnRecvVSCPacket(suite.consumerChain.GetContext(), packet, pd) suite.Require().NotNil(ack, "OnRecvVSCPacket did not return ack") suite.Require().True(ack.Success(), "OnRecvVSCPacket did not return a Success Acknowledgment")