From e9cf9f6581a923a86f68f8c98f14a02ffdda7d8a Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 6 Apr 2022 12:19:43 -0500 Subject: [PATCH] second e2e chain with expanded test (#1206) --- tests/e2e/chain.go | 5 +-- tests/e2e/e2e_setup_test.go | 79 ++++++++++++++++++++++++++----------- tests/e2e/e2e_test.go | 42 ++++++++++++++------ 3 files changed, 87 insertions(+), 39 deletions(-) diff --git a/tests/e2e/chain.go b/tests/e2e/chain.go index a5ce93561ad..24cea7e9f3b 100644 --- a/tests/e2e/chain.go +++ b/tests/e2e/chain.go @@ -10,7 +10,6 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - tmrand "github.com/tendermint/tendermint/libs/rand" osmosisApp "github.com/osmosis-labs/osmosis/v7/app" "github.com/osmosis-labs/osmosis/v7/app/params" @@ -48,14 +47,14 @@ type chain struct { validators []*validator } -func newChain() (*chain, error) { +func newChain(name string) (*chain, error) { tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-") if err != nil { return nil, err } return &chain{ - id: "chain-" + tmrand.NewRand().Str(6), + id: name, dataDir: tmpDir, }, nil } diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 5e320e8c68c..ad6be48df76 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -26,25 +26,37 @@ import ( ) const ( - osmoBalance = 200000000000 - osmoDenom = "uosmo" - stakeBalance = 110000000000 - stakeAmount = 100000000000 - stakeDenom = "stake" - minGasPrice = "0.00001" + // common + osmoDenom = "uosmo" + stakeDenom = "stake" + minGasPrice = "0.00001" + // chainA + chainAName = "osmo-test-a" + osmoBalanceA = 200000000000 + stakeBalanceA = 110000000000 + stakeAmountA = 100000000000 + // chainB + chainBName = "osmo-test-b" + osmoBalanceB = 500000000000 + stakeBalanceB = 440000000000 + stakeAmountB = 400000000000 ) var ( - initBalanceStr = fmt.Sprintf("%d%s,%d%s", osmoBalance, osmoDenom, stakeBalance, stakeDenom) - stakeAmountInt, _ = sdk.NewIntFromString(fmt.Sprintf("%d", stakeAmount)) - stakeAmountCoin = sdk.NewCoin(stakeDenom, stakeAmountInt) + initBalanceStrA = fmt.Sprintf("%d%s,%d%s", osmoBalanceA, osmoDenom, stakeBalanceA, stakeDenom) + initBalanceStrB = fmt.Sprintf("%d%s,%d%s", osmoBalanceB, osmoDenom, stakeBalanceB, stakeDenom) + stakeAmountIntA = sdk.NewInt(stakeAmountA) + stakeAmountCoinA = sdk.NewCoin(stakeDenom, stakeAmountIntA) + stakeAmountIntB = sdk.NewInt(stakeAmountB) + stakeAmountCoinB = sdk.NewCoin(stakeDenom, stakeAmountIntB) ) type IntegrationTestSuite struct { suite.Suite tmpDirs []string - chain *chain + chainA *chain + chainB *chain dkrPool *dockertest.Pool dkrNet *dockertest.Network valResources map[string][]*dockertest.Resource @@ -58,13 +70,16 @@ func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up e2e integration test suite...") var err error - s.chain, err = newChain() + s.chainA, err = newChain(chainAName) + s.Require().NoError(err) + + s.chainB, err = newChain(chainBName) s.Require().NoError(err) s.dkrPool, err = dockertest.NewPool("") s.Require().NoError(err) - s.dkrNet, err = s.dkrPool.CreateNetwork(fmt.Sprintf("%s-testnet", s.chain.id)) + s.dkrNet, err = s.dkrPool.CreateNetwork(fmt.Sprintf("%s-%s-testnet", s.chainA.id, s.chainB.id)) s.Require().NoError(err) s.valResources = make(map[string][]*dockertest.Resource) @@ -72,13 +87,20 @@ func (s *IntegrationTestSuite) SetupSuite() { // The boostrapping phase is as follows: // // 1. Initialize Osmosis validator nodes. - // 2. Create and initialize Osmosis validator genesis files (one chain) - - s.T().Logf("starting e2e infrastructure for chain A; chain-id: %s; datadir: %s", s.chain.id, s.chain.dataDir) - s.initNodes(s.chain) - s.initGenesis(s.chain) - s.initValidatorConfigs(s.chain) - s.runValidators(s.chain, 0) + // 2. Create and initialize Osmosis validator genesis files (both chains) + // 3. Start both networks. + + s.T().Logf("starting e2e infrastructure for chain A; chain-id: %s; datadir: %s", s.chainA.id, s.chainA.dataDir) + s.initNodes(s.chainA) + s.initGenesis(s.chainA) + s.initValidatorConfigs(s.chainA) + s.runValidators(s.chainA, 0) + + s.T().Logf("starting e2e infrastructure for chain B; chain-id: %s; datadir: %s", s.chainB.id, s.chainB.dataDir) + s.initNodes(s.chainB) + s.initGenesis(s.chainB) + s.initValidatorConfigs(s.chainB) + s.runValidators(s.chainB, 10) } func (s *IntegrationTestSuite) TearDownSuite() { @@ -101,7 +123,8 @@ func (s *IntegrationTestSuite) TearDownSuite() { s.Require().NoError(s.dkrPool.RemoveNetwork(s.dkrNet)) - os.RemoveAll(s.chain.dataDir) + os.RemoveAll(s.chainA.dataDir) + os.RemoveAll(s.chainB.dataDir) for _, td := range s.tmpDirs { os.RemoveAll(td) @@ -114,9 +137,15 @@ func (s *IntegrationTestSuite) initNodes(c *chain) { // initialize a genesis file for the first validator val0ConfigDir := c.validators[0].configDir() for _, val := range c.validators { - s.Require().NoError( - addGenesisAccount(val0ConfigDir, "", initBalanceStr, val.keyInfo.GetAddress()), - ) + if c.id == chainAName { + s.Require().NoError( + addGenesisAccount(val0ConfigDir, "", initBalanceStrA, val.keyInfo.GetAddress()), + ) + } else if c.id == chainBName { + s.Require().NoError( + addGenesisAccount(val0ConfigDir, "", initBalanceStrB, val.keyInfo.GetAddress()), + ) + } } // copy the genesis file to the remaining validators @@ -167,6 +196,10 @@ func (s *IntegrationTestSuite) initGenesis(c *chain) { // generate genesis txs genTxs := make([]json.RawMessage, len(c.validators)) for i, val := range c.validators { + stakeAmountCoin := stakeAmountCoinA + if c.id != chainAName { + stakeAmountCoin = stakeAmountCoinB + } createValmsg, err := val.buildCreateValidatorMsg(stakeAmountCoin) s.Require().NoError(err) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 5495a4efecd..2cc226a7854 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -13,26 +13,42 @@ import ( func (s *IntegrationTestSuite) TestQueryBalances() { var ( - expectedDenoms = []string{osmoDenom, stakeDenom} - expectedBalances = []uint64{osmoBalance, stakeBalance - stakeAmount} + expectedDenoms = []string{osmoDenom, stakeDenom} + expectedBalancesA = []uint64{osmoBalanceA, stakeBalanceA - stakeAmountA} + expectedBalancesB = []uint64{osmoBalanceB, stakeBalanceB - stakeAmountB} ) - chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chain.id][0].GetHostPort("1317/tcp")) - balances, err := queryBalances(chainAAPIEndpoint, s.chain.validators[0].keyInfo.GetAddress().String()) + chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp")) + balancesA, err := queryBalances(chainAAPIEndpoint, s.chainA.validators[0].keyInfo.GetAddress().String()) s.Require().NoError(err) - s.Require().NotNil(balances) - s.Require().Equal(2, len(balances)) + s.Require().NotNil(balancesA) + s.Require().Equal(2, len(balancesA)) - actualDenoms := make([]string, 0, 2) - actualBalances := make([]uint64, 0, 2) + chainBAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainB.id][0].GetHostPort("1317/tcp")) + balancesB, err := queryBalances(chainBAPIEndpoint, s.chainB.validators[0].keyInfo.GetAddress().String()) + s.Require().NoError(err) + s.Require().NotNil(balancesB) + s.Require().Equal(2, len(balancesB)) + + actualDenomsA := make([]string, 0, 2) + actualBalancesA := make([]uint64, 0, 2) + actualDenomsB := make([]string, 0, 2) + actualBalancesB := make([]uint64, 0, 2) + + for _, balanceA := range balancesA { + actualDenomsA = append(actualDenomsA, balanceA.GetDenom()) + actualBalancesA = append(actualBalancesA, balanceA.Amount.Uint64()) + } - for _, balance := range balances { - actualDenoms = append(actualDenoms, balance.GetDenom()) - actualBalances = append(actualBalances, balance.Amount.Uint64()) + for _, balanceB := range balancesB { + actualDenomsB = append(actualDenomsB, balanceB.GetDenom()) + actualBalancesB = append(actualBalancesB, balanceB.Amount.Uint64()) } - s.Require().ElementsMatch(expectedDenoms, actualDenoms) - s.Require().ElementsMatch(expectedBalances, actualBalances) + s.Require().ElementsMatch(expectedDenoms, actualDenomsA) + s.Require().ElementsMatch(expectedBalancesA, actualBalancesA) + s.Require().ElementsMatch(expectedDenoms, actualDenomsB) + s.Require().ElementsMatch(expectedBalancesB, actualBalancesB) } func queryBalances(endpoint, addr string) (sdk.Coins, error) {