Skip to content

Commit

Permalink
tests: fix integration test setup (#2183)
Browse files Browse the repository at this point in the history
* fix integration test setup

* fix integration tests
  • Loading branch information
mpoke authored Aug 28, 2024
1 parent a9b39dd commit 289e05c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 228 deletions.
2 changes: 1 addition & 1 deletion tests/integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *CCVTestSuite) getFirstBundle() icstestingutils.ConsumerBundle {
}

func (s *CCVTestSuite) getBundleByIdx(index int) icstestingutils.ConsumerBundle {
return *s.consumerBundles[fmt.Sprintf("%d", 2+index)]
return *s.consumerBundles[fmt.Sprintf("%d", index)]
}

func (s *CCVTestSuite) providerCtx() sdk.Context {
Expand Down
178 changes: 0 additions & 178 deletions tests/integration/provider_gov_hooks.go

This file was deleted.

7 changes: 3 additions & 4 deletions tests/integration/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ func (suite *CCVTestSuite) SetupTest() {
// 1. the consumer chain is added to the coordinator
// 2. MakeGenesis is called on the provider chain
// 3. ibc/testing sets the tendermint header for the consumer chain app

providerKeeper.SetConsumerPhase(suite.providerCtx(), icstestingutils.FirstConsumerId, providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)
preProposalKeyAssignment(suite, icstestingutils.FirstConsumerId)
providerKeeper.SetConsumerPhase(suite.providerCtx(), icstestingutils.FirstConsumerID, providertypes.ConsumerPhase_CONSUMER_PHASE_INITIALIZED)
preProposalKeyAssignment(suite, icstestingutils.FirstConsumerID)

// start consumer chains
suite.consumerBundles = make(map[string]*icstestingutils.ConsumerBundle)
Expand Down Expand Up @@ -284,7 +283,7 @@ func initConsumerChain(
err = bundle.Path.EndpointA.UpdateClient()
s.Require().NoError(err)

if consumerId == "2" {
if consumerId == "0" {
// Support tests that were written before multiple consumers were supported.
firstBundle := s.getFirstBundle()
s.consumerApp = firstBundle.App
Expand Down
18 changes: 11 additions & 7 deletions testutil/ibc_testing/generic_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const (
)

var (
FirstConsumerId string
firstConsumerChainID string
FirstConsumerID string
provChainID string
democConsumerChainID string
consumerTopNParams [NumConsumers]uint32
Expand All @@ -47,7 +48,8 @@ var (
func init() {
// Disable revision format
ibctesting.ChainIDSuffix = ""
FirstConsumerId = "2"
firstConsumerChainID = ibctesting.GetChainID(2)
FirstConsumerID = ""
provChainID = ibctesting.GetChainID(1)
democConsumerChainID = ibctesting.GetChainID(5000)
// TopN parameter values per consumer chain initiated
Expand Down Expand Up @@ -153,7 +155,10 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
powerShapingParameters := testkeeper.GetTestPowerShapingParameters()
powerShapingParameters.Top_N = consumerTopNParams[index] // isn't used in CreateConsumerClient

consumerId := fmt.Sprintf("%d", index+2)
consumerId := providerKeeper.FetchAndIncrementConsumerId(providerChain.GetContext())
if chainID == firstConsumerChainID {
FirstConsumerID = consumerId
}
providerKeeper.SetConsumerChainId(providerChain.GetContext(), consumerId, chainID)
providerKeeper.SetConsumerMetadata(providerChain.GetContext(), consumerId, consumerMetadata)
providerKeeper.SetConsumerInitializationParameters(providerChain.GetContext(), consumerId, initializationParameters)
Expand All @@ -180,14 +185,13 @@ func AddConsumer[Tp testutil.ProviderApp, Tc testutil.ConsumerApp](
providerChain.GetContext(),
consumerId,
)
s.Require().True(found, "consumer genesis not found in AddConsumer")

foo, found := providerKeeper.GetConsumerClientId(
_, found = providerKeeper.GetConsumerClientId(
providerChain.GetContext(),
consumerId,
)
_ = foo

s.Require().True(found, "consumer genesis not found in AddConsumer")
s.Require().True(found, "clientID not found in AddConsumer")

// use InitialValSet as the valset on the consumer
var valz []*tmtypes.Validator
Expand Down
45 changes: 7 additions & 38 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,18 @@ func GetTestConsumerMetadata() providertypes.ConsumerMetadata {
}

func GetTestInitializationParameters() providertypes.ConsumerInitializationParameters {
initialHeight := clienttypes.NewHeight(4, 5)
spawnTime := time.Now().UTC()
ccvTimeoutPeriod := types.DefaultCCVTimeoutPeriod
transferTimeoutPeriod := types.DefaultTransferTimeoutPeriod
unbondingPeriod := types.DefaultConsumerUnbondingPeriod
return providertypes.ConsumerInitializationParameters{
InitialHeight: initialHeight,
InitialHeight: clienttypes.NewHeight(4, 5),
GenesisHash: []byte("gen_hash"),
BinaryHash: []byte("bin_hash"),
SpawnTime: spawnTime,
SpawnTime: time.Now().UTC(),

Check warning

Code scanning / CodeQL

Calling the system time Warning test

Calling the system time may be a possible source of non-determinism
ConsumerRedistributionFraction: types.DefaultConsumerRedistributeFrac,
BlocksPerDistributionTransmission: types.DefaultBlocksPerDistributionTransmission,
DistributionTransmissionChannel: "",
HistoricalEntries: types.DefaultHistoricalEntries,
CcvTimeoutPeriod: ccvTimeoutPeriod,
TransferTimeoutPeriod: transferTimeoutPeriod,
UnbondingPeriod: unbondingPeriod,
CcvTimeoutPeriod: types.DefaultCCVTimeoutPeriod,
TransferTimeoutPeriod: types.DefaultTransferTimeoutPeriod,
UnbondingPeriod: types.DefaultConsumerUnbondingPeriod,
}
}

Expand All @@ -309,37 +304,11 @@ func GetTestPowerShapingParameters() providertypes.PowerShapingParameters {
ValidatorSetCap: 0,
Allowlist: nil,
Denylist: nil,
MinStake: 0,
AllowInactiveVals: false,
}
}

func GetTestConsumerAdditionProp() *providertypes.ConsumerAdditionProposal {
prop := providertypes.NewConsumerAdditionProposal(
"chainID",
"description",
"chainID",
clienttypes.NewHeight(4, 5),
[]byte("gen_hash"),
[]byte("bin_hash"),
time.Now(),
types.DefaultConsumerRedistributeFrac,
types.DefaultBlocksPerDistributionTransmission,
"",
types.DefaultHistoricalEntries,
types.DefaultCCVTimeoutPeriod,
types.DefaultTransferTimeoutPeriod,
types.DefaultConsumerUnbondingPeriod,
0,
0,
0,
nil,
nil,
0,
false,
).(*providertypes.ConsumerAdditionProposal)

return prop
}

func GetTestMsgUpdateConsumer() providertypes.MsgUpdateConsumer {
return providertypes.MsgUpdateConsumer{
Signer: "signer",
Expand Down

0 comments on commit 289e05c

Please sign in to comment.