From b6851c85f1e6abd86981db50a2bcc1384710e1c4 Mon Sep 17 00:00:00 2001 From: Shawn Marshall-Spitzbart <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Wed, 5 Oct 2022 22:43:06 -0700 Subject: [PATCH 1/6] remove dup setup --- tests/e2e/democracy_test.go | 179 +++--------------------------------- tests/e2e/setup_test.go | 30 +++++- 2 files changed, 41 insertions(+), 168 deletions(-) diff --git a/tests/e2e/democracy_test.go b/tests/e2e/democracy_test.go index 68445c618e..a7c0f71701 100644 --- a/tests/e2e/democracy_test.go +++ b/tests/e2e/democracy_test.go @@ -1,17 +1,13 @@ package e2e_test import ( - "bytes" "fmt" "strconv" "testing" "time" sdk "github.com/cosmos/cosmos-sdk/types" - transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" - clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" - channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -22,14 +18,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/params/types/proposal" proposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" appConsumer "github.com/cosmos/interchain-security/app/consumer-democracy" - appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/testutil/simapp" consumerkeeper "github.com/cosmos/interchain-security/x/ccv/consumer/keeper" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" - "github.com/cosmos/interchain-security/x/ccv/types" - "github.com/cosmos/interchain-security/x/ccv/utils" - - tmtypes "github.com/tendermint/tendermint/types" "github.com/stretchr/testify/suite" ) @@ -37,161 +28,27 @@ import ( var consumerFraction, _ = sdk.NewDecFromStr(consumerkeeper.ConsumerRedistributeFrac) type ConsumerDemocracyTestSuite struct { + underlyingSuite CCVTestSuite suite.Suite - - coordinator *ibctesting.Coordinator - - // testing chains - providerChain *ibctesting.TestChain - consumerChain *ibctesting.TestChain - - path *ibctesting.Path - transferPath *ibctesting.Path -} - -func (s *ConsumerDemocracyTestSuite) SetupTest() { - s.coordinator, s.providerChain, s.consumerChain = simapp.NewProviderConsumerDemocracyCoordinator(s.T()) - - // valsets must match - providerValUpdates := tmtypes.TM2PB.ValidatorUpdates(s.providerChain.Vals) - consumerValUpdates := tmtypes.TM2PB.ValidatorUpdates(s.consumerChain.Vals) - s.Require().True(len(providerValUpdates) == len(consumerValUpdates), "initial valset not matching") - for i := 0; i < len(providerValUpdates); i++ { - addr1 := utils.GetChangePubKeyAddress(providerValUpdates[i]) - addr2 := utils.GetChangePubKeyAddress(consumerValUpdates[i]) - s.Require().True(bytes.Equal(addr1, addr2), "validator mismatch") - } - - // move both chains to the next block - s.providerChain.NextBlock() - s.consumerChain.NextBlock() - - // create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper. - err := s.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient( - s.providerCtx(), - s.consumerChain.ChainID, - s.consumerChain.LastHeader.GetHeight().(clienttypes.Height), - false, - ) - s.Require().NoError(err) - - // move provider to next block to commit the state - s.providerChain.NextBlock() - - // initialize the consumer chain with the genesis state stored on the provider - consumerGenesis, found := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerGenesis( - s.providerCtx(), - s.consumerChain.ChainID, - ) - s.Require().True(found, "consumer genesis not found") - s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.InitGenesis(s.consumerChain.GetContext(), &consumerGenesis) - - // create path for the CCV channel - s.path = ibctesting.NewPath(s.consumerChain, s.providerChain) - - // update CCV path with correct info - // - set provider endpoint's clientID - consumerClient, found := s.providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerClientId( - s.providerCtx(), - s.consumerChain.ChainID, - ) - s.Require().True(found, "consumer client not found") - s.path.EndpointB.ClientID = consumerClient - // - set consumer endpoint's clientID - providerClient, found := s.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClientID(s.consumerChain.GetContext()) - s.Require().True(found, "provider client not found") - s.path.EndpointA.ClientID = providerClient - // - client config - providerUnbondingPeriod := s.providerChain.App.(*appProvider.App).GetStakingKeeper().UnbondingTime(s.providerCtx()) - s.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = providerUnbondingPeriod - s.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = providerUnbondingPeriod / utils.TrustingPeriodFraction - consumerUnbondingPeriod := utils.ComputeConsumerUnbondingPeriod(providerUnbondingPeriod) - s.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = consumerUnbondingPeriod - s.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = consumerUnbondingPeriod / utils.TrustingPeriodFraction - // - channel config - s.path.EndpointA.ChannelConfig.PortID = types.ConsumerPortID - s.path.EndpointB.ChannelConfig.PortID = types.ProviderPortID - s.path.EndpointA.ChannelConfig.Version = types.Version - s.path.EndpointB.ChannelConfig.Version = types.Version - s.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED - s.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED - - // set chains sender account number - // TODO: to be fixed in #151 - err = s.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6) - s.Require().NoError(err) - err = s.path.EndpointA.Chain.SenderAccount.SetAccountNumber(0) - s.Require().NoError(err) - - // create path for the transfer channel - s.transferPath = ibctesting.NewPath(s.consumerChain, s.providerChain) - s.transferPath.EndpointA.ChannelConfig.PortID = transfertypes.PortID - s.transferPath.EndpointB.ChannelConfig.PortID = transfertypes.PortID - s.transferPath.EndpointA.ChannelConfig.Version = transfertypes.Version - s.transferPath.EndpointB.ChannelConfig.Version = transfertypes.Version -} - -func (s *ConsumerDemocracyTestSuite) SetupCCVChannel() { - s.StartSetupCCVChannel() - s.CompleteSetupCCVChannel() - s.SetupTransferChannel() -} - -func (s *ConsumerDemocracyTestSuite) StartSetupCCVChannel() { - s.coordinator.CreateConnections(s.path) - - err := s.path.EndpointA.ChanOpenInit() - s.Require().NoError(err) - - err = s.path.EndpointB.ChanOpenTry() - s.Require().NoError(err) } -func (s *ConsumerDemocracyTestSuite) CompleteSetupCCVChannel() { - err := s.path.EndpointA.ChanOpenAck() - s.Require().NoError(err) - - err = s.path.EndpointB.ChanOpenConfirm() - s.Require().NoError(err) - - // ensure counterparty is up to date - err = s.path.EndpointA.UpdateClient() - s.Require().NoError(err) -} - -func (s *ConsumerDemocracyTestSuite) SetupTransferChannel() { - // transfer path will use the same connection as ccv path - - s.transferPath.EndpointA.ClientID = s.path.EndpointA.ClientID - s.transferPath.EndpointA.ConnectionID = s.path.EndpointA.ConnectionID - s.transferPath.EndpointB.ClientID = s.path.EndpointB.ClientID - s.transferPath.EndpointB.ConnectionID = s.path.EndpointB.ConnectionID - - // CCV channel handshake will automatically initiate transfer channel handshake on ACK - // so transfer channel will be on stage INIT when CompleteSetupCCVChannel returns. - s.transferPath.EndpointA.ChannelID = s.consumerChain.App.(*appConsumer.App). - ConsumerKeeper.GetDistributionTransmissionChannel(s.consumerChain.GetContext()) - - // Complete TRY, ACK, CONFIRM for transfer path - err := s.transferPath.EndpointB.ChanOpenTry() - s.Require().NoError(err) - - err = s.transferPath.EndpointA.ChanOpenAck() - s.Require().NoError(err) - - err = s.transferPath.EndpointB.ChanOpenConfirm() - s.Require().NoError(err) - - // ensure counterparty is up to date - err = s.transferPath.EndpointA.UpdateClient() - s.Require().NoError(err) +// SetupTest is a shim for the democracy suite to use code for the ccv suite +func (democSuite *ConsumerDemocracyTestSuite) SetupTest() { + ccvSuite := CCVTestSuite{} + ccvSuite.SetT(democSuite.T()) + ccvSuite.coordinator, ccvSuite.providerChain, + ccvSuite.consumerChain = simapp.NewProviderConsumerDemocracyCoordinator(democSuite.T()) + CommonSetup(&ccvSuite, true) + democSuite.underlyingSuite = ccvSuite } func TestConsumerDemocracyTestSuite(t *testing.T) { suite.Run(t, new(ConsumerDemocracyTestSuite)) } -func (s *ConsumerDemocracyTestSuite) TestDemocracyRewarsDistribution() { +func (suite *ConsumerDemocracyTestSuite) TestDemocracyRewarsDistribution() { + + s := suite.underlyingSuite s.consumerChain.NextBlock() stakingKeeper := s.consumerChain.App.(*appConsumer.App).StakingKeeper @@ -263,7 +120,9 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyRewarsDistribution() { } } -func (s *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() { +func (suite *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() { + s := suite.underlyingSuite + govKeeper := s.consumerChain.App.(*appConsumer.App).GovKeeper stakingKeeper := s.consumerChain.App.(*appConsumer.App).StakingKeeper bankKeeper := s.consumerChain.App.(*appConsumer.App).BankKeeper @@ -365,11 +224,3 @@ func getAccountsBalances(ctx sdk.Context, bankKeeper bankkeeper.Keeper, bondDeno return accountsBalances } - -func (s *ConsumerDemocracyTestSuite) providerCtx() sdk.Context { - return s.providerChain.GetContext() -} - -func (s *ConsumerDemocracyTestSuite) consumerCtx() sdk.Context { - return s.consumerChain.GetContext() -} diff --git a/tests/e2e/setup_test.go b/tests/e2e/setup_test.go index 3fd0522729..afb39e8ddd 100644 --- a/tests/e2e/setup_test.go +++ b/tests/e2e/setup_test.go @@ -1,11 +1,13 @@ package e2e_test import ( - ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" - "bytes" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" + consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" + ccv "github.com/cosmos/interchain-security/x/ccv/types" "github.com/cosmos/interchain-security/x/ccv/utils" @@ -15,9 +17,11 @@ import ( ibctesting "github.com/cosmos/ibc-go/v3/testing" appConsumer "github.com/cosmos/interchain-security/app/consumer" + appconsumerdemocracy "github.com/cosmos/interchain-security/app/consumer-democracy" appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/testutil/simapp" + abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" "github.com/stretchr/testify/suite" @@ -40,6 +44,24 @@ func TestCCVTestSuite(t *testing.T) { func (suite *CCVTestSuite) SetupTest() { suite.coordinator, suite.providerChain, suite.consumerChain = simapp.NewProviderConsumerCoordinator(suite.T()) + CommonSetup(suite, false) +} + +// Interface for democracy suite to use CommonSetup +type consumerKeeper interface { + InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState) []abci.ValidatorUpdate + GetProviderClientID(ctx sdk.Context) (string, bool) +} + +// CommonSetup sets up a test suite, with the option to cast the consumer keeper to a democracy consumer +func CommonSetup(suite *CCVTestSuite, isDemocracyTest bool) { + + var consumerKeeper consumerKeeper + if isDemocracyTest { + consumerKeeper = suite.consumerChain.App.(*appconsumerdemocracy.App).ConsumerKeeper + } else { + consumerKeeper = suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper + } // valsets must match providerValUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.providerChain.Vals) @@ -72,7 +94,7 @@ func (suite *CCVTestSuite) SetupTest() { suite.consumerChain.ChainID, ) suite.Require().True(found, "consumer genesis not found") - suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), &consumerGenesis) + consumerKeeper.InitGenesis(suite.consumerChain.GetContext(), &consumerGenesis) suite.providerClient = consumerGenesis.ProviderClientState suite.providerConsState = consumerGenesis.ProviderConsensusState @@ -89,7 +111,7 @@ func (suite *CCVTestSuite) SetupTest() { suite.Require().True(found, "consumer client not found") suite.path.EndpointB.ClientID = consumerClient // - set consumer endpoint's clientID - providerClient, found := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClientID(suite.consumerChain.GetContext()) + providerClient, found := consumerKeeper.GetProviderClientID(suite.consumerChain.GetContext()) suite.Require().True(found, "provider client not found") suite.path.EndpointA.ClientID = providerClient // - client config From 554abd702527e769432948519678df28e61ada93 Mon Sep 17 00:00:00 2001 From: Shawn Marshall-Spitzbart <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Wed, 5 Oct 2022 22:45:31 -0700 Subject: [PATCH 2/6] Update democracy_test.go --- tests/e2e/democracy_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/democracy_test.go b/tests/e2e/democracy_test.go index a7c0f71701..8d6d6568d8 100644 --- a/tests/e2e/democracy_test.go +++ b/tests/e2e/democracy_test.go @@ -32,7 +32,7 @@ type ConsumerDemocracyTestSuite struct { suite.Suite } -// SetupTest is a shim for the democracy suite to use code for the ccv suite +// SetupTest is a shim for the democracy suite to share setup code with the ccv suite func (democSuite *ConsumerDemocracyTestSuite) SetupTest() { ccvSuite := CCVTestSuite{} ccvSuite.SetT(democSuite.T()) From 4af84fa4cc47f678f56070203965286a8a304bfc Mon Sep 17 00:00:00 2001 From: Shawn Marshall-Spitzbart <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 10 Oct 2022 23:31:47 -0700 Subject: [PATCH 3/6] made less confusing --- tests/e2e/common_test.go | 15 ++++ tests/e2e/democracy_test.go | 54 ++++++++++----- tests/e2e/setup_test.go | 134 +++++++++++++++++++----------------- 3 files changed, 124 insertions(+), 79 deletions(-) diff --git a/tests/e2e/common_test.go b/tests/e2e/common_test.go index c329f877d2..3de75d5d0e 100644 --- a/tests/e2e/common_test.go +++ b/tests/e2e/common_test.go @@ -8,6 +8,7 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" "github.com/cosmos/interchain-security/x/ccv/utils" "github.com/stretchr/testify/require" @@ -32,6 +33,20 @@ const ( Consumer ) +// The interface that any consumer keeper must implement to be compatible with e2e tests +type consumerKeeper interface { + InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState) []abci.ValidatorUpdate + GetProviderClientID(ctx sdk.Context) (string, bool) + // TODO: Expand this interface to be referenced by all e2e tests +} + +// The interface that any provider keeper must implement to be compatible with e2e tests +type providerKeeper interface { + CreateConsumerClient(ctx sdk.Context, chainID string, initialHeight clienttypes.Height, lockUbdOnTimeout bool) error + GetConsumerGenesis(ctx sdk.Context, chainID string) (consumertypes.GenesisState, bool) + // TODO: Expand this interface to be referenced by all e2e tests +} + func (s *CCVTestSuite) providerCtx() sdk.Context { return s.providerChain.GetContext() } diff --git a/tests/e2e/democracy_test.go b/tests/e2e/democracy_test.go index 8d6d6568d8..45a02c24c3 100644 --- a/tests/e2e/democracy_test.go +++ b/tests/e2e/democracy_test.go @@ -8,6 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -18,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/params/types/proposal" proposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" appConsumer "github.com/cosmos/interchain-security/app/consumer-democracy" + appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/testutil/simapp" consumerkeeper "github.com/cosmos/interchain-security/x/ccv/consumer/keeper" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" @@ -28,47 +30,58 @@ import ( var consumerFraction, _ = sdk.NewDecFromStr(consumerkeeper.ConsumerRedistributeFrac) type ConsumerDemocracyTestSuite struct { - underlyingSuite CCVTestSuite suite.Suite + coordinator *ibctesting.Coordinator + providerChain *ibctesting.TestChain + consumerChain *ibctesting.TestChain + providerClient *ibctmtypes.ClientState + providerConsState *ibctmtypes.ConsensusState + path *ibctesting.Path + transferPath *ibctesting.Path } -// SetupTest is a shim for the democracy suite to share setup code with the ccv suite +// SetupTest sets up in-mem state for the group of tests relevant to ccv with a democracy consumer +// TODO: Make this method more generalizable to be called by any provider/consumer implementation func (democSuite *ConsumerDemocracyTestSuite) SetupTest() { - ccvSuite := CCVTestSuite{} - ccvSuite.SetT(democSuite.T()) - ccvSuite.coordinator, ccvSuite.providerChain, - ccvSuite.consumerChain = simapp.NewProviderConsumerDemocracyCoordinator(democSuite.T()) - CommonSetup(&ccvSuite, true) - democSuite.underlyingSuite = ccvSuite + democSuite.coordinator, democSuite.providerChain, + democSuite.consumerChain = simapp.NewProviderConsumerDemocracyCoordinator(democSuite.T()) + + democSuite.providerClient, democSuite.providerConsState, + democSuite.path, democSuite.transferPath = CommonSetup( + + democSuite.Suite, + &democSuite.providerChain.App.(*appProvider.App).ProviderKeeper, + &democSuite.consumerChain.App.(*appConsumer.App).ConsumerKeeper, + democSuite.providerChain, + democSuite.consumerChain, + ) } func TestConsumerDemocracyTestSuite(t *testing.T) { suite.Run(t, new(ConsumerDemocracyTestSuite)) } -func (suite *ConsumerDemocracyTestSuite) TestDemocracyRewarsDistribution() { - - s := suite.underlyingSuite +func (s *ConsumerDemocracyTestSuite) TestDemocracyRewarsDistribution() { s.consumerChain.NextBlock() stakingKeeper := s.consumerChain.App.(*appConsumer.App).StakingKeeper authKeeper := s.consumerChain.App.(*appConsumer.App).AccountKeeper distrKeeper := s.consumerChain.App.(*appConsumer.App).DistrKeeper bankKeeper := s.consumerChain.App.(*appConsumer.App).BankKeeper - bondDenom := stakingKeeper.BondDenom(s.consumerCtx()) + bondDenom := stakingKeeper.BondDenom(s.consumerChain.GetContext()) currentRepresentativesRewards := map[string]sdk.Dec{} nextRepresentativesRewards := map[string]sdk.Dec{} representativesTokens := map[string]sdk.Int{} - for _, representative := range stakingKeeper.GetAllValidators(s.consumerCtx()) { + for _, representative := range stakingKeeper.GetAllValidators(s.consumerChain.GetContext()) { currentRepresentativesRewards[representative.OperatorAddress] = sdk.NewDec(0) nextRepresentativesRewards[representative.OperatorAddress] = sdk.NewDec(0) representativesTokens[representative.OperatorAddress] = representative.GetTokens() } - distrModuleAccount := distrKeeper.GetDistributionAccount(s.consumerCtx()) - providerRedistributeAccount := authKeeper.GetModuleAccount(s.consumerCtx(), consumertypes.ConsumerToSendToProviderName) + distrModuleAccount := distrKeeper.GetDistributionAccount(s.consumerChain.GetContext()) + providerRedistributeAccount := authKeeper.GetModuleAccount(s.consumerChain.GetContext(), consumertypes.ConsumerToSendToProviderName) //balance of consumer redistribute address will always be 0 when checked between 2 NextBlock() calls currentDistrModuleAccountBalance := sdk.NewDecFromInt(bankKeeper.GetBalance(s.consumerCtx(), distrModuleAccount.GetAddress(), bondDenom).Amount) @@ -120,8 +133,7 @@ func (suite *ConsumerDemocracyTestSuite) TestDemocracyRewarsDistribution() { } } -func (suite *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() { - s := suite.underlyingSuite +func (s *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() { govKeeper := s.consumerChain.App.(*appConsumer.App).GovKeeper stakingKeeper := s.consumerChain.App.(*appConsumer.App).StakingKeeper @@ -224,3 +236,11 @@ func getAccountsBalances(ctx sdk.Context, bankKeeper bankkeeper.Keeper, bondDeno return accountsBalances } + +func (s *ConsumerDemocracyTestSuite) providerCtx() sdk.Context { + return s.providerChain.GetContext() +} + +func (s *ConsumerDemocracyTestSuite) consumerCtx() sdk.Context { + return s.consumerChain.GetContext() +} diff --git a/tests/e2e/setup_test.go b/tests/e2e/setup_test.go index afb39e8ddd..5eeeea5a02 100644 --- a/tests/e2e/setup_test.go +++ b/tests/e2e/setup_test.go @@ -4,9 +4,7 @@ import ( "bytes" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" - consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" "github.com/cosmos/interchain-security/x/ccv/utils" @@ -17,11 +15,9 @@ import ( ibctesting "github.com/cosmos/ibc-go/v3/testing" appConsumer "github.com/cosmos/interchain-security/app/consumer" - appconsumerdemocracy "github.com/cosmos/interchain-security/app/consumer-democracy" appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/testutil/simapp" - abci "github.com/tendermint/tendermint/abci/types" tmtypes "github.com/tendermint/tendermint/types" "github.com/stretchr/testify/suite" @@ -42,30 +38,42 @@ func TestCCVTestSuite(t *testing.T) { suite.Run(t, new(CCVTestSuite)) } -func (suite *CCVTestSuite) SetupTest() { - suite.coordinator, suite.providerChain, suite.consumerChain = simapp.NewProviderConsumerCoordinator(suite.T()) - CommonSetup(suite, false) -} - -// Interface for democracy suite to use CommonSetup -type consumerKeeper interface { - InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState) []abci.ValidatorUpdate - GetProviderClientID(ctx sdk.Context) (string, bool) +// SetupTest sets up in-mem state for the standard group of tests validating chains which implement the ccv modules +// TODO: Make this method more generalizable to be called by any provider/consumer implementation +func (ccvSuite *CCVTestSuite) SetupTest() { + ccvSuite.coordinator, ccvSuite.providerChain, + ccvSuite.consumerChain = simapp.NewProviderConsumerCoordinator(ccvSuite.T()) + + ccvSuite.providerClient, ccvSuite.providerConsState, + ccvSuite.path, ccvSuite.transferPath = CommonSetup( + + ccvSuite.Suite, + // Pointers to provider/consumer keeper implementations are passed as interfaces here + &ccvSuite.providerChain.App.(*appProvider.App).ProviderKeeper, + &ccvSuite.consumerChain.App.(*appConsumer.App).ConsumerKeeper, + ccvSuite.providerChain, + ccvSuite.consumerChain, + ) } -// CommonSetup sets up a test suite, with the option to cast the consumer keeper to a democracy consumer -func CommonSetup(suite *CCVTestSuite, isDemocracyTest bool) { - - var consumerKeeper consumerKeeper - if isDemocracyTest { - consumerKeeper = suite.consumerChain.App.(*appconsumerdemocracy.App).ConsumerKeeper - } else { - consumerKeeper = suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper - } +// CommonSetup sets up various state for the test suite. It is used by both the standard +// group of ccv tests, and the group of tests relevant to a democracy consumer. +func CommonSetup( + suite suite.Suite, + providerKeeper providerKeeper, + consumerKeeper consumerKeeper, + providerChain *ibctesting.TestChain, + consumerChain *ibctesting.TestChain, +) ( + providerClientState *ibctmtypes.ClientState, + providerConsState *ibctmtypes.ConsensusState, + path *ibctesting.Path, + transferPath *ibctesting.Path, +) { // valsets must match - providerValUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.providerChain.Vals) - consumerValUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.consumerChain.Vals) + providerValUpdates := tmtypes.TM2PB.ValidatorUpdates(providerChain.Vals) + consumerValUpdates := tmtypes.TM2PB.ValidatorUpdates(consumerChain.Vals) suite.Require().True(len(providerValUpdates) == len(consumerValUpdates), "initial valset not matching") for i := 0; i < len(providerValUpdates); i++ { addr1 := utils.GetChangePubKeyAddress(providerValUpdates[i]) @@ -74,74 +82,76 @@ func CommonSetup(suite *CCVTestSuite, isDemocracyTest bool) { } // move both chains to the next block - suite.providerChain.NextBlock() - suite.consumerChain.NextBlock() + providerChain.NextBlock() + consumerChain.NextBlock() // create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper. - err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient( - suite.providerCtx(), - suite.consumerChain.ChainID, - suite.consumerChain.LastHeader.GetHeight().(clienttypes.Height), + err := providerKeeper.CreateConsumerClient( + providerChain.GetContext(), + consumerChain.ChainID, + consumerChain.LastHeader.GetHeight().(clienttypes.Height), false, ) suite.Require().NoError(err) // move provider to next block to commit the state - suite.providerChain.NextBlock() + providerChain.NextBlock() // initialize the consumer chain with the genesis state stored on the provider - consumerGenesis, found := suite.providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerGenesis( - suite.providerCtx(), - suite.consumerChain.ChainID, + consumerGenesis, found := providerKeeper.GetConsumerGenesis( + providerChain.GetContext(), + consumerChain.ChainID, ) suite.Require().True(found, "consumer genesis not found") - consumerKeeper.InitGenesis(suite.consumerChain.GetContext(), &consumerGenesis) - suite.providerClient = consumerGenesis.ProviderClientState - suite.providerConsState = consumerGenesis.ProviderConsensusState + consumerKeeper.InitGenesis(consumerChain.GetContext(), &consumerGenesis) + providerClientState = consumerGenesis.ProviderClientState + providerConsState = consumerGenesis.ProviderConsensusState // create path for the CCV channel - suite.path = ibctesting.NewPath(suite.consumerChain, suite.providerChain) + path = ibctesting.NewPath(consumerChain, providerChain) // update CCV path with correct info // - set provider endpoint's clientID - consumerClient, found := suite.providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerClientId( - suite.providerCtx(), - suite.consumerChain.ChainID, + consumerClient, found := providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerClientId( + providerChain.GetContext(), + consumerChain.ChainID, ) suite.Require().True(found, "consumer client not found") - suite.path.EndpointB.ClientID = consumerClient + path.EndpointB.ClientID = consumerClient // - set consumer endpoint's clientID - providerClient, found := consumerKeeper.GetProviderClientID(suite.consumerChain.GetContext()) + providerClientID, found := consumerKeeper.GetProviderClientID(consumerChain.GetContext()) suite.Require().True(found, "provider client not found") - suite.path.EndpointA.ClientID = providerClient + path.EndpointA.ClientID = providerClientID // - client config - providerUnbondingPeriod := suite.providerChain.App.(*appProvider.App).GetStakingKeeper().UnbondingTime(suite.providerCtx()) - suite.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = providerUnbondingPeriod - suite.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = providerUnbondingPeriod / utils.TrustingPeriodFraction + providerUnbondingPeriod := providerChain.App.GetStakingKeeper().UnbondingTime(providerChain.GetContext()) + path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = providerUnbondingPeriod + path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = providerUnbondingPeriod / utils.TrustingPeriodFraction consumerUnbondingPeriod := utils.ComputeConsumerUnbondingPeriod(providerUnbondingPeriod) - suite.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = consumerUnbondingPeriod - suite.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = consumerUnbondingPeriod / utils.TrustingPeriodFraction + path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = consumerUnbondingPeriod + path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = consumerUnbondingPeriod / utils.TrustingPeriodFraction // - channel config - suite.path.EndpointA.ChannelConfig.PortID = ccv.ConsumerPortID - suite.path.EndpointB.ChannelConfig.PortID = ccv.ProviderPortID - suite.path.EndpointA.ChannelConfig.Version = ccv.Version - suite.path.EndpointB.ChannelConfig.Version = ccv.Version - suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED - suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED + path.EndpointA.ChannelConfig.PortID = ccv.ConsumerPortID + path.EndpointB.ChannelConfig.PortID = ccv.ProviderPortID + path.EndpointA.ChannelConfig.Version = ccv.Version + path.EndpointB.ChannelConfig.Version = ccv.Version + path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED + path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED // set chains sender account number // TODO: to be fixed in #151 - err = suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6) + err = path.EndpointB.Chain.SenderAccount.SetAccountNumber(6) suite.Require().NoError(err) - err = suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(1) + err = path.EndpointA.Chain.SenderAccount.SetAccountNumber(1) suite.Require().NoError(err) // create path for the transfer channel - suite.transferPath = ibctesting.NewPath(suite.consumerChain, suite.providerChain) - suite.transferPath.EndpointA.ChannelConfig.PortID = transfertypes.PortID - suite.transferPath.EndpointB.ChannelConfig.PortID = transfertypes.PortID - suite.transferPath.EndpointA.ChannelConfig.Version = transfertypes.Version - suite.transferPath.EndpointB.ChannelConfig.Version = transfertypes.Version + transferPath = ibctesting.NewPath(consumerChain, providerChain) + transferPath.EndpointA.ChannelConfig.PortID = transfertypes.PortID + transferPath.EndpointB.ChannelConfig.PortID = transfertypes.PortID + transferPath.EndpointA.ChannelConfig.Version = transfertypes.Version + transferPath.EndpointB.ChannelConfig.Version = transfertypes.Version + + return providerClientState, providerConsState, path, transferPath } func (suite *CCVTestSuite) SetupCCVChannel() { From 9b55ab8569d9bb8f929f264b400bf9a37412d742 Mon Sep 17 00:00:00 2001 From: Shawn Marshall-Spitzbart <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 10 Oct 2022 23:40:41 -0700 Subject: [PATCH 4/6] Update democracy_test.go --- tests/e2e/democracy_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/e2e/democracy_test.go b/tests/e2e/democracy_test.go index 45a02c24c3..2ce498eac3 100644 --- a/tests/e2e/democracy_test.go +++ b/tests/e2e/democracy_test.go @@ -68,20 +68,20 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyRewarsDistribution() { authKeeper := s.consumerChain.App.(*appConsumer.App).AccountKeeper distrKeeper := s.consumerChain.App.(*appConsumer.App).DistrKeeper bankKeeper := s.consumerChain.App.(*appConsumer.App).BankKeeper - bondDenom := stakingKeeper.BondDenom(s.consumerChain.GetContext()) + bondDenom := stakingKeeper.BondDenom(s.consumerCtx()) currentRepresentativesRewards := map[string]sdk.Dec{} nextRepresentativesRewards := map[string]sdk.Dec{} representativesTokens := map[string]sdk.Int{} - for _, representative := range stakingKeeper.GetAllValidators(s.consumerChain.GetContext()) { + for _, representative := range stakingKeeper.GetAllValidators(s.consumerCtx()) { currentRepresentativesRewards[representative.OperatorAddress] = sdk.NewDec(0) nextRepresentativesRewards[representative.OperatorAddress] = sdk.NewDec(0) representativesTokens[representative.OperatorAddress] = representative.GetTokens() } - distrModuleAccount := distrKeeper.GetDistributionAccount(s.consumerChain.GetContext()) - providerRedistributeAccount := authKeeper.GetModuleAccount(s.consumerChain.GetContext(), consumertypes.ConsumerToSendToProviderName) + distrModuleAccount := distrKeeper.GetDistributionAccount(s.consumerCtx()) + providerRedistributeAccount := authKeeper.GetModuleAccount(s.consumerCtx(), consumertypes.ConsumerToSendToProviderName) //balance of consumer redistribute address will always be 0 when checked between 2 NextBlock() calls currentDistrModuleAccountBalance := sdk.NewDecFromInt(bankKeeper.GetBalance(s.consumerCtx(), distrModuleAccount.GetAddress(), bondDenom).Amount) @@ -134,7 +134,6 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyRewarsDistribution() { } func (s *ConsumerDemocracyTestSuite) TestDemocracyGovernanceWhitelisting() { - govKeeper := s.consumerChain.App.(*appConsumer.App).GovKeeper stakingKeeper := s.consumerChain.App.(*appConsumer.App).StakingKeeper bankKeeper := s.consumerChain.App.(*appConsumer.App).BankKeeper From 789e1b92cefa81500f42e3ed818791814838b3ff Mon Sep 17 00:00:00 2001 From: Shawn Marshall-Spitzbart <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Mon, 10 Oct 2022 23:48:56 -0700 Subject: [PATCH 5/6] Update democracy_test.go --- tests/e2e/democracy_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/e2e/democracy_test.go b/tests/e2e/democracy_test.go index 2ce498eac3..1f2370a6cb 100644 --- a/tests/e2e/democracy_test.go +++ b/tests/e2e/democracy_test.go @@ -236,10 +236,6 @@ func getAccountsBalances(ctx sdk.Context, bankKeeper bankkeeper.Keeper, bondDeno return accountsBalances } -func (s *ConsumerDemocracyTestSuite) providerCtx() sdk.Context { - return s.providerChain.GetContext() -} - func (s *ConsumerDemocracyTestSuite) consumerCtx() sdk.Context { return s.consumerChain.GetContext() } From 4958d0fb9551f50220b15f15ed605f04b494dbba Mon Sep 17 00:00:00 2001 From: Shawn Marshall-Spitzbart <44221603+smarshall-spitzbart@users.noreply.github.com> Date: Tue, 11 Oct 2022 14:34:25 -0700 Subject: [PATCH 6/6] make pr simple --- tests/e2e/common_test.go | 15 ----- tests/e2e/democracy_test.go | 24 ++------ tests/e2e/setup_test.go | 120 +++++++++++++----------------------- 3 files changed, 48 insertions(+), 111 deletions(-) diff --git a/tests/e2e/common_test.go b/tests/e2e/common_test.go index 3de75d5d0e..c329f877d2 100644 --- a/tests/e2e/common_test.go +++ b/tests/e2e/common_test.go @@ -8,7 +8,6 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" ccv "github.com/cosmos/interchain-security/x/ccv/types" "github.com/cosmos/interchain-security/x/ccv/utils" "github.com/stretchr/testify/require" @@ -33,20 +32,6 @@ const ( Consumer ) -// The interface that any consumer keeper must implement to be compatible with e2e tests -type consumerKeeper interface { - InitGenesis(ctx sdk.Context, state *consumertypes.GenesisState) []abci.ValidatorUpdate - GetProviderClientID(ctx sdk.Context) (string, bool) - // TODO: Expand this interface to be referenced by all e2e tests -} - -// The interface that any provider keeper must implement to be compatible with e2e tests -type providerKeeper interface { - CreateConsumerClient(ctx sdk.Context, chainID string, initialHeight clienttypes.Height, lockUbdOnTimeout bool) error - GetConsumerGenesis(ctx sdk.Context, chainID string) (consumertypes.GenesisState, bool) - // TODO: Expand this interface to be referenced by all e2e tests -} - func (s *CCVTestSuite) providerCtx() sdk.Context { return s.providerChain.GetContext() } diff --git a/tests/e2e/democracy_test.go b/tests/e2e/democracy_test.go index 1f2370a6cb..1b5d6d8f66 100644 --- a/tests/e2e/democracy_test.go +++ b/tests/e2e/democracy_test.go @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" ibctesting "github.com/cosmos/ibc-go/v3/testing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -19,7 +18,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/params/types/proposal" proposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" appConsumer "github.com/cosmos/interchain-security/app/consumer-democracy" - appProvider "github.com/cosmos/interchain-security/app/provider" "github.com/cosmos/interchain-security/testutil/simapp" consumerkeeper "github.com/cosmos/interchain-security/x/ccv/consumer/keeper" consumertypes "github.com/cosmos/interchain-security/x/ccv/consumer/types" @@ -31,13 +29,9 @@ var consumerFraction, _ = sdk.NewDecFromStr(consumerkeeper.ConsumerRedistributeF type ConsumerDemocracyTestSuite struct { suite.Suite - coordinator *ibctesting.Coordinator - providerChain *ibctesting.TestChain - consumerChain *ibctesting.TestChain - providerClient *ibctmtypes.ClientState - providerConsState *ibctmtypes.ConsensusState - path *ibctesting.Path - transferPath *ibctesting.Path + coordinator *ibctesting.Coordinator + providerChain *ibctesting.TestChain + consumerChain *ibctesting.TestChain } // SetupTest sets up in-mem state for the group of tests relevant to ccv with a democracy consumer @@ -45,23 +39,13 @@ type ConsumerDemocracyTestSuite struct { func (democSuite *ConsumerDemocracyTestSuite) SetupTest() { democSuite.coordinator, democSuite.providerChain, democSuite.consumerChain = simapp.NewProviderConsumerDemocracyCoordinator(democSuite.T()) - - democSuite.providerClient, democSuite.providerConsState, - democSuite.path, democSuite.transferPath = CommonSetup( - - democSuite.Suite, - &democSuite.providerChain.App.(*appProvider.App).ProviderKeeper, - &democSuite.consumerChain.App.(*appConsumer.App).ConsumerKeeper, - democSuite.providerChain, - democSuite.consumerChain, - ) } func TestConsumerDemocracyTestSuite(t *testing.T) { suite.Run(t, new(ConsumerDemocracyTestSuite)) } -func (s *ConsumerDemocracyTestSuite) TestDemocracyRewarsDistribution() { +func (s *ConsumerDemocracyTestSuite) TestDemocracyRewardsDistribution() { s.consumerChain.NextBlock() stakingKeeper := s.consumerChain.App.(*appConsumer.App).StakingKeeper diff --git a/tests/e2e/setup_test.go b/tests/e2e/setup_test.go index 5eeeea5a02..3fd0522729 100644 --- a/tests/e2e/setup_test.go +++ b/tests/e2e/setup_test.go @@ -1,11 +1,11 @@ package e2e_test import ( + ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" + "bytes" "testing" - ibctmtypes "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" - ccv "github.com/cosmos/interchain-security/x/ccv/types" "github.com/cosmos/interchain-security/x/ccv/utils" @@ -38,42 +38,12 @@ func TestCCVTestSuite(t *testing.T) { suite.Run(t, new(CCVTestSuite)) } -// SetupTest sets up in-mem state for the standard group of tests validating chains which implement the ccv modules -// TODO: Make this method more generalizable to be called by any provider/consumer implementation -func (ccvSuite *CCVTestSuite) SetupTest() { - ccvSuite.coordinator, ccvSuite.providerChain, - ccvSuite.consumerChain = simapp.NewProviderConsumerCoordinator(ccvSuite.T()) - - ccvSuite.providerClient, ccvSuite.providerConsState, - ccvSuite.path, ccvSuite.transferPath = CommonSetup( - - ccvSuite.Suite, - // Pointers to provider/consumer keeper implementations are passed as interfaces here - &ccvSuite.providerChain.App.(*appProvider.App).ProviderKeeper, - &ccvSuite.consumerChain.App.(*appConsumer.App).ConsumerKeeper, - ccvSuite.providerChain, - ccvSuite.consumerChain, - ) -} - -// CommonSetup sets up various state for the test suite. It is used by both the standard -// group of ccv tests, and the group of tests relevant to a democracy consumer. -func CommonSetup( - suite suite.Suite, - providerKeeper providerKeeper, - consumerKeeper consumerKeeper, - providerChain *ibctesting.TestChain, - consumerChain *ibctesting.TestChain, -) ( - providerClientState *ibctmtypes.ClientState, - providerConsState *ibctmtypes.ConsensusState, - path *ibctesting.Path, - transferPath *ibctesting.Path, -) { +func (suite *CCVTestSuite) SetupTest() { + suite.coordinator, suite.providerChain, suite.consumerChain = simapp.NewProviderConsumerCoordinator(suite.T()) // valsets must match - providerValUpdates := tmtypes.TM2PB.ValidatorUpdates(providerChain.Vals) - consumerValUpdates := tmtypes.TM2PB.ValidatorUpdates(consumerChain.Vals) + providerValUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.providerChain.Vals) + consumerValUpdates := tmtypes.TM2PB.ValidatorUpdates(suite.consumerChain.Vals) suite.Require().True(len(providerValUpdates) == len(consumerValUpdates), "initial valset not matching") for i := 0; i < len(providerValUpdates); i++ { addr1 := utils.GetChangePubKeyAddress(providerValUpdates[i]) @@ -82,76 +52,74 @@ func CommonSetup( } // move both chains to the next block - providerChain.NextBlock() - consumerChain.NextBlock() + suite.providerChain.NextBlock() + suite.consumerChain.NextBlock() // create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper. - err := providerKeeper.CreateConsumerClient( - providerChain.GetContext(), - consumerChain.ChainID, - consumerChain.LastHeader.GetHeight().(clienttypes.Height), + err := suite.providerChain.App.(*appProvider.App).ProviderKeeper.CreateConsumerClient( + suite.providerCtx(), + suite.consumerChain.ChainID, + suite.consumerChain.LastHeader.GetHeight().(clienttypes.Height), false, ) suite.Require().NoError(err) // move provider to next block to commit the state - providerChain.NextBlock() + suite.providerChain.NextBlock() // initialize the consumer chain with the genesis state stored on the provider - consumerGenesis, found := providerKeeper.GetConsumerGenesis( - providerChain.GetContext(), - consumerChain.ChainID, + consumerGenesis, found := suite.providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerGenesis( + suite.providerCtx(), + suite.consumerChain.ChainID, ) suite.Require().True(found, "consumer genesis not found") - consumerKeeper.InitGenesis(consumerChain.GetContext(), &consumerGenesis) - providerClientState = consumerGenesis.ProviderClientState - providerConsState = consumerGenesis.ProviderConsensusState + suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.InitGenesis(suite.consumerChain.GetContext(), &consumerGenesis) + suite.providerClient = consumerGenesis.ProviderClientState + suite.providerConsState = consumerGenesis.ProviderConsensusState // create path for the CCV channel - path = ibctesting.NewPath(consumerChain, providerChain) + suite.path = ibctesting.NewPath(suite.consumerChain, suite.providerChain) // update CCV path with correct info // - set provider endpoint's clientID - consumerClient, found := providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerClientId( - providerChain.GetContext(), - consumerChain.ChainID, + consumerClient, found := suite.providerChain.App.(*appProvider.App).ProviderKeeper.GetConsumerClientId( + suite.providerCtx(), + suite.consumerChain.ChainID, ) suite.Require().True(found, "consumer client not found") - path.EndpointB.ClientID = consumerClient + suite.path.EndpointB.ClientID = consumerClient // - set consumer endpoint's clientID - providerClientID, found := consumerKeeper.GetProviderClientID(consumerChain.GetContext()) + providerClient, found := suite.consumerChain.App.(*appConsumer.App).ConsumerKeeper.GetProviderClientID(suite.consumerChain.GetContext()) suite.Require().True(found, "provider client not found") - path.EndpointA.ClientID = providerClientID + suite.path.EndpointA.ClientID = providerClient // - client config - providerUnbondingPeriod := providerChain.App.GetStakingKeeper().UnbondingTime(providerChain.GetContext()) - path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = providerUnbondingPeriod - path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = providerUnbondingPeriod / utils.TrustingPeriodFraction + providerUnbondingPeriod := suite.providerChain.App.(*appProvider.App).GetStakingKeeper().UnbondingTime(suite.providerCtx()) + suite.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = providerUnbondingPeriod + suite.path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = providerUnbondingPeriod / utils.TrustingPeriodFraction consumerUnbondingPeriod := utils.ComputeConsumerUnbondingPeriod(providerUnbondingPeriod) - path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = consumerUnbondingPeriod - path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = consumerUnbondingPeriod / utils.TrustingPeriodFraction + suite.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).UnbondingPeriod = consumerUnbondingPeriod + suite.path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod = consumerUnbondingPeriod / utils.TrustingPeriodFraction // - channel config - path.EndpointA.ChannelConfig.PortID = ccv.ConsumerPortID - path.EndpointB.ChannelConfig.PortID = ccv.ProviderPortID - path.EndpointA.ChannelConfig.Version = ccv.Version - path.EndpointB.ChannelConfig.Version = ccv.Version - path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED - path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED + suite.path.EndpointA.ChannelConfig.PortID = ccv.ConsumerPortID + suite.path.EndpointB.ChannelConfig.PortID = ccv.ProviderPortID + suite.path.EndpointA.ChannelConfig.Version = ccv.Version + suite.path.EndpointB.ChannelConfig.Version = ccv.Version + suite.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED + suite.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED // set chains sender account number // TODO: to be fixed in #151 - err = path.EndpointB.Chain.SenderAccount.SetAccountNumber(6) + err = suite.path.EndpointB.Chain.SenderAccount.SetAccountNumber(6) suite.Require().NoError(err) - err = path.EndpointA.Chain.SenderAccount.SetAccountNumber(1) + err = suite.path.EndpointA.Chain.SenderAccount.SetAccountNumber(1) suite.Require().NoError(err) // create path for the transfer channel - transferPath = ibctesting.NewPath(consumerChain, providerChain) - transferPath.EndpointA.ChannelConfig.PortID = transfertypes.PortID - transferPath.EndpointB.ChannelConfig.PortID = transfertypes.PortID - transferPath.EndpointA.ChannelConfig.Version = transfertypes.Version - transferPath.EndpointB.ChannelConfig.Version = transfertypes.Version - - return providerClientState, providerConsState, path, transferPath + suite.transferPath = ibctesting.NewPath(suite.consumerChain, suite.providerChain) + suite.transferPath.EndpointA.ChannelConfig.PortID = transfertypes.PortID + suite.transferPath.EndpointB.ChannelConfig.PortID = transfertypes.PortID + suite.transferPath.EndpointA.ChannelConfig.Version = transfertypes.Version + suite.transferPath.EndpointB.ChannelConfig.Version = transfertypes.Version } func (suite *CCVTestSuite) SetupCCVChannel() {