Skip to content

Commit

Permalink
Remove redundant e2e test code (#372)
Browse files Browse the repository at this point in the history
* for provider

* cool it works

Co-authored-by: Jehan <[email protected]>
  • Loading branch information
shaspitz and jtremback authored Oct 5, 2022
1 parent 92c44bb commit 1540617
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 456 deletions.
10 changes: 5 additions & 5 deletions tests/e2e/channel_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
)

func (suite *ConsumerKeeperTestSuite) TestConsumerGenesis() {
func (suite *CCVTestSuite) TestConsumerGenesis() {
genesis := suite.consumerChain.App.(*app.App).ConsumerKeeper.ExportGenesis(suite.consumerChain.GetContext())

suite.Require().Equal(suite.providerClient, genesis.ProviderClientState)
Expand Down Expand Up @@ -76,7 +76,7 @@ func (suite *ConsumerKeeperTestSuite) TestConsumerGenesis() {
providerChannel := suite.path.EndpointA.ChannelID
suite.Require().Equal(providerChannel, restartGenesis.ProviderChannelId)
maturityTime := suite.consumerChain.App.(*app.App).ConsumerKeeper.GetPacketMaturityTime(suite.consumerChain.GetContext(), 1)
unbondingPeriod, found := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.ctx)
unbondingPeriod, found := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(suite.consumerCtx())
suite.Require().True(found)
suite.Require().Equal(uint64(origTime.Add(unbondingPeriod).UnixNano()), maturityTime, "maturity time is not set correctly in genesis")

Expand All @@ -86,10 +86,10 @@ func (suite *ConsumerKeeperTestSuite) TestConsumerGenesis() {
}

// TestProviderClientMatches tests that the provider client managed by the consumer keeper matches the client keeper's client state
func (suite *ConsumerKeeperTestSuite) TestProviderClientMatches() {
providerClientID, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClientID(suite.ctx)
func (suite *CCVTestSuite) TestProviderClientMatches() {
providerClientID, ok := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClientID(suite.consumerCtx())
suite.Require().True(ok)

clientState, _ := suite.consumerChain.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.ctx, providerClientID)
clientState, _ := suite.consumerChain.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.consumerCtx(), providerClientID)
suite.Require().Equal(suite.providerClient, clientState, "stored client state does not match genesis provider client")
}
40 changes: 20 additions & 20 deletions tests/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ const (
Consumer
)

func (s *ProviderTestSuite) providerCtx() sdk.Context {
func (s *CCVTestSuite) providerCtx() sdk.Context {
return s.providerChain.GetContext()
}

func (s *ProviderTestSuite) consumerCtx() sdk.Context {
func (s *CCVTestSuite) consumerCtx() sdk.Context {
return s.consumerChain.GetContext()
}

func (s *ProviderTestSuite) providerBondDenom() string {
func (s *CCVTestSuite) providerBondDenom() string {
return s.providerChain.App.(*appProvider.App).StakingKeeper.BondDenom(s.providerCtx())
}

func (s *ProviderTestSuite) getVal(index int) (validator stakingtypes.Validator, valAddr sdk.ValAddress) {
func (s *CCVTestSuite) getVal(index int) (validator stakingtypes.Validator, valAddr sdk.ValAddress) {
// Choose a validator, and get its address and data structure into the correct types
tmValidator := s.providerChain.Vals.Validators[index]
valAddr, err := sdk.ValAddressFromHex(tmValidator.Address.String())
Expand All @@ -55,13 +55,13 @@ func (s *ProviderTestSuite) getVal(index int) (validator stakingtypes.Validator,
return validator, valAddr
}

func getBalance(s *ProviderTestSuite, providerCtx sdk.Context, delAddr sdk.AccAddress) sdk.Int {
func getBalance(s *CCVTestSuite, providerCtx sdk.Context, delAddr sdk.AccAddress) sdk.Int {
return s.providerChain.App.(*appProvider.App).BankKeeper.GetBalance(providerCtx, delAddr, s.providerBondDenom()).Amount
}

// delegateAndUndelegate delegates bondAmt from delAddr to the first validator
// and then immediately undelegates 1/shareDiv of that delegation
func delegateAndUndelegate(s *ProviderTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int, shareDiv int64) (initBalance sdk.Int, valsetUpdateId uint64) {
func delegateAndUndelegate(s *CCVTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int, shareDiv int64) (initBalance sdk.Int, valsetUpdateId uint64) {
// delegate
initBalance, shares, valAddr := delegate(s, delAddr, bondAmt)

Expand All @@ -82,7 +82,7 @@ func delegateAndUndelegate(s *ProviderTestSuite, delAddr sdk.AccAddress, bondAmt
//
// Note: This function advances blocks in-between operations, where validator powers are
// not checked, since they are checked in integration tests.
func delegateAndRedelegate(s *ProviderTestSuite, delAddr sdk.AccAddress,
func delegateAndRedelegate(s *CCVTestSuite, delAddr sdk.AccAddress,
srcValAddr sdk.ValAddress, dstValAddr sdk.ValAddress, amount sdk.Int) {

stakingKeeper := s.providerChain.App.(*appProvider.App).StakingKeeper
Expand Down Expand Up @@ -115,7 +115,7 @@ func delegateAndRedelegate(s *ProviderTestSuite, delAddr sdk.AccAddress,
}

// delegate delegates bondAmt to the first validator
func delegate(s *ProviderTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) (initBalance sdk.Int, shares sdk.Dec, valAddr sdk.ValAddress) {
func delegate(s *CCVTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) (initBalance sdk.Int, shares sdk.Dec, valAddr sdk.ValAddress) {
initBalance = getBalance(s, s.providerCtx(), delAddr)
// choose a validator
validator, valAddr := s.getVal(0)
Expand All @@ -135,7 +135,7 @@ func delegate(s *ProviderTestSuite, delAddr sdk.AccAddress, bondAmt sdk.Int) (in
}

// undelegate unbonds an amount of delegator shares from a given validator
func undelegate(s *ProviderTestSuite, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) (valsetUpdateId uint64) {
func undelegate(s *CCVTestSuite, delAddr sdk.AccAddress, valAddr sdk.ValAddress, sharesAmount sdk.Dec) (valsetUpdateId uint64) {
_, err := s.providerChain.App.(*appProvider.App).StakingKeeper.Undelegate(s.providerCtx(), delAddr, valAddr, sharesAmount)
s.Require().NoError(err)

Expand All @@ -147,7 +147,7 @@ func undelegate(s *ProviderTestSuite, delAddr sdk.AccAddress, valAddr sdk.ValAdd

// Executes a BeginRedelegation (unbonding and redelegation) operation
// on the provider chain using delegated funds from delAddr
func redelegate(s *ProviderTestSuite, delAddr sdk.AccAddress, valSrcAddr sdk.ValAddress,
func redelegate(s *CCVTestSuite, delAddr sdk.AccAddress, valSrcAddr sdk.ValAddress,
ValDstAddr sdk.ValAddress, sharesAmount sdk.Dec) {
ctx := s.providerCtx()

Expand Down Expand Up @@ -179,7 +179,7 @@ func redelegate(s *ProviderTestSuite, delAddr sdk.AccAddress, valSrcAddr sdk.Val

// relayAllCommittedPackets relays all committed packets from `srcChain` on `path`
func relayAllCommittedPackets(
s *ProviderTestSuite,
s *CCVTestSuite,
srcChain *ibctesting.TestChain,
path *ibctesting.Path,
portID string,
Expand Down Expand Up @@ -212,7 +212,7 @@ func relayAllCommittedPackets(
//
// Note that it is expected for the provider unbonding period
// to be one day larger than the consumer unbonding period.
func incrementTimeByUnbondingPeriod(s *ProviderTestSuite, chainType ChainType) {
func incrementTimeByUnbondingPeriod(s *CCVTestSuite, chainType ChainType) {
// Get unboding period from staking keeper
providerUnbondingPeriod := s.providerChain.App.GetStakingKeeper().UnbondingTime(s.providerCtx())
consumerUnbondingPeriod, found := s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(s.consumerCtx())
Expand All @@ -239,13 +239,13 @@ func incrementTimeByUnbondingPeriod(s *ProviderTestSuite, chainType ChainType) {
}
}

func checkStakingUnbondingOps(s *ProviderTestSuite, id uint64, found bool, onHold bool) {
func checkStakingUnbondingOps(s *CCVTestSuite, id uint64, found bool, onHold bool) {
stakingUnbondingOp, wasFound := getStakingUnbondingDelegationEntry(s.providerCtx(), s.providerChain.App.(*appProvider.App).StakingKeeper, id)
s.Require().True(found == wasFound)
s.Require().True(onHold == (0 < stakingUnbondingOp.UnbondingOnHoldRefCount))
}

func checkCCVUnbondingOp(s *ProviderTestSuite, providerCtx sdk.Context, chainID string, valUpdateID uint64, found bool) {
func checkCCVUnbondingOp(s *CCVTestSuite, providerCtx sdk.Context, chainID string, valUpdateID uint64, found bool) {
entries, wasFound := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetUnbondingOpsFromIndex(providerCtx, chainID, valUpdateID)
s.Require().True(found == wasFound)
if found {
Expand All @@ -257,7 +257,7 @@ func checkCCVUnbondingOp(s *ProviderTestSuite, providerCtx sdk.Context, chainID

// Checks that an expected amount of redelegations exist for a delegator
// via the staking keeper, then returns those redelegations.
func checkRedelegations(s *ProviderTestSuite, delAddr sdk.AccAddress,
func checkRedelegations(s *CCVTestSuite, delAddr sdk.AccAddress,
expect uint16) []stakingtypes.Redelegation {

redelegations := s.providerChain.App.(*appProvider.App).StakingKeeper.
Expand All @@ -269,7 +269,7 @@ func checkRedelegations(s *ProviderTestSuite, delAddr sdk.AccAddress,

// Checks that a redelegation entry has a completion time equal to an expected time
func checkRedelegationEntryCompletionTime(
s *ProviderTestSuite, entry stakingtypes.RedelegationEntry, expectedCompletion time.Time) {
s *CCVTestSuite, entry stakingtypes.RedelegationEntry, expectedCompletion time.Time) {
s.Require().Equal(expectedCompletion, entry.CompletionTime)
}

Expand All @@ -289,7 +289,7 @@ func getStakingUnbondingDelegationEntry(ctx sdk.Context, k stakingkeeper.Keeper,

// SendEmptyVSCPacket sends a VSC packet without any changes
// to ensure that the channel gets established
func (suite *ConsumerKeeperTestSuite) SendEmptyVSCPacket() {
func (suite *CCVTestSuite) SendEmptyVSCPacket() {
providerKeeper := suite.providerChain.App.(*appProvider.App).ProviderKeeper

oldBlockTime := suite.providerChain.GetContext().BlockTime()
Expand Down Expand Up @@ -318,7 +318,7 @@ func (suite *ConsumerKeeperTestSuite) SendEmptyVSCPacket() {

// commitSlashPacket returns a commit hash for the given slash packet data
// Note that it must be called before sending the embedding IBC packet.
func (suite *ConsumerKeeperTestSuite) commitSlashPacket(ctx sdk.Context, packetData ccv.SlashPacketData) []byte {
func (suite *CCVTestSuite) commitSlashPacket(ctx sdk.Context, packetData ccv.SlashPacketData) []byte {
oldBlockTime := ctx.BlockTime()
timeout := uint64(ccv.GetTimeoutTimestamp(oldBlockTime).UnixNano())

Expand All @@ -329,7 +329,7 @@ func (suite *ConsumerKeeperTestSuite) commitSlashPacket(ctx sdk.Context, packetD
}

// incrementTimeBy increments the overall time by jumpPeriod
func incrementTimeBy(s *ConsumerKeeperTestSuite, jumpPeriod time.Duration) {
func incrementTimeBy(s *CCVTestSuite, jumpPeriod time.Duration) {
// Get unboding period from staking keeper
consumerUnbondingPeriod, found := s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetUnbondingTime(s.consumerChain.GetContext())
s.Require().True(found)
Expand All @@ -356,7 +356,7 @@ func incrementTimeBy(s *ConsumerKeeperTestSuite, jumpPeriod time.Duration) {
// using the given unbonding period.
// It will update the clientID for the endpoint if the message
// is successfully executed.
func (suite *ConsumerKeeperTestSuite) CreateCustomClient(endpoint *ibctesting.Endpoint, unbondingPeriod time.Duration) {
func (suite *CCVTestSuite) CreateCustomClient(endpoint *ibctesting.Endpoint, unbondingPeriod time.Duration) {
// ensure counterparty has committed state
endpoint.Chain.Coordinator.CommitBlock(endpoint.Counterparty.Chain)

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
)

//This test is valid for minimal viable consumer chain
func (s *ProviderTestSuite) TestRewardsDistribution() {
func (s *CCVTestSuite) TestRewardsDistribution() {

//set up channel and delegate some tokens in order for validator set update to be sent to the consumer chain
s.SetupCCVChannel()
s.SetupTransferChannel()
bondAmt := sdk.NewInt(10000000)
delAddr := s.providerChain.SenderAccount.GetAddress()
delegate(s, delAddr, bondAmt)
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/normal_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// Tests the tracking of historical info in the context of new blocks being committed
func (k ConsumerKeeperTestSuite) TestTrackHistoricalInfo() {
func (k CCVTestSuite) TestTrackHistoricalInfo() {
consumerKeeper := k.consumerChain.App.(*appConsumer.App).ConsumerKeeper
cCtx := k.consumerChain.GetContext

Expand All @@ -19,7 +19,7 @@ func (k ConsumerKeeperTestSuite) TestTrackHistoricalInfo() {

// define an utility function that creates a new cross-chain validator
// and then call track historical info in the next block
createVal := func(k ConsumerKeeperTestSuite) {
createVal := func(k CCVTestSuite) {
// add new validator to consumer states
pk := ed25519.GenPrivKey().PubKey()
cVal, err := types.NewCCValidator(pk.Address(), int64(1), pk)
Expand All @@ -35,10 +35,10 @@ func (k ConsumerKeeperTestSuite) TestTrackHistoricalInfo() {
// increased by HistoricalEntries in order to prune the historical info less or equal to the current block height
// Note that historical info containing the created validators are stored during the next block BeginBlocker
// and thus are indexed with the respective block heights InitHeight+1 and InitHeight+2
testSetup := []func(ConsumerKeeperTestSuite){
testSetup := []func(CCVTestSuite){
createVal,
createVal,
func(k ConsumerKeeperTestSuite) {
func(k CCVTestSuite) {
newHeight := k.consumerChain.GetContext().BlockHeight() + int64(types.HistoricalEntries)
header := tmproto.Header{
ChainID: "HelloChain",
Expand Down
Loading

0 comments on commit 1540617

Please sign in to comment.