Skip to content

Commit

Permalink
revert tests that should not have been touched
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Dec 22, 2022
1 parent b7fc0a1 commit 7336dac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
35 changes: 18 additions & 17 deletions tests/e2e/expired_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package e2e
import (
"time"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
ibcexported "github.com/cosmos/ibc-go/v3/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
ccv "github.com/cosmos/interchain-security/x/ccv/types"
abci "github.com/tendermint/tendermint/abci/types"
)

// TestVSCPacketSendWithExpiredClient tests queueing of VSCPackets when the consumer client is expired.
Expand Down Expand Up @@ -104,11 +107,13 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() {

// relay all VSC packet from provider to consumer
relayAllCommittedPackets(s, s.providerChain, s.path, ccv.ProviderPortID, s.path.EndpointB.ChannelID, 2)

// expire client to provider
expireClient(s, Provider)

// check that the client to the consumer is active
checkClientExpired(s, Consumer, false)

// increment time so that the unbonding period ends on the consumer;
// do not try to update the client to the provider since it's expired
consumerUnbondingPeriod := s.consumerApp.GetConsumerKeeper().GetUnbondingPeriod(s.consumerCtx())
Expand All @@ -119,23 +124,19 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() {
s.Require().NotEmpty(consumerPackets)
s.Require().Equal(2, len(consumerPackets.GetList()), "unexpected number of pending data packets")

// TODO: reintroduce this section if SlashPackets that are outdated
// or do not correspond to any VSCIds awaiting maturation
// should not return an errAck and not close the channel

// try to send slash packet for downtime infraction
// addr := ed25519.GenPrivKey().PubKey().Address()
// val := abci.Validator{Address: addr}
// consumerKeeper.QueueSlashPacket(s.consumerCtx(), val, 2, stakingtypes.Downtime)
// // try to send slash packet for the same downtime infraction
// consumerKeeper.QueueSlashPacket(s.consumerCtx(), val, 3, stakingtypes.Downtime)
// // try to send slash packet for the double-sign infraction
// consumerKeeper.QueueSlashPacket(s.consumerCtx(), val, 3, stakingtypes.DoubleSign)

// // check that the packets were added to the list of pending data packets
// consumerPackets = consumerKeeper.GetPendingPackets(s.consumerCtx())
// s.Require().NotEmpty(consumerPackets)
// s.Require().Equal(4, len(consumerPackets.GetList()), "unexpected number of pending data packets")
addr := ed25519.GenPrivKey().PubKey().Address()
val := abci.Validator{Address: addr}
consumerKeeper.QueueSlashPacket(s.consumerCtx(), val, 2, stakingtypes.Downtime)
// try to send slash packet for the same downtime infraction
consumerKeeper.QueueSlashPacket(s.consumerCtx(), val, 3, stakingtypes.Downtime)
// try to send slash packet for the double-sign infraction
consumerKeeper.QueueSlashPacket(s.consumerCtx(), val, 3, stakingtypes.DoubleSign)

// check that the packets were added to the list of pending data packets
consumerPackets = consumerKeeper.GetPendingPackets(s.consumerCtx())
s.Require().NotEmpty(consumerPackets)
s.Require().Equal(4, len(consumerPackets.GetList()), "unexpected number of pending data packets")

// upgrade expired client to the consumer
upgradeExpiredClient(s, Provider)
Expand All @@ -149,7 +150,7 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() {
s.Require().Equal(0, len(consumerPackets.GetList()), "unexpected number of pending data packets")

// relay all packet from consumer to provider
relayAllCommittedPackets(s, s.consumerChain, s.path, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, 2)
relayAllCommittedPackets(s, s.consumerChain, s.path, ccv.ConsumerPortID, s.path.EndpointA.ChannelID, 4)

// check that everything works
// - bond more tokens on provider to change validator powers
Expand Down
40 changes: 20 additions & 20 deletions tests/e2e/throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,18 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() {
s.SetupAllCCVChannels()
s.setupValidatorPowers()

providerKeeper := s.providerApp.GetProviderKeeper()
providerStakingKeeper := s.providerApp.GetE2eStakingKeeper()

consumer := s.getFirstBundle()

// Use default params (incl replenish period), but set replenish fraction to tc value.
params := providertypes.DefaultParams()
params.SlashMeterReplenishFraction = tc.replenishFraction
s.providerApp.GetProviderKeeper().SetParams(s.providerCtx(), params)

// Elapse a replenish period and check for replenishment, so new param is fully in effect.
customCtx := s.getCtxWithReplenishPeriodElapsed(s.providerCtx())
providerKeeper.CheckForSlashMeterReplenishment(customCtx)
s.providerApp.GetProviderKeeper().CheckForSlashMeterReplenishment(customCtx)

slashMeter := providerKeeper.GetSlashMeter(s.providerCtx())
slashMeter := s.providerApp.GetProviderKeeper().GetSlashMeter(s.providerCtx())
s.Require().Equal(tc.expectedMeterBeforeFirstSlash, slashMeter.Int64())

// Assert that we start out with no jailings
Expand All @@ -63,7 +60,8 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() {
// Send a slash packet from consumer to provider
s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[0])
tmVal := s.providerChain.Vals.Validators[0]
sendOnConsumerRecvOnProvider(s, consumer.Path, s.constructSlashPacketFromConsumer(consumer, *tmVal, stakingtypes.Downtime, 1))
packet := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Downtime, 1)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, packet)

// Assert validator 0 is jailed and has no power
vals = providerStakingKeeper.GetAllValidators(s.providerCtx())
Expand All @@ -73,22 +71,23 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() {
s.Require().Equal(int64(0), lastValPower)

// Assert expected slash meter and allowance value
slashMeter = providerKeeper.GetSlashMeter(s.providerCtx())
slashMeter = s.providerApp.GetProviderKeeper().GetSlashMeter(s.providerCtx())
s.Require().Equal(tc.expectedMeterAfterFirstSlash, slashMeter.Int64())
s.Require().Equal(tc.expectedAllowanceAfterFirstSlash,
providerKeeper.GetSlashMeterAllowance(s.providerCtx()).Int64())
s.providerApp.GetProviderKeeper().GetSlashMeterAllowance(s.providerCtx()).Int64())

// Now send a second slash packet from consumer to provider for a different validator.
s.setDefaultValSigningInfo(*s.providerChain.Vals.Validators[2])
tmVal = s.providerChain.Vals.Validators[2]
sendOnConsumerRecvOnProvider(s, consumer.Path, s.constructSlashPacketFromConsumer(consumer, *tmVal, stakingtypes.Downtime, 2))
packet = s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmVal, stakingtypes.Downtime, 2)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, packet)

// Require that slash packet has not been handled
vals = providerStakingKeeper.GetAllValidators(s.providerCtx())
s.Require().False(vals[2].IsJailed())

// Assert slash meter value is still the same
slashMeter = providerKeeper.GetSlashMeter(s.providerCtx())
slashMeter = s.providerApp.GetProviderKeeper().GetSlashMeter(s.providerCtx())
s.Require().Equal(tc.expectedMeterAfterFirstSlash, slashMeter.Int64())

// Replenish slash meter until it is positive
Expand All @@ -98,9 +97,9 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() {
customCtx = s.getCtxWithReplenishPeriodElapsed(s.providerCtx())

// CheckForSlashMeterReplenishment should replenish meter here.
slashMeterBefore := providerKeeper.GetSlashMeter(s.providerCtx())
providerKeeper.CheckForSlashMeterReplenishment(customCtx)
slashMeter = providerKeeper.GetSlashMeter(s.providerCtx())
slashMeterBefore := s.providerApp.GetProviderKeeper().GetSlashMeter(s.providerCtx())
s.providerApp.GetProviderKeeper().CheckForSlashMeterReplenishment(customCtx)
slashMeter = s.providerApp.GetProviderKeeper().GetSlashMeter(s.providerCtx())
s.Require().True(slashMeter.GT(slashMeterBefore))

// Check that slash meter is still negative or 0,
Expand All @@ -111,7 +110,7 @@ func (s *CCVTestSuite) TestBasicSlashPacketThrottling() {
}

// Meter is positive at this point, and ready to handle the second slash packet.
slashMeter = providerKeeper.GetSlashMeter(s.providerCtx())
slashMeter = s.providerApp.GetProviderKeeper().GetSlashMeter(s.providerCtx())
s.Require().True(slashMeter.IsPositive())

// Assert validator 2 is jailed once pending slash packets are handled in ccv endblocker.
Expand Down Expand Up @@ -497,8 +496,7 @@ func (s *CCVTestSuite) TestSlashingSmallValidators() {

// Replenish slash meter with default params and new total voting power.
customCtx := s.getCtxWithReplenishPeriodElapsed(s.providerCtx())
providerKeeper := s.providerApp.GetProviderKeeper()
providerKeeper.CheckForSlashMeterReplenishment(customCtx)
s.providerApp.GetProviderKeeper().CheckForSlashMeterReplenishment(customCtx)

// Assert that we start out with no jailings
providerStakingKeeper := s.providerApp.GetE2eStakingKeeper()
Expand All @@ -516,10 +514,12 @@ func (s *CCVTestSuite) TestSlashingSmallValidators() {
tmval1 := s.providerChain.Vals.Validators[1]
tmval2 := s.providerChain.Vals.Validators[2]
tmval3 := s.providerChain.Vals.Validators[3]

sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval1, stakingtypes.DoubleSign, 1))
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.Downtime, 2))
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval3, stakingtypes.Downtime, 3))
packet1 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval1, stakingtypes.DoubleSign, 1)
packet2 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval2, stakingtypes.Downtime, 2)
packet3 := s.constructSlashPacketFromConsumer(s.getFirstBundle(), *tmval3, stakingtypes.Downtime, 3)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, packet1)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, packet2)
sendOnConsumerRecvOnProvider(s, s.getFirstBundle().Path, packet3)

// Default slash meter replenish fraction is 0.05, so all sent packets should be handled immediately.
vals = providerStakingKeeper.GetAllValidators(s.providerCtx())
Expand Down

0 comments on commit 7336dac

Please sign in to comment.