Skip to content

Commit

Permalink
refactor nextBlocks(epoch) to nextEpoch
Browse files Browse the repository at this point in the history
  • Loading branch information
insumity committed Mar 1, 2024
1 parent 2208cd4 commit 914840c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 40 deletions.
12 changes: 7 additions & 5 deletions tests/integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func delegateAndRedelegate(s *CCVTestSuite, delAddr sdk.AccAddress,
srcValTokensAfter := s.getVal(s.providerCtx(), srcValAddr).GetBondedTokens()
s.Require().Equal(srcValTokensAfter.Sub(srcValTokensBefore), amount)

nextBlocks(s.providerChain, s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch)
s.nextEpoch()

dstValTokensBefore := s.getVal(s.providerCtx(), dstValAddr).GetBondedTokens()

Expand Down Expand Up @@ -626,9 +626,11 @@ func (s *CCVTestSuite) mustGetStakingValFromTmVal(tmVal tmtypes.Validator) (stak
return stakingVal
}

// nextBlocks moves `chain` forward by a `numberOfBlocks` blocks
func nextBlocks(chain *ibctesting.TestChain, numberOfBlocks int64) {
for i := int64(0); i < numberOfBlocks; i++ {
chain.NextBlock()
// nextEpoch moves `chain` forward by an epoch
func (s *CCVTestSuite) nextEpoch() {
blocksPerEpoch := s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch

for i := int64(0); i < blocksPerEpoch; i++ {
s.providerChain.NextBlock()
}
}
6 changes: 3 additions & 3 deletions tests/integration/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() {
bondAmt := sdk.NewInt(10000000)
delAddr := s.providerChain.SenderAccount.GetAddress()
delegate(s, delAddr, bondAmt)
nextBlocks(s.providerChain, s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch)
s.nextEpoch()

// register a consumer reward denom
params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
Expand Down Expand Up @@ -124,7 +124,7 @@ func (s *CCVTestSuite) TestSendRewardsRetries() {
bondAmt := sdk.NewInt(10000000)
delAddr := s.providerChain.SenderAccount.GetAddress()
delegate(s, delAddr, bondAmt)
nextBlocks(s.providerChain, s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch)
s.nextEpoch()

// Register denom on consumer chain
params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
Expand Down Expand Up @@ -253,7 +253,7 @@ func (s *CCVTestSuite) TestEndBlockRD() {
bondAmt := sdk.NewInt(10000000)
delAddr := s.providerChain.SenderAccount.GetAddress()
delegate(s, delAddr, bondAmt)
nextBlocks(s.providerChain, s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch)
s.nextEpoch()

if tc.denomRegistered {
params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx())
Expand Down
16 changes: 7 additions & 9 deletions tests/integration/expired_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ func (s *CCVTestSuite) TestVSCPacketSendExpiredClient() {
delegate(s, delAddr, bondAmt)

// try to send CCV packet to consumer
blocksPerEpoch := s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

// check that the packet was added to the list of pending VSC packets
packets := providerKeeper.GetPendingVSCPackets(s.providerCtx(), s.consumerChain.ChainID)
s.Require().NotEmpty(packets, "no pending VSC packets found")
s.Require().Equal(1, len(packets), "unexpected number of pending VSC packets")

// try again to send CCV packet to consumer
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

// check that the packet is still in the list of pending VSC packets
packets = providerKeeper.GetPendingVSCPackets(s.providerCtx(), s.consumerChain.ChainID)
Expand All @@ -53,7 +52,7 @@ func (s *CCVTestSuite) TestVSCPacketSendExpiredClient() {
delegate(s, delAddr, bondAmt)

// try again to send CCV packets to consumer
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

// check that the packets are still in the list of pending VSC packets
packets = providerKeeper.GetPendingVSCPackets(s.providerCtx(), s.consumerChain.ChainID)
Expand All @@ -64,7 +63,7 @@ func (s *CCVTestSuite) TestVSCPacketSendExpiredClient() {
upgradeExpiredClient(s, Consumer)

// go to next epoch
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

// check that the packets are not in the list of pending VSC packets
packets = providerKeeper.GetPendingVSCPackets(s.providerCtx(), s.consumerChain.ChainID)
Expand All @@ -74,7 +73,7 @@ func (s *CCVTestSuite) TestVSCPacketSendExpiredClient() {
// - bond more tokens on provider to change validator powers
delegate(s, delAddr, bondAmt)
// - send CCV packet to consumer
nextBlocks(s.providerChain, blocksPerEpoch)
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
Expand Down Expand Up @@ -103,8 +102,7 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() {
delegate(s, delAddr, bondAmt)

// send CCV packets to consumer
blocksPerEpoch := s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

// check that the packets are not in the list of pending VSC packets
providerPackets := providerKeeper.GetPendingVSCPackets(s.providerCtx(), s.consumerChain.ChainID)
Expand Down Expand Up @@ -174,7 +172,7 @@ func (s *CCVTestSuite) TestConsumerPacketSendExpiredClient() {
// - bond more tokens on provider to change validator powers
delegate(s, delAddr, bondAmt)
// - send CCV packet to consumer
nextBlocks(s.providerChain, blocksPerEpoch)
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
Expand Down
19 changes: 9 additions & 10 deletions tests/integration/key_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

func (s *CCVTestSuite) TestKeyAssignment() {
blocksPerEpoch := s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch
testCases := []struct {
name string
assignFunc func(*providerkeeper.Keeper) error
Expand All @@ -31,7 +30,7 @@ func (s *CCVTestSuite) TestKeyAssignment() {
}

// check that a VSCPacket is queued
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()
pendingPackets := pk.GetPendingVSCPackets(s.providerCtx(), s.consumerChain.ChainID)
s.Require().Len(pendingPackets, 1)

Expand All @@ -52,7 +51,7 @@ func (s *CCVTestSuite) TestKeyAssignment() {
if err != nil {
return err
}
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

return nil
}, false, 2,
Expand All @@ -74,7 +73,7 @@ func (s *CCVTestSuite) TestKeyAssignment() {
delAddr := s.providerChain.SenderAccount.GetAddress()
delegate(s, delAddr, bondAmt)

nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

return nil
}, false, 2,
Expand All @@ -96,7 +95,7 @@ func (s *CCVTestSuite) TestKeyAssignment() {
if err != nil {
return err
}
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

return nil
}, true, 2,
Expand All @@ -119,7 +118,7 @@ func (s *CCVTestSuite) TestKeyAssignment() {
if err != nil {
return err
}
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

return nil
}, false, 2,
Expand All @@ -135,14 +134,14 @@ func (s *CCVTestSuite) TestKeyAssignment() {
if err != nil {
return err
}
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

// same key assignment
err = pk.AssignConsumerKey(s.providerCtx(), s.consumerChain.ChainID, validator, consumerKey)
if err != nil {
return err
}
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

return nil
}, true, 2,
Expand All @@ -158,15 +157,15 @@ func (s *CCVTestSuite) TestKeyAssignment() {
if err != nil {
return err
}
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

// same key assignment
validator, consumerKey = generateNewConsumerKey(s, 0)
err = pk.AssignConsumerKey(s.providerCtx(), s.consumerChain.ChainID, validator, consumerKey)
if err != nil {
return err
}
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

return nil
}, false, 3,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *CCVTestSuite) TestRelayAndApplyDowntimePacket() {
s.Require().True(found)
}

nextBlocks(s.providerChain, s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch)
s.nextEpoch()

// Confirm the valset update Id was incremented twice on provider,
// since an epoch has passed.
Expand Down
8 changes: 3 additions & 5 deletions tests/integration/soft_opt_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
func (suite *CCVTestSuite) TestSoftOptOut() {
var votes []abci.VoteInfo

blocksPerEpoch := suite.providerApp.GetProviderKeeper().GetParams(suite.providerCtx()).BlocksPerEpoch

testCases := []struct {
name string
downtimeFunc func(*consumerKeeper.Keeper, *slashingkeeper.Keeper, []byte, int)
Expand Down Expand Up @@ -75,7 +73,7 @@ func (suite *CCVTestSuite) TestSoftOptOut() {
bondAmt := sdk.NewInt(100).Mul(sdk.DefaultPowerReduction)
delegateByIdx(suite, delAddr, bondAmt, valIdx)

nextBlocks(suite.providerChain, blocksPerEpoch)
suite.nextEpoch()

// Relay 1 VSC packet from provider to consumer
relayAllCommittedPackets(suite, suite.providerChain, suite.path, ccv.ProviderPortID, suite.path.EndpointB.ChannelID, 1)
Expand Down Expand Up @@ -114,7 +112,7 @@ func (suite *CCVTestSuite) TestSoftOptOut() {
bondAmt := sdk.NewInt(100).Mul(sdk.DefaultPowerReduction)
delegateByIdx(suite, delAddr, bondAmt, valIdx)

nextBlocks(suite.providerChain, blocksPerEpoch)
suite.nextEpoch()

// Relay 1 VSC packet from provider to consumer
relayAllCommittedPackets(suite, suite.providerChain, suite.path, ccv.ProviderPortID, suite.path.EndpointB.ChannelID, 1)
Expand Down Expand Up @@ -151,7 +149,7 @@ func (suite *CCVTestSuite) TestSoftOptOut() {
validatorPowers := []int64{1000, 500, 50, 10}
suite.setupValidatorPowers(validatorPowers)

nextBlocks(suite.providerChain, blocksPerEpoch)
suite.nextEpoch()

// Relay 1 VSC packet from provider to consumer
relayAllCommittedPackets(suite, suite.providerChain, suite.path, ccv.ProviderPortID, suite.path.EndpointB.ChannelID, 1)
Expand Down
10 changes: 4 additions & 6 deletions tests/integration/unbonding.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ func (s *CCVTestSuite) TestUndelegationDuringInit() {
// update init timeout timestamp
tc.updateInitTimeoutTimestamp(&providerKeeper, providerUnbondingPeriod)

blocksPerEpoch := s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

// check that the VSC packet is stored in state as pending
pendingVSCs := providerKeeper.GetPendingVSCPackets(s.providerCtx(), s.consumerChain.ChainID)
Expand All @@ -241,8 +240,7 @@ func (s *CCVTestSuite) TestUndelegationDuringInit() {
// delegate again to create another VSC packet
delegate(s, delAddr, bondAmt)

// call NextBlocks on the provider (which increments the height)
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

// check that the VSC packet is stored in state as pending
pendingVSCs = providerKeeper.GetPendingVSCPackets(s.providerCtx(), s.consumerChain.ChainID)
Expand All @@ -266,7 +264,7 @@ func (s *CCVTestSuite) TestUndelegationDuringInit() {

// complete CCV channel setup
s.SetupCCVChannel(s.path)
nextBlocks(s.providerChain, blocksPerEpoch)
s.nextEpoch()

// relay VSC packets from provider to consumer
relayAllCommittedPackets(s, s.providerChain, s.path, ccv.ProviderPortID, s.path.EndpointB.ChannelID, 2)
Expand Down Expand Up @@ -431,7 +429,7 @@ func (s *CCVTestSuite) TestRedelegationProviderFirst() {
checkCCVUnbondingOp(s, s.providerCtx(), s.consumerChain.ChainID, valsetUpdateID, true)

// move forward by an epoch to be able to relay VSC packets
nextBlocks(s.providerChain, s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch)
s.nextEpoch()

// Relay 2 VSC packets from provider to consumer (original delegation, and redelegation)
relayAllCommittedPackets(s, s.providerChain, s.path,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/valset_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (s *CCVTestSuite) TestPacketRoundtrip() {
delegate(s, delAddr, bondAmt)

// Send CCV packet to consumer at the end of the epoch
nextBlocks(s.providerChain, s.providerApp.GetProviderKeeper().GetParams(s.providerCtx()).BlocksPerEpoch)
s.nextEpoch()

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

0 comments on commit 914840c

Please sign in to comment.