Skip to content

Commit

Permalink
second e2e chain with expanded test (#1206)
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic authored and p0mvn committed Apr 24, 2022
1 parent 74609cf commit b80433c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 39 deletions.
5 changes: 2 additions & 3 deletions tests/e2e/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
79 changes: 56 additions & 23 deletions tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,27 +70,37 @@ 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)

// 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() {
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
42 changes: 29 additions & 13 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b80433c

Please sign in to comment.