Skip to content

Commit

Permalink
fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Oct 20, 2024
1 parent 5d4b6d8 commit 9b5c5df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 147 deletions.
21 changes: 6 additions & 15 deletions tests/integration/expired_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ func (s *CCVTestSuite) TestVSCPacketSendExpiredClient() {
s.nextEpoch()
// - relay all VSC packet from provider to consumer
relayAllCommittedPackets(s, s.providerChain, s.path, ccv.ProviderPortID, s.path.EndpointB.ChannelID, 3)
// - increment time so that the unbonding period ends on the consumer
incrementTimeByUnbondingPeriod(s, Consumer)
// - relay all VSCMatured packet from consumer to provider
relayAllCommittedPackets(s, s.consumerChain, s.path, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, 3)
}

// TestConsumerPacketSendExpiredClient tests the consumer sending packets when the provider client is expired.
Expand Down Expand Up @@ -134,10 +130,9 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() {
consumerUnbondingPeriod := s.consumerApp.GetConsumerKeeper().GetUnbondingPeriod(s.consumerCtx())
incrementTimeWithoutUpdate(s, consumerUnbondingPeriod+time.Hour, Provider)

// check that the packets were added to the list of pending data packets
// check that no packets were added to the list of pending data packets
consumerPackets := consumerKeeper.GetPendingPackets(s.consumerCtx())
s.Require().NotEmpty(consumerPackets)
s.Require().Len(consumerPackets, 2, "unexpected number of pending data packets")
s.Require().Empty(consumerPackets)

// try to send slash packet for downtime infraction
addr := ed25519.GenPrivKey().PubKey().Address()
Expand All @@ -151,21 +146,21 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() {
// check that the packets were added to the list of pending data packets
consumerPackets = consumerKeeper.GetPendingPackets(s.consumerCtx())
s.Require().NotEmpty(consumerPackets)
// At this point we expect 4 packets, two vsc matured packets and two trailing slash packets
s.Require().Len(consumerPackets, 4, "unexpected number of pending data packets")
// At this point we expect two trailing slash packets
s.Require().Len(consumerPackets, 2, "unexpected number of pending data packets")

// upgrade expired client to the consumer
upgradeExpiredClient(s, Provider)

// go to next block to trigger SendPendingPackets
s.consumerChain.NextBlock()

// Check that the leading vsc matured packets were sent and no longer pending
// Check that both slash packets are still pending
consumerPackets = consumerKeeper.GetPendingPackets(s.consumerCtx())
s.Require().Len(consumerPackets, 2, "unexpected number of pending data packets")

// relay committed packets from consumer to provider, first slash packet should be committed
relayAllCommittedPackets(s, s.consumerChain, s.path, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, 3) // two vsc matured + one slash
relayAllCommittedPackets(s, s.consumerChain, s.path, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, 1) // one slash

// First slash has been acked, now only the second slash packet should remain as pending
consumerPackets = consumerKeeper.GetPendingPackets(s.consumerCtx())
Expand All @@ -187,10 +182,6 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() {
s.nextEpoch()
// - relay 1 VSC packet from provider to consumer
relayAllCommittedPackets(s, s.providerChain, s.path, ccv.ProviderPortID, s.path.EndpointB.ChannelID, 1)
// - increment time so that the unbonding period ends on the provider
incrementTimeByUnbondingPeriod(s, Consumer)
// - relay 1 VSCMatured packet from consumer to provider
relayAllCommittedPackets(s, s.consumerChain, s.path, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, 1)
}

// expireClient expires the client to the `clientTo` chain
Expand Down
132 changes: 0 additions & 132 deletions tests/integration/valset_update.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package integration

import (
"time"

clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"

"cosmossdk.io/math"

cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"

abci "github.com/cometbft/cometbft/abci/types"

ccv "github.com/cosmos/interchain-security/v6/x/ccv/types"
)

Expand All @@ -34,128 +26,4 @@ func (s *CCVTestSuite) TestPacketRoundtrip() {

// Relay 1 VSC packet from provider to consumer
relayAllCommittedPackets(s, s.providerChain, s.path, ccv.ProviderPortID, s.path.EndpointB.ChannelID, 1)

// Increment time so that the unbonding period ends on the provider
incrementTimeByUnbondingPeriod(s, Provider)

// Relay 1 VSCMatured packet from consumer to provider
relayAllCommittedPackets(s, s.consumerChain, s.path, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, 1)
}

// TestQueueAndSendVSCMaturedPackets tests the behavior of EndBlock QueueVSCMaturedPackets call and its integration with SendPackets call.
// @Long Description@
// * Set up CCV channel.
// * Create and simulate the sending of three VSC packets from the provider chain to the consumer chain at different times.
// * Send the first packet and validate its processing.
// * Simulate the passage of one hour.
// * Send the second packet and validate its processing.
// * Simulate the passage of 24 more hours.
// * Send the third packet and validate its processing.
// * Retrieve all packet maturity times from the consumer, and use this to check the maturity status of the packets sent earlier.
// * Advance the time so that the first two packets reach their unbonding period, while the third packet does not.
// * Ensure first two packets are unbonded, their maturity times are deleted, and that VSCMatured packets are queued.
// * The third packet is still in the store and has not yet been processed for unbonding.
// * Checks that the packet commitments for the processed packets are correctly reflected in the consumer chain's state.
func (suite *CCVTestSuite) TestQueueAndSendVSCMaturedPackets() {
consumerKeeper := suite.consumerApp.GetConsumerKeeper()

// setup CCV channel
suite.SetupCCVChannel(suite.path)

// send 3 packets to consumer chain at different times
pk, err := cryptocodec.FromCmtPubKeyInterface(suite.providerChain.Vals.Validators[0].PubKey)
suite.Require().NoError(err)
pk1, err := cryptocodec.ToCmtProtoPublicKey(pk)
suite.Require().NoError(err)
pk, err = cryptocodec.FromCmtPubKeyInterface(suite.providerChain.Vals.Validators[1].PubKey)
suite.Require().NoError(err)
pk2, err := cryptocodec.ToCmtProtoPublicKey(pk)
suite.Require().NoError(err)

pd := ccv.NewValidatorSetChangePacketData(
[]abci.ValidatorUpdate{
{
PubKey: pk1,
Power: 30,
},
{
PubKey: pk2,
Power: 20,
},
},
1,
nil,
)

// send first packet
packet := suite.newPacketFromProvider(pd.GetBytes(), 1, suite.path, clienttypes.NewHeight(1, 0), 0)
err = consumerKeeper.OnRecvVSCPacket(suite.consumerChain.GetContext(), packet, pd)
suite.Require().Nil(err, "OnRecvVSCPacket did return non-nil error")

// increase time
incrementTime(suite, time.Hour)

// update time and send second packet
pd.ValidatorUpdates[0].Power = 15
pd.ValsetUpdateId = 2
packet.Data = pd.GetBytes()
packet.Sequence = 2
err = consumerKeeper.OnRecvVSCPacket(suite.consumerChain.GetContext(), packet, pd)
suite.Require().Nil(err, "OnRecvVSCPacket did return non-nil error")

// increase time
incrementTime(suite, 24*time.Hour)

// update time and send third packet
pd.ValidatorUpdates[1].Power = 40
pd.ValsetUpdateId = 3
packet.Data = pd.GetBytes()
packet.Sequence = 3
err = consumerKeeper.OnRecvVSCPacket(suite.consumerChain.GetContext(), packet, pd)
suite.Require().Nil(err, "OnRecvVSCPacket did return non-nil error")

packetMaturities := consumerKeeper.GetAllPacketMaturityTimes(suite.consumerChain.GetContext())

// increase time such that first two packets are unbonded but third is not.
unbondingPeriod := consumerKeeper.GetUnbondingPeriod(suite.consumerChain.GetContext())
// increase time
incrementTime(suite, unbondingPeriod-time.Hour)

// ensure first two packets are unbonded and VSCMatured packets are queued
// unbonded time is deleted
suite.Require().False(
consumerKeeper.PacketMaturityTimeExists(
suite.consumerChain.GetContext(),
packetMaturities[0].VscId,
packetMaturities[0].MaturityTime,
),
"maturity time not deleted for mature packet 1",
)
suite.Require().False(
consumerKeeper.PacketMaturityTimeExists(
suite.consumerChain.GetContext(),
packetMaturities[1].VscId,
packetMaturities[1].MaturityTime,
),
"maturity time not deleted for mature packet 2",
)
// ensure that third packet did not get unbonded and is still in store
suite.Require().True(
consumerKeeper.PacketMaturityTimeExists(
suite.consumerChain.GetContext(),
packetMaturities[2].VscId,
packetMaturities[2].MaturityTime,
),
"maturity time for packet 3 is not after current time",
)

// check that the packets are committed in state
commitments := suite.consumerApp.GetIBCKeeper().ChannelKeeper.GetAllPacketCommitmentsAtChannel(
suite.consumerChain.GetContext(),
ccv.ConsumerPortID,
suite.path.EndpointA.ChannelID,
)
suite.Require().Equal(2, len(commitments), "did not find packet commitments")
suite.Require().Equal(uint64(1), commitments[0].Sequence, "did not send VSCMatured packet for VSC packet 1")
suite.Require().Equal(uint64(2), commitments[1].Sequence, "did not send VSCMatured packet for VSC packet 2")
}

0 comments on commit 9b5c5df

Please sign in to comment.