From 2c87381d5dbabac55fd690346a6224219bcfbdd7 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 23 May 2022 09:38:21 -0500 Subject: [PATCH 01/20] change to osmo no stake --- Dockerfile | 2 +- tests/e2e/chain/config.go | 4 +- tests/e2e/chain/export.go | 3 + tests/e2e/chain/validator.go | 1 + tests/e2e/e2e_setup_test.go | 24 ++- tests/e2e/e2e_test.go | 16 +- tests/e2e/e2e_util_test.go | 216 ++++++++++++++++++++++++-- tests/e2e/scripts/genesis_mod.sh | 33 ++++ tests/e2e/scripts/hermes_bootstrap.sh | 4 +- 9 files changed, 279 insertions(+), 24 deletions(-) create mode 100755 tests/e2e/scripts/genesis_mod.sh diff --git a/Dockerfile b/Dockerfile index b1d1331a642..a2b842b6f91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build # Runner # -------------------------------------------------------- -FROM gcr.io/distroless/base-debian11:${BASE_IMG_TAG} +FROM ubuntu COPY --from=build /osmosis/build/osmosisd /bin/osmosisd diff --git a/tests/e2e/chain/config.go b/tests/e2e/chain/config.go index 94d016a7ada..848b5029ade 100644 --- a/tests/e2e/chain/config.go +++ b/tests/e2e/chain/config.go @@ -52,9 +52,9 @@ const ( var ( StakeAmountIntA = sdk.NewInt(StakeAmountA) - StakeAmountCoinA = sdk.NewCoin(StakeDenom, StakeAmountIntA) + StakeAmountCoinA = sdk.NewCoin(OsmoDenom, StakeAmountIntA) StakeAmountIntB = sdk.NewInt(StakeAmountB) - StakeAmountCoinB = sdk.NewCoin(StakeDenom, StakeAmountIntB) + StakeAmountCoinB = sdk.NewCoin(OsmoDenom, StakeAmountIntB) InitBalanceStrA = fmt.Sprintf("%d%s,%d%s", OsmoBalanceA, OsmoDenom, StakeBalanceA, StakeDenom) InitBalanceStrB = fmt.Sprintf("%d%s,%d%s", OsmoBalanceB, OsmoDenom, StakeBalanceB, StakeDenom) diff --git a/tests/e2e/chain/export.go b/tests/e2e/chain/export.go index d2b7922dbaa..2c6811258ca 100644 --- a/tests/e2e/chain/export.go +++ b/tests/e2e/chain/export.go @@ -13,11 +13,14 @@ type Validator struct { Index int `json:"index"` Mnemonic string `json:"mnemonic"` PublicAddress string `json:"publicAddress"` + PublicKey string `json:"publicKey"` + OperAddress string `json:"operAddress"` } type Chain struct { ChainMeta ChainMeta `json:"chainMeta"` Validators []*Validator `json:"validators"` + PropNumber int `json:"propNumber"` } func (c *ChainMeta) configDir() string { diff --git a/tests/e2e/chain/validator.go b/tests/e2e/chain/validator.go index 5f57a71a2bc..9df18cdb6eb 100644 --- a/tests/e2e/chain/validator.go +++ b/tests/e2e/chain/validator.go @@ -182,6 +182,7 @@ func (v *internalValidator) export() *Validator { Index: v.index, Mnemonic: v.mnemonic, PublicAddress: v.keyInfo.GetAddress().String(), + PublicKey: v.keyInfo.GetPubKey().Address().String(), } } diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 399bfdc3e32..a7715db1dd5 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -29,10 +29,10 @@ var ( upgradeVersion = "v9" // osmosis repo/version for initialization (this should be one version below upgradeVersion) initRepository = "osmolabs/osmosis-init" - initVersion = "v8.0.0" + initVersion = "v8.0.0-1-osmo" // pre upgrade osmosis repo/version to pull (should match initVersion numer) debugRepository = "osmolabs/osmosis-dev" - debugVersion = "v8.0.0-debug" + debugVersion = "v8.0.0-1-debug" // hermes repo/version for relayer relayerRepository = "osmolabs/hermes" relayerVersion = "0.13.0" @@ -54,6 +54,8 @@ var ( propHeightA int // upgrade proposal height for chain B propHeightB int + // current prop number + propNumber int = 1 // max retries for json unmarshalling maxRetries = 60 // whatever number of validator configs get posted here are how many validators that will spawn on chain A and B respectively @@ -125,6 +127,10 @@ type syncInfo struct { SyncInfo status `json:"SyncInfo"` } +type operInfo struct { + Bech32Val string `json:"Bech32 Val"` +} + func TestIntegrationTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) } @@ -155,6 +161,8 @@ func (s *IntegrationTestSuite) SetupSuite() { s.runValidators(s.chains[0], 0) s.runValidators(s.chains[1], 10) + s.extractOperAddress(s.chains[0]) + s.extractOperAddress(s.chains[1]) s.runIBCRelayer() s.runPostUpgradeTests() return @@ -166,6 +174,8 @@ func (s *IntegrationTestSuite) SetupSuite() { s.runValidators(s.chains[0], 0) s.runValidators(s.chains[1], 10) + s.extractOperAddress(s.chains[0]) + s.extractOperAddress(s.chains[1]) s.runIBCRelayer() // pre upgrade state creation s.createPreUpgradeState() @@ -221,8 +231,10 @@ func (s *IntegrationTestSuite) runValidators(c *chain.Chain, portOffset int) { }, Repository: debugRepository, Tag: debugVersion, - Cmd: []string{ - "start", + Entrypoint: []string{ + "sh", + "-c", + "chmod +x /osmosis/genesis_mod.sh && /osmosis/genesis_mod.sh", }, } @@ -461,13 +473,13 @@ func (s *IntegrationTestSuite) upgrade() { // prop height = current height + voting period + time it takes to submit proposal + small buffer currentHeightA := s.getCurrentChainHeight(s.valResources[s.chains[0].ChainMeta.Id][0].Container.ID) propHeightA = currentHeightA + int(votingPeriodA) + int(propSubmitBlocks) + int(propBufferBlocks) - s.submitProposal(s.chains[0], propHeightA) + s.submitUpgradeProposal(s.chains[0], propHeightA) s.depositProposal(s.chains[0]) s.voteProposal(s.chains[0]) // prop height = current height + voting period + time it takes to submit proposal + small buffer currentHeightB := s.getCurrentChainHeight(s.valResources[s.chains[1].ChainMeta.Id][0].Container.ID) propHeightB = currentHeightB + int(votingPeriodB) + int(propSubmitBlocks) + int(propBufferBlocks) - s.submitProposal(s.chains[1], propHeightB) + s.submitUpgradeProposal(s.chains[1], propHeightB) s.depositProposal(s.chains[1]) s.voteProposal(s.chains[1]) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index f329cdcd80f..49c77714375 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -1,13 +1,27 @@ package e2e import ( + "fmt" + "github.com/osmosis-labs/osmosis/v7/tests/e2e/chain" ) func (s *IntegrationTestSuite) TestIBCTokenTransfer() { s.Run("send_uosmo_to_chainB", func() { - // compare coins of reciever pre and post IBC send + // compare coins of receiver pre and post IBC send // diff should only be the amount sent s.sendIBC(s.chains[0], s.chains[1], s.chains[1].Validators[0].PublicAddress, chain.OsmoToken) }) } + +func (s *IntegrationTestSuite) TestSuperfluidVoting() { + s.Run("superfluid_vote_chainA", func() { + s.submitSuperfluidProposal(s.chains[0], "gamm/pool/1") + s.depositProposal(s.chains[0]) + s.voteProposal(s.chains[0]) + //s.lockTokens(s.chains[0], "100000000000000000000gamm/pool/2", "1814400s") + delAddr := s.chains[0].Validators[1].OperAddress + fmt.Printf("DELADDR %s", delAddr) + s.superfluidDelegate(s.chains[0], "100000000000000000000gamm/pool/1", delAddr) + }) +} diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index 1a6c26f7870..cf985cbefb7 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "regexp" "strconv" "strings" "time" @@ -135,13 +136,13 @@ func (s *IntegrationTestSuite) sendIBC(srcChain *chain.Chain, dstChain *chain.Ch }, 5*time.Minute, time.Second, - "tx not recieved on destination chain", + "tx not received on destination chain", ) s.T().Log("successfully sent IBC tokens") } -func (s *IntegrationTestSuite) submitProposal(c *chain.Chain, upgradeHeight int) { +func (s *IntegrationTestSuite) submitUpgradeProposal(c *chain.Chain, upgradeHeight int) { upgradeHeightStr := strconv.Itoa(upgradeHeight) ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -180,14 +181,60 @@ func (s *IntegrationTestSuite) submitProposal(c *chain.Chain, upgradeHeight int) "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), ) - s.T().Log("successfully submitted proposal") + s.T().Log("successfully submitted upgrade proposal") + c.PropNumber = c.PropNumber + 1 +} + +func (s *IntegrationTestSuite) submitSuperfluidProposal(c *chain.Chain, asset string) { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + s.T().Logf("submitting superfluid proposal for asset %s on %s container: %s", asset, s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) + + var ( + outBuf bytes.Buffer + errBuf bytes.Buffer + ) + + s.Require().Eventually( + func() bool { + exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ + Context: ctx, + AttachStdout: true, + AttachStderr: true, + Container: s.valResources[c.ChainMeta.Id][0].Container.ID, + User: "root", + Cmd: []string{ + "osmosisd", "tx", "gov", "submit-proposal", "set-superfluid-assets-proposal", fmt.Sprintf("--superfluid-assets=%s", asset), fmt.Sprintf("--title=\"%s superfluid asset\"", asset), fmt.Sprintf("--description=\"%s superfluid asset\"", asset), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), + }, + }) + s.Require().NoError(err) + + err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ + Context: ctx, + Detach: false, + OutputStream: &outBuf, + ErrorStream: &errBuf, + }) + return strings.Contains(outBuf.String(), "code: 0") + }, + time.Minute, + time.Second, + "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), + ) + + s.T().Log("successfully submitted superfluid proposal") + c.PropNumber = c.PropNumber + 1 } func (s *IntegrationTestSuite) depositProposal(c *chain.Chain) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - s.T().Logf("depositing to upgrade proposal from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) + fmt.Printf("PROPNUMBER STRUCT %v\n", c.PropNumber) + propStr := strconv.Itoa(c.PropNumber) + fmt.Printf("PROPNUMBER DEPOSIT %v\n", propStr) + s.T().Logf("depositing to proposal from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) var ( outBuf bytes.Buffer @@ -203,7 +250,7 @@ func (s *IntegrationTestSuite) depositProposal(c *chain.Chain) { Container: s.valResources[c.ChainMeta.Id][0].Container.ID, User: "root", Cmd: []string{ - "osmosisd", "tx", "gov", "deposit", "1", "10000000stake", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test", + "osmosisd", "tx", "gov", "deposit", propStr, "500000000uosmo", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test", }, }) s.Require().NoError(err) @@ -222,14 +269,14 @@ func (s *IntegrationTestSuite) depositProposal(c *chain.Chain) { ) s.T().Log("successfully deposited to proposal") - } func (s *IntegrationTestSuite) voteProposal(c *chain.Chain) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - - s.T().Logf("voting for upgrade proposal for chain-id: %s", c.ChainMeta.Id) + propStr := strconv.Itoa(c.PropNumber) + fmt.Printf("PROPNUMBER VOTE %v\n", propStr) + s.T().Logf("voting for proposal for chain-id: %s", c.ChainMeta.Id) for i := range c.Validators { var ( @@ -246,7 +293,7 @@ func (s *IntegrationTestSuite) voteProposal(c *chain.Chain) { Container: s.valResources[c.ChainMeta.Id][i].Container.ID, User: "root", Cmd: []string{ - "osmosisd", "tx", "gov", "vote", "1", "yes", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test", + "osmosisd", "tx", "gov", "vote", propStr, "yes", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test", }, }) s.Require().NoError(err) @@ -257,6 +304,8 @@ func (s *IntegrationTestSuite) voteProposal(c *chain.Chain) { OutputStream: &outBuf, ErrorStream: &errBuf, }) + fmt.Printf("OUTBUF %s\n", outBuf.String()) + fmt.Printf("ERRBUF %s\n", errBuf.String()) return strings.Contains(outBuf.String(), "code: 0") }, time.Minute, @@ -308,9 +357,19 @@ func (s *IntegrationTestSuite) chainStatus(containerId string) []byte { func (s *IntegrationTestSuite) getCurrentChainHeight(containerId string) int { var block syncInfo - out := s.chainStatus(containerId) - err := json.Unmarshal(out, &block) - s.Require().NoError(err) + s.Require().Eventually( + func() bool { + out := s.chainStatus(containerId) + err := json.Unmarshal(out, &block) + if err != nil { + return false + } + return true + }, + 1*time.Minute, + time.Second, + "Osmosis node failed to retrieve height info", + ) currentHeight, err := strconv.Atoi(block.SyncInfo.LatestHeight) s.Require().NoError(err) return currentHeight @@ -397,3 +456,136 @@ func (s *IntegrationTestSuite) createPool(c *chain.Chain, poolFile string) { s.T().Logf("successfully created pool from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) } + +func (s *IntegrationTestSuite) lockTokens(c *chain.Chain, tokens string, duration string) { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + s.T().Logf("locking %s for %s on chain-id: %s", tokens, duration, c.ChainMeta.Id) + var ( + outBuf bytes.Buffer + errBuf bytes.Buffer + ) + + s.Require().Eventually( + func() bool { + exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ + Context: ctx, + AttachStdout: true, + AttachStderr: true, + Container: s.valResources[c.ChainMeta.Id][0].Container.ID, + User: "root", + Cmd: []string{ + "osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--duration=%s", duration), "--from=val", "-b=block", "--yes", "--keyring-backend=test", + }, + }) + s.Require().NoError(err) + err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ + Context: ctx, + Detach: false, + OutputStream: &outBuf, + ErrorStream: &errBuf, + }) + return strings.Contains(outBuf.String(), "code: 0") + }, + time.Minute, + time.Second, + "tx returned non code 0; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), + ) + + s.T().Logf("successfully created lock from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) + +} + +func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, tokens string, valAddress string) { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + s.T().Logf("superfluid delegating %s to %s on chain-id: %s", tokens, valAddress, c.ChainMeta.Id) + var ( + outBuf bytes.Buffer + errBuf bytes.Buffer + ) + + s.Require().Eventually( + func() bool { + exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ + Context: ctx, + AttachStdout: true, + AttachStderr: true, + Container: s.valResources[c.ChainMeta.Id][0].Container.ID, + User: "root", + Cmd: []string{ + "osmosisd", "tx", "superfluid", "lock-and-superfluid-delegate", "100000000000000000000gamm/pool/2", valAddress, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", + }, + }) + s.Require().NoError(err) + err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ + Context: ctx, + Detach: false, + OutputStream: &outBuf, + ErrorStream: &errBuf, + }) + return strings.Contains(outBuf.String(), "code: 0") + }, + time.Minute, + time.Second, + "tx returned non code 0; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), + ) + + s.T().Logf("successfully superfluid delegated from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) + +} + +func (s *IntegrationTestSuite) extractOperAddress(c *chain.Chain) { + // var oper operInfo + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + s.T().Logf("extracting validator operator address for chain-id: %s", c.ChainMeta.Id) + for i, val := range c.Validators { + + var ( + outBuf bytes.Buffer + errBuf bytes.Buffer + ) + + s.Require().Eventually( + func() bool { + exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ + Context: ctx, + AttachStdout: true, + AttachStderr: true, + Container: s.valResources[c.ChainMeta.Id][i].Container.ID, + User: "root", + Cmd: []string{ + "osmosisd", "debug", "addr", val.PublicKey, "--log_format=json", + }, + }) + s.Require().NoError(err) + + err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ + Context: ctx, + Detach: false, + OutputStream: &outBuf, + ErrorStream: &errBuf, + }) + if err != nil { + return false + } + return true + }, + time.Minute, + time.Second, + ) + re := regexp.MustCompile(`[^: ]*$`) + val.OperAddress = fmt.Sprintf("%s\n", re.FindString(errBuf.String())) + // valOper := valOperFull[0:len(valOperFull)-2] + // fmt.Printf("TESTING %s") + // errBufByte := errBuf.Bytes() + // err := json.Unmarshal(errBufByte, &oper) + // if err != nil { + // panic(err) + // } + // fmt.Printf("BECH32 VAL %v\n", oper.Bech32Val) + // val.OperAddress = oper.Bech32Val + + } +} diff --git a/tests/e2e/scripts/genesis_mod.sh b/tests/e2e/scripts/genesis_mod.sh new file mode 100755 index 00000000000..3eef8b8f032 --- /dev/null +++ b/tests/e2e/scripts/genesis_mod.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# change staking denom to uosmo +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json +# update staking genesis +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["staking"]["params"]["unbonding_time"]="240s"' | sponge $HOME/.osmosisd/config/genesis.json +# update crisis variable to uosmo +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json +# udpate gov genesis +# cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="60s"' | sponge $HOME/.osmosisd/config/genesis.json +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json +# update epochs genesis +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["epochs"]["epochs"][1]["duration"]="60s"' | sponge $HOME/.osmosisd/config/genesis.json +# update poolincentives genesis +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["lockable_durations"][0]="120s"' | sponge $HOME/.osmosisd/config/genesis.json +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["lockable_durations"][1]="180s"' | sponge $HOME/.osmosisd/config/genesis.json +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["lockable_durations"][2]="240s"' | sponge $HOME/.osmosisd/config/genesis.json +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["params"]["minted_denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json +# update incentives genesis +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][0]="1s"' | sponge $HOME/.osmosisd/config/genesis.json +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][1]="120s"' | sponge $HOME/.osmosisd/config/genesis.json +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][2]="180s"' | sponge $HOME/.osmosisd/config/genesis.json +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][3]="240s"' | sponge $HOME/.osmosisd/config/genesis.json +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["params"]["distr_epoch_identifier"]="day"' | sponge $HOME/.osmosisd/config/genesis.json +# update mint genesis +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["mint"]["params"]["epoch_identifier"]="day"' | sponge $HOME/.osmosisd/config/genesis.json +# update gamm genesis +cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["gamm"]["params"]["pool_creation_fee"][0]["denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json +# remove seeds +sed -i.bak -E 's#^(seeds[[:space:]]+=[[:space:]]+).*$#\1""#' ~/.osmosisd/config/config.toml + +osmosisd start diff --git a/tests/e2e/scripts/hermes_bootstrap.sh b/tests/e2e/scripts/hermes_bootstrap.sh index 4a438c1f9ff..273e8177ea5 100644 --- a/tests/e2e/scripts/hermes_bootstrap.sh +++ b/tests/e2e/scripts/hermes_bootstrap.sh @@ -45,7 +45,7 @@ max_gas = 6000000 gas_price = { price = 0.000, denom = 'stake' } gas_adjustment = 1.0 clock_drift = '1m' # to accomdate docker containers -trusting_period = '14days' +trusting_period = '239seconds' trust_threshold = { numerator = '1', denominator = '3' } [[chains]] id = '$OSMO_B_E2E_CHAIN_ID' @@ -60,7 +60,7 @@ max_gas = 6000000 gas_price = { price = 0.000, denom = 'stake' } gas_adjustment = 1.0 clock_drift = '1m' # to accomdate docker containers -trusting_period = '14days' +trusting_period = '239seconds' trust_threshold = { numerator = '1', denominator = '3' } EOF From f416f6f9f6aadcb25f366640f131d51f7ce7c31a Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 23 May 2022 17:40:23 -0500 Subject: [PATCH 02/20] currently working --- Dockerfile | 2 +- tests/e2e/chain_init/chain-init.Dockerfile | 14 ++++++++++---- tests/e2e/e2e_setup_test.go | 2 ++ tests/e2e/e2e_test.go | 5 ++--- tests/e2e/e2e_util_test.go | 12 +++++++----- tests/e2e/scripts/.bash_history | 18 ++++++++++++++++++ tests/e2e/scripts/pool2A.json | 4 ++-- tests/e2e/scripts/pool2B.json | 4 ++-- 8 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 tests/e2e/scripts/.bash_history diff --git a/Dockerfile b/Dockerfile index a2b842b6f91..a5d01f74b9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,7 @@ RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build # -------------------------------------------------------- FROM ubuntu +RUN apt-get update && apt-get install -y jq moreutils COPY --from=build /osmosis/build/osmosisd /bin/osmosisd @@ -43,4 +44,3 @@ EXPOSE 26657 EXPOSE 1317 ENTRYPOINT ["osmosisd"] -CMD [ "start" ] diff --git a/tests/e2e/chain_init/chain-init.Dockerfile b/tests/e2e/chain_init/chain-init.Dockerfile index 6c807829b5b..e5b86262413 100644 --- a/tests/e2e/chain_init/chain-init.Dockerfile +++ b/tests/e2e/chain_init/chain-init.Dockerfile @@ -13,14 +13,20 @@ RUN apk add linux-headers WORKDIR /osmosis COPY . /osmosis -# From https://github.com/CosmWasm/wasmd/blob/master/Dockerfile -# For more details see https://github.com/CosmWasm/wasmvm#builds-of-libwasmvm -ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.a -RUN sha256sum /lib/libwasmvm_muslc.a | grep f6282df732a13dec836cda1f399dd874b1e3163504dbd9607c6af915b2740479 +# CosmWasm: see https://github.com/CosmWasm/wasmvm/releases +ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a +ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a +RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 7d2239e9f25e96d0d4daba982ce92367aacf0cbd95d2facb8442268f2b1cc1fc +RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep f6282df732a13dec836cda1f399dd874b1e3163504dbd9607c6af915b2740479 + +# CosmWasm: copy the right library according to architecture. The final location will be found by the linker flag `-lwasmvm_muslc` +RUN cp /lib/libwasmvm_muslc.$(uname -m).a /lib/libwasmvm_muslc.a + RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build-e2e-chain-init ## Deploy image FROM ubuntu +RUN apt-get update && apt-get install -y jq moreutils COPY --from=build /osmosis/build/chain_init /bin/chain_init diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index a7715db1dd5..c97c813b2f3 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -155,6 +155,8 @@ func (s *IntegrationTestSuite) SetupSuite() { if skipUpgrade { debugRepository = "osmosis" debugVersion = "debug" + initRepository = "osmosis-e2e-chain-init" + initVersion = "debug" s.configureDockerResources(chain.ChainAID, chain.ChainBID) s.configureChain(chain.ChainAID, validatorConfigsChainA) s.configureChain(chain.ChainBID, validatorConfigsChainB) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 49c77714375..48ec7406b05 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -20,8 +20,7 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { s.depositProposal(s.chains[0]) s.voteProposal(s.chains[0]) //s.lockTokens(s.chains[0], "100000000000000000000gamm/pool/2", "1814400s") - delAddr := s.chains[0].Validators[1].OperAddress - fmt.Printf("DELADDR %s", delAddr) - s.superfluidDelegate(s.chains[0], "100000000000000000000gamm/pool/1", delAddr) + fmt.Printf("DELADDR %s", s.chains[0].Validators[1].OperAddress) + s.superfluidDelegate(s.chains[0], "100000000000000000000gamm/pool/1", s.chains[0].Validators[1].OperAddress) }) } diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index cf985cbefb7..41f090fbf07 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -514,7 +514,7 @@ func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, tokens string, Container: s.valResources[c.ChainMeta.Id][0].Container.ID, User: "root", Cmd: []string{ - "osmosisd", "tx", "superfluid", "lock-and-superfluid-delegate", "100000000000000000000gamm/pool/2", valAddress, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", + "osmosisd", "tx", "superfluid", "lock-and-superfluid-delegate", fmt.Sprintf("%s", tokens), fmt.Sprintf("%s", valAddress), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", }, }) s.Require().NoError(err) @@ -526,7 +526,7 @@ func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, tokens string, }) return strings.Contains(outBuf.String(), "code: 0") }, - time.Minute, + 5*time.Minute, time.Second, "tx returned non code 0; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), ) @@ -556,7 +556,7 @@ func (s *IntegrationTestSuite) extractOperAddress(c *chain.Chain) { Container: s.valResources[c.ChainMeta.Id][i].Container.ID, User: "root", Cmd: []string{ - "osmosisd", "debug", "addr", val.PublicKey, "--log_format=json", + "osmosisd", "debug", "addr", val.PublicKey, }, }) s.Require().NoError(err) @@ -575,8 +575,10 @@ func (s *IntegrationTestSuite) extractOperAddress(c *chain.Chain) { time.Minute, time.Second, ) - re := regexp.MustCompile(`[^: ]*$`) - val.OperAddress = fmt.Sprintf("%s\n", re.FindString(errBuf.String())) + re := regexp.MustCompile("osmovaloper(.{39})") + + operAddr := fmt.Sprintf("%s\n", re.FindString(errBuf.String())) + val.OperAddress = strings.TrimSuffix(operAddr, "\n") // valOper := valOperFull[0:len(valOperFull)-2] // fmt.Printf("TESTING %s") // errBufByte := errBuf.Bytes() diff --git a/tests/e2e/scripts/.bash_history b/tests/e2e/scripts/.bash_history new file mode 100644 index 00000000000..70979d3617a --- /dev/null +++ b/tests/e2e/scripts/.bash_history @@ -0,0 +1,18 @@ +osmosisd q gov proposals +osmosisd q superfluid -h +osmosisd q superfluid all-superfluid-assets +osmosisd q gamm pools +exit +osmosisd q gamm pools +osmosisd q superfluid +osmosisd q superfluid all-superfluid-assets +osmosisd tx superfluid lock-and-superfluid-delegate 100000000000000000000gamm/pool/1 osmovaloper1dma9s7mvgj6r6h8gyql08kw0kyqm7phct3hmml --chain-id osmo-test-a -b block --from val +osmosisd tx superfluid lock-and-superfluid-delegate 100000000000000000000gamm/pool/1 osmovaloper1dma9s7mvgj6r6h8gyql08kw0kyqm7phct3hmml --chain-id osmo-test-a -b block --from val --keyring-backend tes +osmosisd tx superfluid lock-and-superfluid-delegate 100000000000000000000gamm/pool/1 osmovaloper1dma9s7mvgj6r6h8gyql08kw0kyqm7phct3hmml --chain-id osmo-test-a -b block --from val --keyring-backend test +exit +osmosisd debug addr fadssfadsdsf +osmosisd debug addr -h +osmosisd debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg +osmosisd status +osmosisd debug addr 9AD1DD4F5ADE6C731665FA63BFFD632E8293B3A5 +exit diff --git a/tests/e2e/scripts/pool2A.json b/tests/e2e/scripts/pool2A.json index 18935f15945..86e86c56ff9 100644 --- a/tests/e2e/scripts/pool2A.json +++ b/tests/e2e/scripts/pool2A.json @@ -1,6 +1,6 @@ { - "weights": "5ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518,5stake", - "initial-deposit": "499404ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518,500000stake", + "weights": "5uosmo,5stake", + "initial-deposit": "499404uosmo,500000stake", "swap-fee": "0.01", "exit-fee": "0.01", "future-governor": "" diff --git a/tests/e2e/scripts/pool2B.json b/tests/e2e/scripts/pool2B.json index 2bc62445f50..730a02acb80 100644 --- a/tests/e2e/scripts/pool2B.json +++ b/tests/e2e/scripts/pool2B.json @@ -1,6 +1,6 @@ { - "weights": "5ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878,5stake", - "initial-deposit": "499404ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878,500000stake", + "weights": "5ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878,5uosmo", + "initial-deposit": "499404ibc/C053D637CCA2A2BA030E2C5EE1B28A16F71CCB0E45E8BE52766DC1B241B77878,500000uosmo", "swap-fee": "0.01", "exit-fee": "0.01", "future-governor": "" From 6d7c5d45fded35201a9d04ee3ef0a6f0646cf723 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 25 May 2022 13:06:11 -0500 Subject: [PATCH 03/20] superfluid vote overwrite test --- Dockerfile | 1 + tests/e2e/chain/chain.go | 3 + tests/e2e/chain/config.go | 162 +++++++++++++++ tests/e2e/chain/export.go | 16 +- tests/e2e/e2e_setup_test.go | 22 ++- tests/e2e/e2e_test.go | 66 +++++-- tests/e2e/e2e_util_test.go | 274 +++++++++++++++++++++++--- tests/e2e/scripts/hermes_bootstrap.sh | 4 +- 8 files changed, 496 insertions(+), 52 deletions(-) diff --git a/Dockerfile b/Dockerfile index a5d01f74b9d..108cbe4e49b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,3 +44,4 @@ EXPOSE 26657 EXPOSE 1317 ENTRYPOINT ["osmosisd"] +CMD [ "start" ] \ No newline at end of file diff --git a/tests/e2e/chain/chain.go b/tests/e2e/chain/chain.go index a746bcc7440..ab8818d6f1a 100644 --- a/tests/e2e/chain/chain.go +++ b/tests/e2e/chain/chain.go @@ -41,6 +41,9 @@ func (c *internalChain) createAndInitValidators(count int) error { if err := node.createKey("val"); err != nil { return err } + if err := node.createKey("val2"); err != nil { + return err + } if err := node.createNodeKey(); err != nil { return err } diff --git a/tests/e2e/chain/config.go b/tests/e2e/chain/config.go index 848b5029ade..daa9ed3ebcf 100644 --- a/tests/e2e/chain/config.go +++ b/tests/e2e/chain/config.go @@ -12,13 +12,22 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + staketypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/spf13/viper" tmconfig "github.com/tendermint/tendermint/config" tmjson "github.com/tendermint/tendermint/libs/json" + epochtypes "github.com/osmosis-labs/osmosis/v7/x/epochs/types" + gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types" + incentivestypes "github.com/osmosis-labs/osmosis/v7/x/incentives/types" + minttypes "github.com/osmosis-labs/osmosis/v7/x/mint/types" + poolitypes "github.com/osmosis-labs/osmosis/v7/x/pool-incentives/types" + txfeestypes "github.com/osmosis-labs/osmosis/v7/x/txfees/types" + "github.com/osmosis-labs/osmosis/v7/tests/e2e/util" ) @@ -171,6 +180,157 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } appGenState[banktypes.ModuleName] = bz + var stakeGenState staketypes.GenesisState + if err := util.Cdc.UnmarshalJSON(appGenState[staketypes.ModuleName], &stakeGenState); err != nil { + return err + } + + stakeGenState.Params = staketypes.Params{ + BondDenom: OsmoDenom, + MaxValidators: 100, + MaxEntries: 7, + HistoricalEntries: 10000, + UnbondingTime: 240000000000, + MinCommissionRate: sdk.ZeroDec(), + } + + sz, err := util.Cdc.MarshalJSON(&stakeGenState) + if err != nil { + return err + } + appGenState[staketypes.ModuleName] = sz + + var pooliGenState poolitypes.GenesisState + if err := util.Cdc.UnmarshalJSON(appGenState[poolitypes.ModuleName], &pooliGenState); err != nil { + return err + } + + pooliGenState.LockableDurations = + []time.Duration{ + time.Second * 120, + time.Second * 180, + time.Second * 240, + } + + pooliGenState.Params = poolitypes.Params{ + MintedDenom: OsmoDenom, + } + + pz, err := util.Cdc.MarshalJSON(&pooliGenState) + if err != nil { + return err + } + appGenState[poolitypes.ModuleName] = pz + + var incentivesGenState incentivestypes.GenesisState + if err := util.Cdc.UnmarshalJSON(appGenState[incentivestypes.ModuleName], &incentivesGenState); err != nil { + return err + } + + incentivesGenState.LockableDurations = + []time.Duration{ + time.Second, + time.Second * 120, + time.Second * 180, + time.Second * 240, + } + + incentivesGenState.Params = incentivestypes.Params{ + DistrEpochIdentifier: "day", + } + + iz, err := util.Cdc.MarshalJSON(&incentivesGenState) + if err != nil { + return err + } + appGenState[incentivestypes.ModuleName] = iz + + var mintGenState minttypes.GenesisState + if err := util.Cdc.UnmarshalJSON(appGenState[minttypes.ModuleName], &mintGenState); err != nil { + return err + } + + mintGenState.Params.MintDenom = OsmoDenom + mintGenState.Params.EpochIdentifier = "day" + + mz, err := util.Cdc.MarshalJSON(&mintGenState) + if err != nil { + return err + } + appGenState[minttypes.ModuleName] = mz + + var txfeesGenState txfeestypes.GenesisState + if err := util.Cdc.UnmarshalJSON(appGenState[txfeestypes.ModuleName], &txfeesGenState); err != nil { + return err + } + + txfeesGenState.Basedenom = OsmoDenom + + tz, err := util.Cdc.MarshalJSON(&txfeesGenState) + if err != nil { + return err + } + appGenState[txfeestypes.ModuleName] = tz + + var gammGenState gammtypes.GenesisState + if err := util.Cdc.UnmarshalJSON(appGenState[gammtypes.ModuleName], &gammGenState); err != nil { + return err + } + + gammGenState.Params.PoolCreationFee = sdk.Coins{sdk.NewInt64Coin(OsmoDenom, 10000000)} + + gaz, err := util.Cdc.MarshalJSON(&gammGenState) + if err != nil { + return err + } + appGenState[gammtypes.ModuleName] = gaz + + var epochGenState epochtypes.GenesisState + if err := util.Cdc.UnmarshalJSON(appGenState[epochtypes.ModuleName], &epochGenState); err != nil { + return err + } + + epochGenState.Epochs = + []epochtypes.EpochInfo{ + { + Identifier: "week", + StartTime: time.Time{}, + Duration: time.Hour * 24 * 7, + CurrentEpoch: 0, + CurrentEpochStartHeight: 0, + CurrentEpochStartTime: time.Time{}, + EpochCountingStarted: false, + }, + { + Identifier: "day", + StartTime: time.Time{}, + Duration: time.Second * 60, + CurrentEpoch: 0, + CurrentEpochStartHeight: 0, + CurrentEpochStartTime: time.Time{}, + EpochCountingStarted: false, + }, + } + + ez, err := util.Cdc.MarshalJSON(&epochGenState) + if err != nil { + return err + } + appGenState[epochtypes.ModuleName] = ez + + var crisisGenState crisistypes.GenesisState + if err := util.Cdc.UnmarshalJSON(appGenState[crisistypes.ModuleName], &crisisGenState); err != nil { + return err + } + + crisisGenState.ConstantFee.Denom = OsmoDenom + + cz, err := util.Cdc.MarshalJSON(&crisisGenState) + if err != nil { + return err + } + appGenState[crisistypes.ModuleName] = cz + var govGenState govtypes.GenesisState if err := util.Cdc.UnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState); err != nil { return err @@ -180,6 +340,8 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { VotingPeriod: votingPeriod, } + govGenState.DepositParams.MinDeposit = sdk.Coins{sdk.NewInt64Coin(OsmoDenom, 10000000)} + gz, err := util.Cdc.MarshalJSON(&govGenState) if err != nil { return err diff --git a/tests/e2e/chain/export.go b/tests/e2e/chain/export.go index 2c6811258ca..b2ddab9e9ac 100644 --- a/tests/e2e/chain/export.go +++ b/tests/e2e/chain/export.go @@ -8,19 +8,21 @@ type ChainMeta struct { } type Validator struct { - Name string `json:"name"` - ConfigDir string `json:"configDir"` - Index int `json:"index"` - Mnemonic string `json:"mnemonic"` - PublicAddress string `json:"publicAddress"` - PublicKey string `json:"publicKey"` - OperAddress string `json:"operAddress"` + Name string `json:"name"` + ConfigDir string `json:"configDir"` + Index int `json:"index"` + Mnemonic string `json:"mnemonic"` + PublicAddress string `json:"publicAddress"` + PublicAddress2 string `json:"publicAddress2"` + PublicKey string `json:"publicKey"` + OperAddress string `json:"operAddress"` } type Chain struct { ChainMeta ChainMeta `json:"chainMeta"` Validators []*Validator `json:"validators"` PropNumber int `json:"propNumber"` + LockNumber int `json:"lockNumber"` } func (c *ChainMeta) configDir() string { diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index c97c813b2f3..d178aea3b0e 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -29,10 +29,10 @@ var ( upgradeVersion = "v9" // osmosis repo/version for initialization (this should be one version below upgradeVersion) initRepository = "osmolabs/osmosis-init" - initVersion = "v8.0.0-1-osmo" + initVersion = "v8.0.0-2-osmo" // pre upgrade osmosis repo/version to pull (should match initVersion numer) debugRepository = "osmolabs/osmosis-dev" - debugVersion = "v8.0.0-1-debug" + debugVersion = "v8.0.0-2-debug" // hermes repo/version for relayer relayerRepository = "osmolabs/hermes" relayerVersion = "0.13.0" @@ -123,8 +123,13 @@ type status struct { LatestHeight string `json:"latest_block_height"` } +type valinfo struct { + VotingPower string `json:"VotingPower"` +} + type syncInfo struct { - SyncInfo status `json:"SyncInfo"` + SyncInfo status `json:"SyncInfo"` + ValidatorInfo valinfo `json:"ValidatorInfo"` } type operInfo struct { @@ -233,10 +238,13 @@ func (s *IntegrationTestSuite) runValidators(c *chain.Chain, portOffset int) { }, Repository: debugRepository, Tag: debugVersion, - Entrypoint: []string{ - "sh", - "-c", - "chmod +x /osmosis/genesis_mod.sh && /osmosis/genesis_mod.sh", + // Entrypoint: []string{ + // "sh", + // "-c", + // "chmod +x /osmosis/genesis_mod.sh && /osmosis/genesis_mod.sh", + // }, + Cmd: []string{ + "start", }, } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 48ec7406b05..b5187bad26a 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -2,25 +2,65 @@ package e2e import ( "fmt" - - "github.com/osmosis-labs/osmosis/v7/tests/e2e/chain" + "strconv" + "time" ) -func (s *IntegrationTestSuite) TestIBCTokenTransfer() { - s.Run("send_uosmo_to_chainB", func() { - // compare coins of receiver pre and post IBC send - // diff should only be the amount sent - s.sendIBC(s.chains[0], s.chains[1], s.chains[1].Validators[0].PublicAddress, chain.OsmoToken) - }) -} - func (s *IntegrationTestSuite) TestSuperfluidVoting() { s.Run("superfluid_vote_chainA", func() { s.submitSuperfluidProposal(s.chains[0], "gamm/pool/1") s.depositProposal(s.chains[0]) s.voteProposal(s.chains[0]) - //s.lockTokens(s.chains[0], "100000000000000000000gamm/pool/2", "1814400s") - fmt.Printf("DELADDR %s", s.chains[0].Validators[1].OperAddress) - s.superfluidDelegate(s.chains[0], "100000000000000000000gamm/pool/1", s.chains[0].Validators[1].OperAddress) + // send gamm tokens to validator's other wallet (non self-delegation wallet) + s.sendTx(s.chains[0], 0, "100000000000000000000gamm/pool/1", s.chains[0].Validators[0].PublicAddress, s.chains[0].Validators[0].PublicAddress2) + // lock tokens from validator 0 on chain A + s.lockTokens(s.chains[0], 0, "100000000000000000000gamm/pool/1", "240s", "val2") + // superfluid delegate from validator 0 non self-delegation wallet to validator 1 on chain A + s.superfluidDelegate(s.chains[0], "100000000000000000000gamm/pool/1", s.chains[0].Validators[1].OperAddress, "val2") + // create a text prop, deposit and vote yes + s.submitTextProposal(s.chains[0], "superfluid vote overwrite test") + s.depositProposal(s.chains[0]) + s.voteProposal(s.chains[0]) + // set delegator vote to no + s.voteNoProposal(s.chains[0], 0, "val2") + + chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chains[0].ChainMeta.Id][0].GetHostPort("1317/tcp")) + sfProposalNumber := strconv.Itoa(s.chains[0].PropNumber) + s.Require().Eventually( + func() bool { + noTotal, yesTotal, noWithVetoTotal, abstainTotal, err := s.queryPropTally(chainAAPIEndpoint, sfProposalNumber) + if err != nil { + return false + } + if abstainTotal.Int64()+noTotal.Int64()+noWithVetoTotal.Int64()+yesTotal.Int64() <= 0 { + return false + } + return true + }, + 1*time.Minute, + time.Second, + "Osmosis node failed to retrieve prop tally", + ) + noTotal, _, _, _, _ := s.queryPropTally(chainAAPIEndpoint, sfProposalNumber) + noTotalFinal, err := strconv.Atoi(noTotal.String()) + s.Require().NoError(err) + + s.Require().Eventually( + func() bool { + intAccountBalance, err := s.queryIntermediaryAccount(s.chains[0], chainAAPIEndpoint, "gamm/pool/1", s.chains[0].Validators[1].OperAddress) + s.Require().NoError(err) + if err != nil { + return false + } + if noTotalFinal != intAccountBalance { + fmt.Printf("noTotalFinal %v does not match intAccountBalance %v", noTotalFinal, intAccountBalance) + return false + } + return true + }, + 1*time.Minute, + time.Second, + "superfluid delegation vote overwrite not working as expected", + ) }) } diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index 41f090fbf07..412d70e4a7b 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -5,6 +5,8 @@ import ( "context" "encoding/json" "fmt" + "io" + "net/http" "regexp" "strconv" "strings" @@ -12,8 +14,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ory/dockertest/v3/docker" + superfluidtypes "github.com/osmosis-labs/osmosis/v7/x/superfluid/types" + "github.com/osmosis-labs/osmosis/v7/tests/e2e/chain" "github.com/osmosis-labs/osmosis/v7/tests/e2e/util" ) @@ -227,13 +233,54 @@ func (s *IntegrationTestSuite) submitSuperfluidProposal(c *chain.Chain, asset st c.PropNumber = c.PropNumber + 1 } +func (s *IntegrationTestSuite) submitTextProposal(c *chain.Chain, text string) { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + s.T().Logf("submitting text proposal on %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) + + var ( + outBuf bytes.Buffer + errBuf bytes.Buffer + ) + + s.Require().Eventually( + func() bool { + exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ + Context: ctx, + AttachStdout: true, + AttachStderr: true, + Container: s.valResources[c.ChainMeta.Id][0].Container.ID, + User: "root", + Cmd: []string{ + "osmosisd", "tx", "gov", "submit-proposal", "--type=text", fmt.Sprintf("--title=\"%s\"", text), "--description=\"test text proposal\"", "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), + }, + }) + s.Require().NoError(err) + + err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ + Context: ctx, + Detach: false, + OutputStream: &outBuf, + ErrorStream: &errBuf, + }) + return strings.Contains(outBuf.String(), "code: 0") + }, + time.Minute, + time.Second, + "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), + ) + + s.T().Log("successfully submitted text proposal") + c.PropNumber = c.PropNumber + 1 +} + func (s *IntegrationTestSuite) depositProposal(c *chain.Chain) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - fmt.Printf("PROPNUMBER STRUCT %v\n", c.PropNumber) propStr := strconv.Itoa(c.PropNumber) - fmt.Printf("PROPNUMBER DEPOSIT %v\n", propStr) + s.T().Logf("depositing to proposal from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) var ( @@ -275,7 +322,6 @@ func (s *IntegrationTestSuite) voteProposal(c *chain.Chain) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() propStr := strconv.Itoa(c.PropNumber) - fmt.Printf("PROPNUMBER VOTE %v\n", propStr) s.T().Logf("voting for proposal for chain-id: %s", c.ChainMeta.Id) for i := range c.Validators { @@ -304,8 +350,6 @@ func (s *IntegrationTestSuite) voteProposal(c *chain.Chain) { OutputStream: &outBuf, ErrorStream: &errBuf, }) - fmt.Printf("OUTBUF %s\n", outBuf.String()) - fmt.Printf("ERRBUF %s\n", errBuf.String()) return strings.Contains(outBuf.String(), "code: 0") }, time.Minute, @@ -317,6 +361,48 @@ func (s *IntegrationTestSuite) voteProposal(c *chain.Chain) { } } +func (s *IntegrationTestSuite) voteNoProposal(c *chain.Chain, i int, from string) { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + propStr := strconv.Itoa(c.PropNumber) + s.T().Logf("voting no for proposal for chain-id: %s", c.ChainMeta.Id) + + var ( + outBuf bytes.Buffer + errBuf bytes.Buffer + ) + + s.Require().Eventually( + func() bool { + exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ + Context: ctx, + AttachStdout: true, + AttachStderr: true, + Container: s.valResources[c.ChainMeta.Id][i].Container.ID, + User: "root", + Cmd: []string{ + "osmosisd", "tx", "gov", "vote", propStr, "no", fmt.Sprintf("--from=%s", from), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test", + }, + }) + s.Require().NoError(err) + + err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ + Context: ctx, + Detach: false, + OutputStream: &outBuf, + ErrorStream: &errBuf, + }) + return strings.Contains(outBuf.String(), "code: 0") + }, + time.Minute, + time.Second, + "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), + ) + + s.T().Logf("successfully voted no for proposal from %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + +} + func (s *IntegrationTestSuite) chainStatus(containerId string) []byte { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -375,6 +461,26 @@ func (s *IntegrationTestSuite) getCurrentChainHeight(containerId string) int { return currentHeight } +func (s *IntegrationTestSuite) getValidatorPower(containerId string) int { + var block syncInfo + s.Require().Eventually( + func() bool { + out := s.chainStatus(containerId) + err := json.Unmarshal(out, &block) + if err != nil { + return false + } + return true + }, + 1*time.Minute, + time.Second, + "Osmosis node failed to retrieve height info", + ) + votingPower, err := strconv.Atoi(block.ValidatorInfo.VotingPower) + s.Require().NoError(err) + return votingPower +} + func (s *IntegrationTestSuite) queryBalances(containerId string, addr string) (sdk.Coins, error) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -418,6 +524,51 @@ func (s *IntegrationTestSuite) queryBalances(containerId string, addr string) (s } +func (s *IntegrationTestSuite) queryPropTally(endpoint, addr string) (sdk.Int, sdk.Int, sdk.Int, sdk.Int, error) { + path := fmt.Sprintf( + "%s/cosmos/gov/v1beta1/proposals/%s/tally", + endpoint, addr, + ) + var err error + var resp *http.Response + retriesLeft := 5 + for { + resp, err = http.Get(path) + + if resp.StatusCode == http.StatusServiceUnavailable { + retriesLeft-- + if retriesLeft == 0 { + return sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), fmt.Errorf("exceeded retry limit of %d with %d", retriesLeft, http.StatusServiceUnavailable) + } + time.Sleep(10 * time.Second) + } else { + break + } + } + + if err != nil { + return sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), fmt.Errorf("failed to execute HTTP request: %w", err) + } + + defer resp.Body.Close() + + bz, err := io.ReadAll(resp.Body) + if err != nil { + return sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), err + } + + var balancesResp govtypes.QueryTallyResultResponse + if err := util.Cdc.UnmarshalJSON(bz, &balancesResp); err != nil { + return sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), err + } + noTotal := balancesResp.Tally.No + yesTotal := balancesResp.Tally.Yes + noWithVetoTotal := balancesResp.Tally.NoWithVeto + abstainTotal := balancesResp.Tally.Abstain + + return noTotal, yesTotal, noWithVetoTotal, abstainTotal, nil +} + func (s *IntegrationTestSuite) createPool(c *chain.Chain, poolFile string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -457,7 +608,7 @@ func (s *IntegrationTestSuite) createPool(c *chain.Chain, poolFile string) { } -func (s *IntegrationTestSuite) lockTokens(c *chain.Chain, tokens string, duration string) { +func (s *IntegrationTestSuite) lockTokens(c *chain.Chain, i int, tokens string, duration string, from string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() s.T().Logf("locking %s for %s on chain-id: %s", tokens, duration, c.ChainMeta.Id) @@ -472,10 +623,10 @@ func (s *IntegrationTestSuite) lockTokens(c *chain.Chain, tokens string, duratio Context: ctx, AttachStdout: true, AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][0].Container.ID, + Container: s.valResources[c.ChainMeta.Id][i].Container.ID, User: "root", Cmd: []string{ - "osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--duration=%s", duration), "--from=val", "-b=block", "--yes", "--keyring-backend=test", + "osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--duration=%s", duration), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test", }, }) s.Require().NoError(err) @@ -491,15 +642,16 @@ func (s *IntegrationTestSuite) lockTokens(c *chain.Chain, tokens string, duratio time.Second, "tx returned non code 0; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), ) - - s.T().Logf("successfully created lock from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) + c.LockNumber = c.LockNumber + 1 + s.T().Logf("successfully created lock %v from %s container: %s", c.LockNumber, s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) } -func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, tokens string, valAddress string) { +func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, tokens string, valAddress string, from string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() s.T().Logf("superfluid delegating %s to %s on chain-id: %s", tokens, valAddress, c.ChainMeta.Id) + lockStr := strconv.Itoa(c.LockNumber) var ( outBuf bytes.Buffer errBuf bytes.Buffer @@ -514,7 +666,7 @@ func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, tokens string, Container: s.valResources[c.ChainMeta.Id][0].Container.ID, User: "root", Cmd: []string{ - "osmosisd", "tx", "superfluid", "lock-and-superfluid-delegate", fmt.Sprintf("%s", tokens), fmt.Sprintf("%s", valAddress), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", + "osmosisd", "tx", "superfluid", "delegate", lockStr, valAddress, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test", }, }) s.Require().NoError(err) @@ -535,11 +687,51 @@ func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, tokens string, } +func (s *IntegrationTestSuite) sendTx(c *chain.Chain, i int, amount string, sendAddress string, receiveAddress string) { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + s.T().Logf("sending %s from %s to %s on chain-id: %s", amount, sendAddress, receiveAddress, c.ChainMeta.Id) + + var ( + outBuf bytes.Buffer + errBuf bytes.Buffer + ) + + s.Require().Eventually( + func() bool { + exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ + Context: ctx, + AttachStdout: true, + AttachStderr: true, + Container: s.valResources[c.ChainMeta.Id][i].Container.ID, + User: "root", + Cmd: []string{ + "osmosisd", "tx", "bank", "send", sendAddress, receiveAddress, amount, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", + }, + }) + s.Require().NoError(err) + err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ + Context: ctx, + Detach: false, + OutputStream: &outBuf, + ErrorStream: &errBuf, + }) + return strings.Contains(outBuf.String(), "code: 0") + }, + 5*time.Minute, + time.Second, + "tx returned non code 0; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), + ) + + s.T().Logf("successfully sent tx from %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + +} + func (s *IntegrationTestSuite) extractOperAddress(c *chain.Chain) { // var oper operInfo ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - s.T().Logf("extracting validator operator address for chain-id: %s", c.ChainMeta.Id) + s.T().Logf("extracting validator operator addresses for chain-id: %s", c.ChainMeta.Id) for i, val := range c.Validators { var ( @@ -576,18 +768,54 @@ func (s *IntegrationTestSuite) extractOperAddress(c *chain.Chain) { time.Second, ) re := regexp.MustCompile("osmovaloper(.{39})") - operAddr := fmt.Sprintf("%s\n", re.FindString(errBuf.String())) val.OperAddress = strings.TrimSuffix(operAddr, "\n") - // valOper := valOperFull[0:len(valOperFull)-2] - // fmt.Printf("TESTING %s") - // errBufByte := errBuf.Bytes() - // err := json.Unmarshal(errBufByte, &oper) - // if err != nil { - // panic(err) - // } - // fmt.Printf("BECH32 VAL %v\n", oper.Bech32Val) - // val.OperAddress = oper.Bech32Val } } + +func (s *IntegrationTestSuite) queryIntermediaryAccount(c *chain.Chain, endpoint string, denom string, valAddr string) (int, error) { + intAccount := superfluidtypes.GetSuperfluidIntermediaryAccountAddr(denom, valAddr) + path := fmt.Sprintf( + "%s/cosmos/staking/v1beta1/validators/%s/delegations/%s", + endpoint, valAddr, intAccount, + ) + var err error + var resp *http.Response + retriesLeft := 5 + for { + resp, err = http.Get(path) + + if resp.StatusCode == http.StatusServiceUnavailable { + retriesLeft-- + if retriesLeft == 0 { + return 0, fmt.Errorf("exceeded retry limit of %d with %d", retriesLeft, http.StatusServiceUnavailable) + } + time.Sleep(10 * time.Second) + } else { + break + } + } + + if err != nil { + return 0, fmt.Errorf("failed to execute HTTP request: %w", err) + } + + defer resp.Body.Close() + + bz, err := io.ReadAll(resp.Body) + if err != nil { + return 0, err + } + + var stakingResp stakingtypes.QueryDelegationResponse + if err := util.Cdc.UnmarshalJSON(bz, &stakingResp); err != nil { + return 0, err + } + + intAccBalance := stakingResp.DelegationResponse.Balance.Amount.String() + intAccountBalance, err := strconv.Atoi(intAccBalance) + s.Require().NoError(err) + return intAccountBalance, err + +} diff --git a/tests/e2e/scripts/hermes_bootstrap.sh b/tests/e2e/scripts/hermes_bootstrap.sh index 273e8177ea5..ce7d2f8dc94 100644 --- a/tests/e2e/scripts/hermes_bootstrap.sh +++ b/tests/e2e/scripts/hermes_bootstrap.sh @@ -42,7 +42,7 @@ account_prefix = 'osmo' key_name = 'val01-osmosis-a' store_prefix = 'ibc' max_gas = 6000000 -gas_price = { price = 0.000, denom = 'stake' } +gas_price = { price = 0.000, denom = 'uosmo' } gas_adjustment = 1.0 clock_drift = '1m' # to accomdate docker containers trusting_period = '239seconds' @@ -57,7 +57,7 @@ account_prefix = 'osmo' key_name = 'val01-osmosis-b' store_prefix = 'ibc' max_gas = 6000000 -gas_price = { price = 0.000, denom = 'stake' } +gas_price = { price = 0.000, denom = 'uosmo' } gas_adjustment = 1.0 clock_drift = '1m' # to accomdate docker containers trusting_period = '239seconds' From 9f0ff0a37a00a7751c47d95e2c53086101213dd7 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 25 May 2022 13:22:25 -0500 Subject: [PATCH 04/20] change docker file --- Dockerfile | 4 ++-- tests/e2e/e2e_setup_test.go | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 108cbe4e49b..160fcac9eec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ + # syntax=docker/dockerfile:1 ARG BASE_IMG_TAG=nonroot @@ -31,8 +32,7 @@ RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build # Runner # -------------------------------------------------------- -FROM ubuntu -RUN apt-get update && apt-get install -y jq moreutils +FROM gcr.io/distroless/base-debian11:${BASE_IMG_TAG} COPY --from=build /osmosis/build/osmosisd /bin/osmosisd diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index d178aea3b0e..dac9f6aff16 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -238,11 +238,6 @@ func (s *IntegrationTestSuite) runValidators(c *chain.Chain, portOffset int) { }, Repository: debugRepository, Tag: debugVersion, - // Entrypoint: []string{ - // "sh", - // "-c", - // "chmod +x /osmosis/genesis_mod.sh && /osmosis/genesis_mod.sh", - // }, Cmd: []string{ "start", }, From 9d33f0dbfe3583999bbd609560a247aef50876a3 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 24 May 2022 08:27:36 -0700 Subject: [PATCH 05/20] refactor: e2e setup to be more extensible for state sync (#1565) Closes: #XXX This PR refactors e2e test setup to have an abstraction `chainConfig` that has information about which validators should not be run during initialization. This is a first step toward testing state-sync as we want to postpone running some nodes so that we can test nodes "catching up". Additionally, this PR extracts a separate package `docker` for managing and storing all information related to docker images. - create a `chainConfig` struct to encapsulate all configurations related to chains in a single abstraction * remove global variables `propHeightA`, `propHeightB`, `votingPeriodA`, `votingPeriodB`. Instead, these are part of the `chainConfig` struct * `skipRunValidatorIndexes` - this is needed to skip certain validators from being run during setup so that we can test state-sync post-initialization and upgrade - remove code duplication for every chain. Instead, always loop over `chainConfig`s so that if we add more chains later, the setup would work out of the box - tested running both with and without upgrade - Does this pull request introduce a new feature or user-facing behavior changes? no - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? no - How is the feature or change documented? not applicable --- tests/e2e/docker/image_config.go | 64 ++++++ tests/e2e/e2e_setup_test.go | 358 ++++++++++++++++--------------- tests/e2e/e2e_test.go | 27 +-- tests/e2e/e2e_util_test.go | 49 ++--- 4 files changed, 284 insertions(+), 214 deletions(-) create mode 100644 tests/e2e/docker/image_config.go diff --git a/tests/e2e/docker/image_config.go b/tests/e2e/docker/image_config.go new file mode 100644 index 00000000000..5d43d894b71 --- /dev/null +++ b/tests/e2e/docker/image_config.go @@ -0,0 +1,64 @@ +package docker + +// ImageConfig contains all images and their respective tags +// needed for running e2e tests. +type ImageConfig struct { + InitRepository string + InitTag string + + OsmosisRepository string + OsmosisTag string + + RelayerRepository string + RelayerTag string +} + +const ( + // Local osmosis repo/version. + // It is used when skipping upgrade by setting OSMOSIS_E2E_SKIP_UPGRADE to true). + // This image should be pre-built with `make docker-build-debug` either in CI or locally. + LocalOsmoRepository = "osmosis" + LocalOsmoTag = "debug" + // Local osmosis repo/version for osmosis initialization. + // It is used when skipping upgrade by setting OSMOSIS_E2E_SKIP_UPGRADE to true). + // This image should be pre-built with `make docker-build-e2e-chain-init` either in CI or locally. + localInitRepository = "osmosis-e2e-chain-init" + localInitTag = "debug" + // Pre-upgrade osmosis repo/tag to pull. + // It should be uploaded to Docker Hub. OSMOSIS_E2E_SKIP_UPGRADE should be unset + // for this functionality to be used. + previousVersionOsmoRepository = "osmolabs/osmosis-dev" + previousVersionOsmoTag = "v8.0.0-2-debug" + // Pre-upgrade repo/tag for osmosis initialization (this should be one version below upgradeVersion) + previousVersionInitRepository = "osmolabs/osmosis-init" + previousVersionInitTag = "v8.0.0-2-osmo" + // Hermes repo/version for relayer + relayerRepository = "osmolabs/hermes" + relayerTag = "0.13.0" +) + +// Returns ImageConfig needed for running e2e test. +// If isUpgrade is true, returns images for running the upgrade +// Otherwise, returns images for running non-upgrade e2e tests. +func NewImageConfig(isUpgrade bool) *ImageConfig { + config := &ImageConfig{ + RelayerRepository: relayerRepository, + RelayerTag: relayerTag, + } + + if isUpgrade { + config.InitRepository = previousVersionInitRepository + config.InitTag = previousVersionInitTag + + config.OsmosisRepository = previousVersionOsmoRepository + config.OsmosisTag = previousVersionOsmoTag + } else { + config.InitRepository = localInitRepository + config.InitTag = localInitTag + + config.OsmosisRepository = LocalOsmoRepository + config.OsmosisTag = LocalOsmoTag + } + + return config +} diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index dac9f6aff16..4c6e4a0f244 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -21,25 +21,41 @@ import ( rpchttp "github.com/tendermint/tendermint/rpc/client/http" "github.com/osmosis-labs/osmosis/v7/tests/e2e/chain" + dockerconfig "github.com/osmosis-labs/osmosis/v7/tests/e2e/docker" "github.com/osmosis-labs/osmosis/v7/tests/e2e/util" ) -var ( +type status struct { + LatestHeight string `json:"latest_block_height"` +} + +type syncInfo struct { + SyncInfo status `json:"SyncInfo"` +} + +type valinfo struct { + VotingPower string `json:"VotingPower"` +} + +type operInfo struct { + Bech32Val string `json:"Bech32 Val"` +} + +type chainConfig struct { + // voting period is number of blocks it takes to deposit, 1.2 seconds per validator to vote on the prop, and a buffer. + votingPeriod float32 + // upgrade proposal height for chain. + propHeight int + // Indexes of the validators to skip from running during initialization. + // This is needed for testing functionality like state-sync where we would + // like to start a node during tests post-initialization. + skipRunValidatorIndexes map[int]struct{} + chain *chain.Chain +} + +const ( // osmosis version being upgraded to (folder must exist here https://github.com/osmosis-labs/osmosis/tree/main/app/upgrades) upgradeVersion = "v9" - // osmosis repo/version for initialization (this should be one version below upgradeVersion) - initRepository = "osmolabs/osmosis-init" - initVersion = "v8.0.0-2-osmo" - // pre upgrade osmosis repo/version to pull (should match initVersion numer) - debugRepository = "osmolabs/osmosis-dev" - debugVersion = "v8.0.0-2-debug" - // hermes repo/version for relayer - relayerRepository = "osmolabs/hermes" - relayerVersion = "0.13.0" - // voting period for chain A - votingPeriodA float32 - // voting period for chain B - votingPeriodB float32 // estimated number of blocks it takes to submit for a proposal propSubmitBlocks float32 = 10 // estimated number of blocks it takes to deposit for a proposal @@ -48,16 +64,11 @@ var ( propVoteBlocks float32 = 1.2 // number of blocks used as a calculation buffer propBufferBlocks float32 = 5 - // variable used to switch between chain A and B prop height in for loop - propHeight int - // upgrade proposal height for chain A - propHeightA int - // upgrade proposal height for chain B - propHeightB int - // current prop number - propNumber int = 1 // max retries for json unmarshalling maxRetries = 60 +) + +var ( // whatever number of validator configs get posted here are how many validators that will spawn on chain A and B respectively validatorConfigsChainA = []*chain.ValidatorConfig{ { @@ -81,6 +92,13 @@ var ( SnapshotInterval: 1500, SnapshotKeepRecent: 2, }, + { + Pruning: "everything", + PruningKeepRecent: "0", + PruningInterval: "0", + SnapshotInterval: 0, + SnapshotKeepRecent: 0, + }, } validatorConfigsChainB = []*chain.ValidatorConfig{ { @@ -111,29 +129,13 @@ type IntegrationTestSuite struct { suite.Suite tmpDirs []string - chains []*chain.Chain + chainConfigs []*chainConfig dkrPool *dockertest.Pool dkrNet *dockertest.Network hermesResource *dockertest.Resource initResource *dockertest.Resource valResources map[string][]*dockertest.Resource -} - -type status struct { - LatestHeight string `json:"latest_block_height"` -} - -type valinfo struct { - VotingPower string `json:"VotingPower"` -} - -type syncInfo struct { - SyncInfo status `json:"SyncInfo"` - ValidatorInfo valinfo `json:"ValidatorInfo"` -} - -type operInfo struct { - Bech32Val string `json:"Bech32 Val"` + dockerImages dockerconfig.ImageConfig } func TestIntegrationTestSuite(t *testing.T) { @@ -143,7 +145,7 @@ func TestIntegrationTestSuite(t *testing.T) { func (s *IntegrationTestSuite) SetupSuite() { s.T().Log("setting up e2e integration test suite...") - s.chains = make([]*chain.Chain, 0, 2) + s.chainConfigs = make([]*chainConfig, 0, 2) // The e2e test flow is as follows: // @@ -153,43 +155,40 @@ func (s *IntegrationTestSuite) SetupSuite() { // 2. Start both networks. // 3. Run IBC relayer betweeen the two chains. // 4. Execute various e2e tests, including IBC. + var ( + skipUpgrade bool + err error + ) + if str := os.Getenv("OSMOSIS_E2E_SKIP_UPGRADE"); len(str) > 0 { - skipUpgrade, err := strconv.ParseBool(str) + skipUpgrade, err = strconv.ParseBool(str) s.Require().NoError(err) + } - if skipUpgrade { - debugRepository = "osmosis" - debugVersion = "debug" - initRepository = "osmosis-e2e-chain-init" - initVersion = "debug" - s.configureDockerResources(chain.ChainAID, chain.ChainBID) - s.configureChain(chain.ChainAID, validatorConfigsChainA) - s.configureChain(chain.ChainBID, validatorConfigsChainB) - - s.runValidators(s.chains[0], 0) - s.runValidators(s.chains[1], 10) - s.extractOperAddress(s.chains[0]) - s.extractOperAddress(s.chains[1]) - s.runIBCRelayer() - s.runPostUpgradeTests() - return + s.dockerImages = *dockerconfig.NewImageConfig(!skipUpgrade) + + s.configureDockerResources(chain.ChainAID, chain.ChainBID) + s.configureChain(chain.ChainAID, validatorConfigsChainA, map[int]struct{}{ + 3: {}, // skip validator at index 3 + }) + s.configureChain(chain.ChainBID, validatorConfigsChainB, map[int]struct{}{}) + + for i, chainConfig := range s.chainConfigs { + s.runValidators(chainConfig, s.dockerImages.OsmosisRepository, s.dockerImages.OsmosisTag, i*10) + } + + // Run a relayer between every possible pair of chains. + for i := 0; i < len(s.chainConfigs); i++ { + for j := i + 1; j < len(s.chainConfigs); j++ { + s.runIBCRelayer(s.chainConfigs[i].chain, s.chainConfigs[j].chain) } } - s.configureDockerResources(chain.ChainAID, chain.ChainBID) - s.configureChain(chain.ChainAID, validatorConfigsChainA) - s.configureChain(chain.ChainBID, validatorConfigsChainB) - - s.runValidators(s.chains[0], 0) - s.runValidators(s.chains[1], 10) - s.extractOperAddress(s.chains[0]) - s.extractOperAddress(s.chains[1]) - s.runIBCRelayer() - // pre upgrade state creation - s.createPreUpgradeState() - // initialize and run the upgrade - s.upgrade() - // post upgrade tests - s.runPostUpgradeTests() + + if !skipUpgrade { + s.createPreUpgradeState() + s.upgrade() + s.runPostUpgradeTests() + } } func (s *IntegrationTestSuite) TearDownSuite() { @@ -214,8 +213,8 @@ func (s *IntegrationTestSuite) TearDownSuite() { s.Require().NoError(s.dkrPool.RemoveNetwork(s.dkrNet)) - for _, chain := range s.chains { - os.RemoveAll(chain.ChainMeta.DataDir) + for _, chainConfig := range s.chainConfigs { + os.RemoveAll(chainConfig.chain.ChainMeta.DataDir) } for _, td := range s.tmpDirs { @@ -223,12 +222,21 @@ func (s *IntegrationTestSuite) TearDownSuite() { } } -func (s *IntegrationTestSuite) runValidators(c *chain.Chain, portOffset int) { - s.T().Logf("starting %s validator containers...", c.ChainMeta.Id) - s.valResources[c.ChainMeta.Id] = make([]*dockertest.Resource, len(c.Validators)) +func (s *IntegrationTestSuite) runValidators(chainConfig *chainConfig, dockerRepository, dockerTag string, portOffset int) { + chain := chainConfig.chain + s.T().Logf("starting %s validator containers...", chain.ChainMeta.Id) + s.valResources[chain.ChainMeta.Id] = make([]*dockertest.Resource, len(chain.Validators)-len(chainConfig.skipRunValidatorIndexes)) pwd, err := os.Getwd() s.Require().NoError(err) - for i, val := range c.Validators { + for i, val := range chain.Validators { + // Skip some validators from running during set up. + // This is needed for testing functionality like + // state-sunc where we might want to start some validators during tests. + if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { + s.T().Logf("skipping %s validator with index %d from running...", val.Name, i) + continue + } + runOpts := &dockertest.RunOptions{ Name: val.Name, NetworkID: s.dkrNet.Network.ID, @@ -236,8 +244,8 @@ func (s *IntegrationTestSuite) runValidators(c *chain.Chain, portOffset int) { fmt.Sprintf("%s/:/osmosis/.osmosisd", val.ConfigDir), fmt.Sprintf("%s/scripts:/osmosis", pwd), }, - Repository: debugRepository, - Tag: debugVersion, + Repository: dockerRepository, + Tag: dockerTag, Cmd: []string{ "start", }, @@ -262,7 +270,7 @@ func (s *IntegrationTestSuite) runValidators(c *chain.Chain, portOffset int) { resource, err := s.dkrPool.RunWithOptions(runOpts, noRestart) s.Require().NoError(err) - s.valResources[c.ChainMeta.Id][i] = resource + s.valResources[chain.ChainMeta.Id][i] = resource s.T().Logf("started %s validator container: %s", resource.Container.Name[1:], resource.Container.ID) } @@ -292,15 +300,15 @@ func (s *IntegrationTestSuite) runValidators(c *chain.Chain, portOffset int) { ) } -func (s *IntegrationTestSuite) runIBCRelayer() { +func (s *IntegrationTestSuite) runIBCRelayer(chainA *chain.Chain, chainB *chain.Chain) { s.T().Log("starting Hermes relayer container...") tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-hermes-") s.Require().NoError(err) s.tmpDirs = append(s.tmpDirs, tmpDir) - osmoAVal := s.chains[0].Validators[0] - osmoBVal := s.chains[1].Validators[0] + osmoAVal := chainA.Validators[0] + osmoBVal := chainB.Validators[0] hermesCfgPath := path.Join(tmpDir, "hermes") s.Require().NoError(os.MkdirAll(hermesCfgPath, 0o755)) @@ -312,9 +320,9 @@ func (s *IntegrationTestSuite) runIBCRelayer() { s.hermesResource, err = s.dkrPool.RunWithOptions( &dockertest.RunOptions{ - Name: fmt.Sprintf("%s-%s-relayer", s.chains[0].ChainMeta.Id, s.chains[1].ChainMeta.Id), - Repository: relayerRepository, - Tag: relayerVersion, + Name: fmt.Sprintf("%s-%s-relayer", chainA.ChainMeta.Id, chainB.ChainMeta.Id), + Repository: s.dockerImages.RelayerRepository, + Tag: s.dockerImages.RelayerTag, NetworkID: s.dkrNet.Network.ID, Cmd: []string{ "start", @@ -330,12 +338,12 @@ func (s *IntegrationTestSuite) runIBCRelayer() { "3031/tcp": {{HostIP: "", HostPort: "3031"}}, }, Env: []string{ - fmt.Sprintf("OSMO_A_E2E_CHAIN_ID=%s", s.chains[0].ChainMeta.Id), - fmt.Sprintf("OSMO_B_E2E_CHAIN_ID=%s", s.chains[1].ChainMeta.Id), + fmt.Sprintf("OSMO_A_E2E_CHAIN_ID=%s", chainA.ChainMeta.Id), + fmt.Sprintf("OSMO_B_E2E_CHAIN_ID=%s", chainB.ChainMeta.Id), fmt.Sprintf("OSMO_A_E2E_VAL_MNEMONIC=%s", osmoAVal.Mnemonic), fmt.Sprintf("OSMO_B_E2E_VAL_MNEMONIC=%s", osmoBVal.Mnemonic), - fmt.Sprintf("OSMO_A_E2E_VAL_HOST=%s", s.valResources[s.chains[0].ChainMeta.Id][0].Container.Name[1:]), - fmt.Sprintf("OSMO_B_E2E_VAL_HOST=%s", s.valResources[s.chains[1].ChainMeta.Id][0].Container.Name[1:]), + fmt.Sprintf("OSMO_A_E2E_VAL_HOST=%s", s.valResources[chainA.ChainMeta.Id][0].Container.Name[1:]), + fmt.Sprintf("OSMO_B_E2E_VAL_HOST=%s", s.valResources[chainB.ChainMeta.Id][0].Container.Name[1:]), }, Entrypoint: []string{ "sh", @@ -384,41 +392,39 @@ func (s *IntegrationTestSuite) runIBCRelayer() { time.Sleep(10 * time.Second) // create the client, connection and channel between the two Osmosis chains - s.connectIBCChains() + s.connectIBCChains(chainA, chainB) } -func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs []*chain.ValidatorConfig) { - +func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs []*chain.ValidatorConfig, skipValidatorIndexes map[int]struct{}) { s.T().Logf("starting e2e infrastructure for chain-id: %s", chainId) tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-") s.T().Logf("temp directory for chain-id %v: %v", chainId, tmpDir) s.Require().NoError(err) - b, err := json.Marshal(validatorConfigs) + validatorConfigBytes, err := json.Marshal(validatorConfigs) s.Require().NoError(err) numVal := float32(len(validatorConfigs)) - // voting period is number of blocks it takes to deposit, 1.2 seconds per validator to vote on the prop, then a buffer - votingPeriodNum := propDepositBlocks + numVal*propVoteBlocks + propBufferBlocks - if chainId == chain.ChainAID { - votingPeriodA = votingPeriodNum - } else if chainId == chain.ChainBID { - votingPeriodB = votingPeriodNum + + newChainConfig := chainConfig{ + votingPeriod: propDepositBlocks + numVal*propVoteBlocks + propBufferBlocks, + skipRunValidatorIndexes: skipValidatorIndexes, } - votingPeriod := time.Duration(int(votingPeriodNum) * 1000000000) + + votingPeriodDuration := time.Duration(int(newChainConfig.votingPeriod) * 1000000000) s.initResource, err = s.dkrPool.RunWithOptions( &dockertest.RunOptions{ Name: fmt.Sprintf("%s", chainId), - Repository: initRepository, - Tag: initVersion, + Repository: s.dockerImages.InitRepository, + Tag: s.dockerImages.InitTag, NetworkID: s.dkrNet.Network.ID, Cmd: []string{ fmt.Sprintf("--data-dir=%s", tmpDir), fmt.Sprintf("--chain-id=%s", chainId), - fmt.Sprintf("--config=%s", b), - fmt.Sprintf("--voting-period=%v", votingPeriod), + fmt.Sprintf("--config=%s", validatorConfigBytes), + fmt.Sprintf("--voting-period=%v", votingPeriodDuration), }, User: "root:root", Mounts: []string{ @@ -429,8 +435,6 @@ func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs [ ) s.Require().NoError(err) - var newChain chain.Chain - fileName := fmt.Sprintf("%v/%v-encode", tmpDir, chainId) s.T().Logf("serialized init file for chain-id %v: %v", chainId, fileName) @@ -438,7 +442,7 @@ func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs [ // without this, test attempts to unmarshal file before docker container is finished writing for i := 0; i < maxRetries; i++ { encJson, _ := os.ReadFile(fileName) - err = json.Unmarshal(encJson, &newChain) + err = json.Unmarshal(encJson, &newChainConfig.chain) if err == nil { break } @@ -451,8 +455,9 @@ func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs [ time.Sleep(1 * time.Second) } } - s.chains = append(s.chains, &newChain) s.Require().NoError(s.dkrPool.Purge(s.initResource)) + + s.chainConfigs = append(s.chainConfigs, &newChainConfig) } func (s *IntegrationTestSuite) configureDockerResources(chainIDOne, chainIDTwo string) { @@ -476,39 +481,36 @@ func noRestart(config *docker.HostConfig) { func (s *IntegrationTestSuite) upgrade() { // submit, deposit, and vote for upgrade proposal // prop height = current height + voting period + time it takes to submit proposal + small buffer - currentHeightA := s.getCurrentChainHeight(s.valResources[s.chains[0].ChainMeta.Id][0].Container.ID) - propHeightA = currentHeightA + int(votingPeriodA) + int(propSubmitBlocks) + int(propBufferBlocks) - s.submitUpgradeProposal(s.chains[0], propHeightA) - s.depositProposal(s.chains[0]) - s.voteProposal(s.chains[0]) - // prop height = current height + voting period + time it takes to submit proposal + small buffer - currentHeightB := s.getCurrentChainHeight(s.valResources[s.chains[1].ChainMeta.Id][0].Container.ID) - propHeightB = currentHeightB + int(votingPeriodB) + int(propSubmitBlocks) + int(propBufferBlocks) - s.submitUpgradeProposal(s.chains[1], propHeightB) - s.depositProposal(s.chains[1]) - s.voteProposal(s.chains[1]) + for _, chainConfig := range s.chainConfigs { + currentHeight := s.getCurrentChainHeight(s.valResources[chainConfig.chain.ChainMeta.Id][0].Container.ID) + chainConfig.propHeight = currentHeight + int(chainConfig.votingPeriod) + int(propSubmitBlocks) + int(propBufferBlocks) + s.submitUpgradeProposal(chainConfig.chain, chainConfig.propHeight) + s.depositProposal(chainConfig.chain) + s.voteProposal(chainConfig) + } // wait till all chains halt at upgrade height - for _, c := range s.chains { - if c.ChainMeta.Id == chain.ChainAID { - propHeight = propHeightA - } else { - propHeight = propHeightB - } - for i := range c.Validators { + for _, chainConfig := range s.chainConfigs { + curChain := chainConfig.chain + + for i := range chainConfig.chain.Validators { + if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { + continue + } + // use counter to ensure no new blocks are being created counter := 0 - s.T().Logf("waiting to reach upgrade height on %s validator container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + s.T().Logf("waiting to reach upgrade height on %s validator container: %s", s.valResources[curChain.ChainMeta.Id][i].Container.Name[1:], s.valResources[curChain.ChainMeta.Id][i].Container.ID) s.Require().Eventually( func() bool { - currentHeight := s.getCurrentChainHeight(s.valResources[c.ChainMeta.Id][i].Container.ID) - if currentHeight != propHeight { - s.T().Logf("current block height on %s is %v, waiting for block %v container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], currentHeight, propHeight, s.valResources[c.ChainMeta.Id][i].Container.ID) + currentHeight := s.getCurrentChainHeight(s.valResources[curChain.ChainMeta.Id][i].Container.ID) + if currentHeight != chainConfig.propHeight { + s.T().Logf("current block height on %s is %v, waiting for block %v container: %s", s.valResources[curChain.ChainMeta.Id][i].Container.Name[1:], currentHeight, chainConfig.propHeight, s.valResources[curChain.ChainMeta.Id][i].Container.ID) } - if currentHeight > propHeight { + if currentHeight > chainConfig.propHeight { panic("chain did not halt at upgrade height") } - if currentHeight == propHeight { + if currentHeight == chainConfig.propHeight { counter++ } return counter == 3 @@ -516,34 +518,48 @@ func (s *IntegrationTestSuite) upgrade() { 5*time.Minute, time.Second, ) - s.T().Logf("reached upgrade height on %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + s.T().Logf("reached upgrade height on %s container: %s", s.valResources[curChain.ChainMeta.Id][i].Container.Name[1:], s.valResources[curChain.ChainMeta.Id][i].Container.ID) } } // remove all containers so we can upgrade them to the new version - for _, chain := range s.chains { - for i := range chain.Validators { + for _, chainConfig := range s.chainConfigs { + curChain := chainConfig.chain + for valIdx := range curChain.Validators { + if _, ok := chainConfig.skipRunValidatorIndexes[valIdx]; ok { + continue + } + var opts docker.RemoveContainerOptions - opts.ID = s.valResources[chain.ChainMeta.Id][i].Container.ID + opts.ID = s.valResources[curChain.ChainMeta.Id][valIdx].Container.ID opts.Force = true s.dkrPool.Client.RemoveContainer(opts) - s.T().Logf("removed container: %s", s.valResources[chain.ChainMeta.Id][i].Container.Name[1:]) + s.T().Logf("removed container: %s", s.valResources[curChain.ChainMeta.Id][valIdx].Container.Name[1:]) } } - s.upgradeContainers(s.chains[0]) - s.upgradeContainers(s.chains[1]) + + // remove all containers so we can upgrade them to the new version + for _, chainConfig := range s.chainConfigs { + s.upgradeContainers(chainConfig, chainConfig.propHeight) + } } -func (s *IntegrationTestSuite) upgradeContainers(c *chain.Chain) { +func (s *IntegrationTestSuite) upgradeContainers(chainConfig *chainConfig, propHeight int) { // upgrade containers to the locally compiled daemon - s.T().Logf("starting upgrade for chain-id: %s...", c.ChainMeta.Id) + chain := chainConfig.chain + s.T().Logf("starting upgrade for chain-id: %s...", chain.ChainMeta.Id) pwd, err := os.Getwd() s.Require().NoError(err) - for i, val := range c.Validators { + + for i, val := range chain.Validators { + if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { + continue + } + runOpts := &dockertest.RunOptions{ Name: val.Name, - Repository: "osmosis", - Tag: "debug", + Repository: dockerconfig.LocalOsmoRepository, + Tag: dockerconfig.LocalOsmoTag, NetworkID: s.dkrNet.Network.ID, User: "root:root", Mounts: []string{ @@ -554,47 +570,51 @@ func (s *IntegrationTestSuite) upgradeContainers(c *chain.Chain) { resource, err := s.dkrPool.RunWithOptions(runOpts, noRestart) s.Require().NoError(err) - s.valResources[c.ChainMeta.Id][i] = resource + s.valResources[chain.ChainMeta.Id][i] = resource s.T().Logf("started %s validator container: %s", resource.Container.Name[1:], resource.Container.ID) } // check that we are creating blocks again - for i := range c.Validators { - if c.ChainMeta.Id == chain.ChainAID { - propHeight = propHeightA - } else { - propHeight = propHeightB + for i := range chain.Validators { + if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { + continue } + s.Require().Eventually( func() bool { - currentHeight := s.getCurrentChainHeight(s.valResources[c.ChainMeta.Id][i].Container.ID) + currentHeight := s.getCurrentChainHeight(s.valResources[chain.ChainMeta.Id][i].Container.ID) if currentHeight <= propHeight { - s.T().Logf("current block height on %s is %v, waiting to create blocks container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], currentHeight, s.valResources[c.ChainMeta.Id][i].Container.ID) + s.T().Logf("current block height on %s is %v, waiting to create blocks container: %s", s.valResources[chain.ChainMeta.Id][i].Container.Name[1:], currentHeight, s.valResources[chain.ChainMeta.Id][i].Container.ID) } return currentHeight > propHeight }, 5*time.Minute, time.Second, ) - s.T().Logf("upgrade successful on %s validator container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + s.T().Logf("upgrade successful on %s validator container: %s", s.valResources[chain.ChainMeta.Id][i].Container.Name[1:], s.valResources[chain.ChainMeta.Id][i].Container.ID) } - } func (s *IntegrationTestSuite) createPreUpgradeState() { - s.sendIBC(s.chains[0], s.chains[1], s.chains[1].Validators[0].PublicAddress, chain.OsmoToken) - s.sendIBC(s.chains[1], s.chains[0], s.chains[0].Validators[0].PublicAddress, chain.OsmoToken) - s.sendIBC(s.chains[0], s.chains[1], s.chains[1].Validators[0].PublicAddress, chain.StakeToken) - s.sendIBC(s.chains[1], s.chains[0], s.chains[0].Validators[0].PublicAddress, chain.StakeToken) - s.createPool(s.chains[0], "pool1A.json") - s.createPool(s.chains[1], "pool1B.json") + chainA := s.chainConfigs[0].chain + chainB := s.chainConfigs[1].chain + + s.sendIBC(chainA, chainB, chainB.Validators[0].PublicAddress, chain.OsmoToken) + s.sendIBC(chainB, chainA, chainA.Validators[0].PublicAddress, chain.OsmoToken) + s.sendIBC(chainA, chainB, chainB.Validators[0].PublicAddress, chain.StakeToken) + s.sendIBC(chainB, chainA, chainA.Validators[0].PublicAddress, chain.StakeToken) + s.createPool(chainA, "pool1A.json") + s.createPool(chainB, "pool1B.json") } func (s *IntegrationTestSuite) runPostUpgradeTests() { - s.sendIBC(s.chains[0], s.chains[1], s.chains[1].Validators[0].PublicAddress, chain.OsmoToken) - s.sendIBC(s.chains[1], s.chains[0], s.chains[0].Validators[0].PublicAddress, chain.OsmoToken) - s.sendIBC(s.chains[0], s.chains[1], s.chains[1].Validators[0].PublicAddress, chain.StakeToken) - s.sendIBC(s.chains[1], s.chains[0], s.chains[0].Validators[0].PublicAddress, chain.StakeToken) - s.createPool(s.chains[0], "pool2A.json") - s.createPool(s.chains[1], "pool2B.json") + chainA := s.chainConfigs[0].chain + chainB := s.chainConfigs[1].chain + + s.sendIBC(chainA, chainB, chainB.Validators[0].PublicAddress, chain.OsmoToken) + s.sendIBC(chainB, chainA, chainA.Validators[0].PublicAddress, chain.OsmoToken) + s.sendIBC(chainA, chainB, chainB.Validators[0].PublicAddress, chain.StakeToken) + s.sendIBC(chainB, chainA, chainA.Validators[0].PublicAddress, chain.StakeToken) + s.createPool(chainA, "pool2A.json") + s.createPool(chainB, "pool2B.json") } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index b5187bad26a..18d20250c16 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -7,25 +7,26 @@ import ( ) func (s *IntegrationTestSuite) TestSuperfluidVoting() { + chainA := s.chainConfigs[0].chain s.Run("superfluid_vote_chainA", func() { - s.submitSuperfluidProposal(s.chains[0], "gamm/pool/1") - s.depositProposal(s.chains[0]) - s.voteProposal(s.chains[0]) + s.submitSuperfluidProposal(chainA, "gamm/pool/1") + s.depositProposal(chainA) + s.voteProposal(s.chainConfigs[0]) // send gamm tokens to validator's other wallet (non self-delegation wallet) - s.sendTx(s.chains[0], 0, "100000000000000000000gamm/pool/1", s.chains[0].Validators[0].PublicAddress, s.chains[0].Validators[0].PublicAddress2) + s.sendTx(chainA, 0, "100000000000000000000gamm/pool/1", chainA.Validators[0].PublicAddress, chainA.Validators[0].PublicAddress2) // lock tokens from validator 0 on chain A - s.lockTokens(s.chains[0], 0, "100000000000000000000gamm/pool/1", "240s", "val2") + s.lockTokens(chainA, 0, "100000000000000000000gamm/pool/1", "240s", "val2") // superfluid delegate from validator 0 non self-delegation wallet to validator 1 on chain A - s.superfluidDelegate(s.chains[0], "100000000000000000000gamm/pool/1", s.chains[0].Validators[1].OperAddress, "val2") + s.superfluidDelegate(chainA, "100000000000000000000gamm/pool/1", chainA.Validators[1].OperAddress, "val2") // create a text prop, deposit and vote yes - s.submitTextProposal(s.chains[0], "superfluid vote overwrite test") - s.depositProposal(s.chains[0]) - s.voteProposal(s.chains[0]) + s.submitTextProposal(chainA, "superfluid vote overwrite test") + s.depositProposal(chainA) + s.voteProposal(s.chainConfigs[0]) // set delegator vote to no - s.voteNoProposal(s.chains[0], 0, "val2") + s.voteNoProposal(chainA, 0, "val2") - chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chains[0].ChainMeta.Id][0].GetHostPort("1317/tcp")) - sfProposalNumber := strconv.Itoa(s.chains[0].PropNumber) + chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[chainA.ChainMeta.Id][0].GetHostPort("1317/tcp")) + sfProposalNumber := strconv.Itoa(chainA.PropNumber) s.Require().Eventually( func() bool { noTotal, yesTotal, noWithVetoTotal, abstainTotal, err := s.queryPropTally(chainAAPIEndpoint, sfProposalNumber) @@ -47,7 +48,7 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { s.Require().Eventually( func() bool { - intAccountBalance, err := s.queryIntermediaryAccount(s.chains[0], chainAAPIEndpoint, "gamm/pool/1", s.chains[0].Validators[1].OperAddress) + intAccountBalance, err := s.queryIntermediaryAccount(chainA, chainAAPIEndpoint, "gamm/pool/1", chainA.Validators[1].OperAddress) s.Require().NoError(err) if err != nil { return false diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index 412d70e4a7b..c7f03e41b5a 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -24,8 +24,8 @@ import ( "github.com/osmosis-labs/osmosis/v7/tests/e2e/util" ) -func (s *IntegrationTestSuite) connectIBCChains() { - s.T().Logf("connecting %s and %s chains via IBC", s.chains[0].ChainMeta.Id, s.chains[1].ChainMeta.Id) +func (s *IntegrationTestSuite) connectIBCChains(chainA *chain.Chain, chainB *chain.Chain) { + s.T().Logf("connecting %s and %s chains via IBC", chainA.ChainMeta.Id, chainB.ChainMeta.Id) ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() @@ -40,8 +40,8 @@ func (s *IntegrationTestSuite) connectIBCChains() { "hermes", "create", "channel", - s.chains[0].ChainMeta.Id, - s.chains[1].ChainMeta.Id, + chainA.ChainMeta.Id, + chainB.ChainMeta.Id, "--port-a=transfer", "--port-b=transfer", }, @@ -70,7 +70,7 @@ func (s *IntegrationTestSuite) connectIBCChains() { "failed to connect chains via IBC: %s", errBuf.String(), ) - s.T().Logf("connected %s and %s chains via IBC", s.chains[0].ChainMeta.Id, s.chains[1].ChainMeta.Id) + s.T().Logf("connected %s and %s chains via IBC", chainA.ChainMeta.Id, chainB.ChainMeta.Id) } func (s *IntegrationTestSuite) sendIBC(srcChain *chain.Chain, dstChain *chain.Chain, recipient string, token sdk.Coin) { @@ -318,12 +318,17 @@ func (s *IntegrationTestSuite) depositProposal(c *chain.Chain) { s.T().Log("successfully deposited to proposal") } -func (s *IntegrationTestSuite) voteProposal(c *chain.Chain) { +func (s *IntegrationTestSuite) voteProposal(chainConfig *chainConfig) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - propStr := strconv.Itoa(c.PropNumber) - s.T().Logf("voting for proposal for chain-id: %s", c.ChainMeta.Id) - for i := range c.Validators { + chain := chainConfig.chain + propStr := strconv.Itoa(chain.PropNumber) + + s.T().Logf("voting for upgrade proposal for chain-id: %s", chain.ChainMeta.Id) + for i := range chain.Validators { + if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { + continue + } var ( outBuf bytes.Buffer @@ -336,10 +341,10 @@ func (s *IntegrationTestSuite) voteProposal(c *chain.Chain) { Context: ctx, AttachStdout: true, AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][i].Container.ID, + Container: s.valResources[chain.ChainMeta.Id][i].Container.ID, User: "root", Cmd: []string{ - "osmosisd", "tx", "gov", "vote", propStr, "yes", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test", + "osmosisd", "tx", "gov", "vote", propStr, "yes", "--from=val", fmt.Sprintf("--chain-id=%s", chain.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test", }, }) s.Require().NoError(err) @@ -357,7 +362,7 @@ func (s *IntegrationTestSuite) voteProposal(c *chain.Chain) { "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), ) - s.T().Logf("successfully voted for proposal from %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + s.T().Logf("successfully voted for proposal from %s container: %s", s.valResources[chain.ChainMeta.Id][i].Container.Name[1:], s.valResources[chain.ChainMeta.Id][i].Container.ID) } } @@ -461,26 +466,6 @@ func (s *IntegrationTestSuite) getCurrentChainHeight(containerId string) int { return currentHeight } -func (s *IntegrationTestSuite) getValidatorPower(containerId string) int { - var block syncInfo - s.Require().Eventually( - func() bool { - out := s.chainStatus(containerId) - err := json.Unmarshal(out, &block) - if err != nil { - return false - } - return true - }, - 1*time.Minute, - time.Second, - "Osmosis node failed to retrieve height info", - ) - votingPower, err := strconv.Atoi(block.ValidatorInfo.VotingPower) - s.Require().NoError(err) - return votingPower -} - func (s *IntegrationTestSuite) queryBalances(containerId string, addr string) (sdk.Coins, error) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() From 12d4a57d191c42e4492ad2fb7f10a2d3cfbf6e1b Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 25 May 2022 14:24:33 -0500 Subject: [PATCH 06/20] add extract oper address --- tests/e2e/e2e_setup_test.go | 1 + tests/e2e/e2e_test.go | 2 +- tests/e2e/e2e_util_test.go | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 4c6e4a0f244..d72cb396331 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -174,6 +174,7 @@ func (s *IntegrationTestSuite) SetupSuite() { s.configureChain(chain.ChainBID, validatorConfigsChainB, map[int]struct{}{}) for i, chainConfig := range s.chainConfigs { + s.extractOperAddress(s.chainConfigs[i].chain) s.runValidators(chainConfig, s.dockerImages.OsmosisRepository, s.dockerImages.OsmosisTag, i*10) } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 18d20250c16..3e299f0f294 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -17,7 +17,7 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { // lock tokens from validator 0 on chain A s.lockTokens(chainA, 0, "100000000000000000000gamm/pool/1", "240s", "val2") // superfluid delegate from validator 0 non self-delegation wallet to validator 1 on chain A - s.superfluidDelegate(chainA, "100000000000000000000gamm/pool/1", chainA.Validators[1].OperAddress, "val2") + s.superfluidDelegate(chainA, s.chainConfigs[0].chain.Validators[1].OperAddress, "val2") // create a text prop, deposit and vote yes s.submitTextProposal(chainA, "superfluid vote overwrite test") s.depositProposal(chainA) diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index c7f03e41b5a..ccca4cc1817 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -632,11 +632,11 @@ func (s *IntegrationTestSuite) lockTokens(c *chain.Chain, i int, tokens string, } -func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, tokens string, valAddress string, from string) { +func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, valAddress string, from string) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - s.T().Logf("superfluid delegating %s to %s on chain-id: %s", tokens, valAddress, c.ChainMeta.Id) lockStr := strconv.Itoa(c.LockNumber) + s.T().Logf("superfluid delegating lock %s to %s on chain-id: %s", lockStr, valAddress, c.ChainMeta.Id) var ( outBuf bytes.Buffer errBuf bytes.Buffer From cac90ee3bf33b83b72c84108c291850a160f55a8 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 25 May 2022 14:49:48 -0500 Subject: [PATCH 07/20] extract val addr --- tests/e2e/e2e_setup_test.go | 2 +- tests/e2e/e2e_util_test.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index d72cb396331..09a3f648123 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -174,8 +174,8 @@ func (s *IntegrationTestSuite) SetupSuite() { s.configureChain(chain.ChainBID, validatorConfigsChainB, map[int]struct{}{}) for i, chainConfig := range s.chainConfigs { - s.extractOperAddress(s.chainConfigs[i].chain) s.runValidators(chainConfig, s.dockerImages.OsmosisRepository, s.dockerImages.OsmosisTag, i*10) + s.extractOperAddress(chainConfig) } // Run a relayer between every possible pair of chains. diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index ccca4cc1817..c3f08aa4af4 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -712,12 +712,17 @@ func (s *IntegrationTestSuite) sendTx(c *chain.Chain, i int, amount string, send } -func (s *IntegrationTestSuite) extractOperAddress(c *chain.Chain) { - // var oper operInfo +func (s *IntegrationTestSuite) extractOperAddress(chainConfig *chainConfig) { + chain := chainConfig.chain ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - s.T().Logf("extracting validator operator addresses for chain-id: %s", c.ChainMeta.Id) - for i, val := range c.Validators { + + s.T().Logf("extracting validator operator addresses for chain-id: %s", chain.ChainMeta.Id) + for i, val := range chain.Validators { + if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { + s.T().Logf("skipping %s validator with index %d from running...", val.Name, i) + continue + } var ( outBuf bytes.Buffer @@ -730,7 +735,7 @@ func (s *IntegrationTestSuite) extractOperAddress(c *chain.Chain) { Context: ctx, AttachStdout: true, AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][i].Container.ID, + Container: s.valResources[chain.ChainMeta.Id][i].Container.ID, User: "root", Cmd: []string{ "osmosisd", "debug", "addr", val.PublicKey, From 6904461386dc78cd568f0be26bf9db555a753a91 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 25 May 2022 15:09:42 -0500 Subject: [PATCH 08/20] new line --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 160fcac9eec..9775179a9a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -44,4 +44,4 @@ EXPOSE 26657 EXPOSE 1317 ENTRYPOINT ["osmosisd"] -CMD [ "start" ] \ No newline at end of file +CMD [ "start" ] From ee095d0b912758ce7a8ef40a65945526ef4a526f Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 25 May 2022 15:12:33 -0500 Subject: [PATCH 09/20] delete no longer needed script --- tests/e2e/scripts/genesis_mod.sh | 33 -------------------------------- 1 file changed, 33 deletions(-) delete mode 100755 tests/e2e/scripts/genesis_mod.sh diff --git a/tests/e2e/scripts/genesis_mod.sh b/tests/e2e/scripts/genesis_mod.sh deleted file mode 100755 index 3eef8b8f032..00000000000 --- a/tests/e2e/scripts/genesis_mod.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -# change staking denom to uosmo -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json -# update staking genesis -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["staking"]["params"]["unbonding_time"]="240s"' | sponge $HOME/.osmosisd/config/genesis.json -# update crisis variable to uosmo -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json -# udpate gov genesis -# cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["gov"]["voting_params"]["voting_period"]="60s"' | sponge $HOME/.osmosisd/config/genesis.json -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json -# update epochs genesis -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["epochs"]["epochs"][1]["duration"]="60s"' | sponge $HOME/.osmosisd/config/genesis.json -# update poolincentives genesis -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["lockable_durations"][0]="120s"' | sponge $HOME/.osmosisd/config/genesis.json -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["lockable_durations"][1]="180s"' | sponge $HOME/.osmosisd/config/genesis.json -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["lockable_durations"][2]="240s"' | sponge $HOME/.osmosisd/config/genesis.json -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["poolincentives"]["params"]["minted_denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json -# update incentives genesis -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][0]="1s"' | sponge $HOME/.osmosisd/config/genesis.json -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][1]="120s"' | sponge $HOME/.osmosisd/config/genesis.json -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][2]="180s"' | sponge $HOME/.osmosisd/config/genesis.json -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["lockable_durations"][3]="240s"' | sponge $HOME/.osmosisd/config/genesis.json -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["incentives"]["params"]["distr_epoch_identifier"]="day"' | sponge $HOME/.osmosisd/config/genesis.json -# update mint genesis -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["mint"]["params"]["epoch_identifier"]="day"' | sponge $HOME/.osmosisd/config/genesis.json -# update gamm genesis -cat $HOME/.osmosisd/config/genesis.json | jq '.app_state["gamm"]["params"]["pool_creation_fee"][0]["denom"]="uosmo"' | sponge $HOME/.osmosisd/config/genesis.json -# remove seeds -sed -i.bak -E 's#^(seeds[[:space:]]+=[[:space:]]+).*$#\1""#' ~/.osmosisd/config/config.toml - -osmosisd start From 6a84b6af1c116e8cd3817490d1fdbc645014fc0e Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 25 May 2022 15:32:52 -0500 Subject: [PATCH 10/20] Delete .bash_history --- tests/e2e/scripts/.bash_history | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 tests/e2e/scripts/.bash_history diff --git a/tests/e2e/scripts/.bash_history b/tests/e2e/scripts/.bash_history deleted file mode 100644 index 70979d3617a..00000000000 --- a/tests/e2e/scripts/.bash_history +++ /dev/null @@ -1,18 +0,0 @@ -osmosisd q gov proposals -osmosisd q superfluid -h -osmosisd q superfluid all-superfluid-assets -osmosisd q gamm pools -exit -osmosisd q gamm pools -osmosisd q superfluid -osmosisd q superfluid all-superfluid-assets -osmosisd tx superfluid lock-and-superfluid-delegate 100000000000000000000gamm/pool/1 osmovaloper1dma9s7mvgj6r6h8gyql08kw0kyqm7phct3hmml --chain-id osmo-test-a -b block --from val -osmosisd tx superfluid lock-and-superfluid-delegate 100000000000000000000gamm/pool/1 osmovaloper1dma9s7mvgj6r6h8gyql08kw0kyqm7phct3hmml --chain-id osmo-test-a -b block --from val --keyring-backend tes -osmosisd tx superfluid lock-and-superfluid-delegate 100000000000000000000gamm/pool/1 osmovaloper1dma9s7mvgj6r6h8gyql08kw0kyqm7phct3hmml --chain-id osmo-test-a -b block --from val --keyring-backend test -exit -osmosisd debug addr fadssfadsdsf -osmosisd debug addr -h -osmosisd debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg -osmosisd status -osmosisd debug addr 9AD1DD4F5ADE6C731665FA63BFFD632E8293B3A5 -exit From 966d36132b22f13659ace6b20cc2b5a05886f8bb Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Thu, 26 May 2022 16:56:39 -0500 Subject: [PATCH 11/20] add helper functions to declutter --- tests/e2e/e2e_setup_test.go | 8 +- tests/e2e/e2e_test.go | 4 +- tests/e2e/e2e_util_test.go | 706 ++++++------------------------------ 3 files changed, 122 insertions(+), 596 deletions(-) diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 09a3f648123..3ced2533774 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -483,11 +483,11 @@ func (s *IntegrationTestSuite) upgrade() { // submit, deposit, and vote for upgrade proposal // prop height = current height + voting period + time it takes to submit proposal + small buffer for _, chainConfig := range s.chainConfigs { - currentHeight := s.getCurrentChainHeight(s.valResources[chainConfig.chain.ChainMeta.Id][0].Container.ID) + currentHeight := s.getCurrentChainHeight(chainConfig.chain, 0) chainConfig.propHeight = currentHeight + int(chainConfig.votingPeriod) + int(propSubmitBlocks) + int(propBufferBlocks) s.submitUpgradeProposal(chainConfig.chain, chainConfig.propHeight) s.depositProposal(chainConfig.chain) - s.voteProposal(chainConfig) + s.voteProposal(chainConfig.chain, chainConfig) } // wait till all chains halt at upgrade height @@ -504,7 +504,7 @@ func (s *IntegrationTestSuite) upgrade() { s.T().Logf("waiting to reach upgrade height on %s validator container: %s", s.valResources[curChain.ChainMeta.Id][i].Container.Name[1:], s.valResources[curChain.ChainMeta.Id][i].Container.ID) s.Require().Eventually( func() bool { - currentHeight := s.getCurrentChainHeight(s.valResources[curChain.ChainMeta.Id][i].Container.ID) + currentHeight := s.getCurrentChainHeight(chainConfig.chain, i) if currentHeight != chainConfig.propHeight { s.T().Logf("current block height on %s is %v, waiting for block %v container: %s", s.valResources[curChain.ChainMeta.Id][i].Container.Name[1:], currentHeight, chainConfig.propHeight, s.valResources[curChain.ChainMeta.Id][i].Container.ID) } @@ -583,7 +583,7 @@ func (s *IntegrationTestSuite) upgradeContainers(chainConfig *chainConfig, propH s.Require().Eventually( func() bool { - currentHeight := s.getCurrentChainHeight(s.valResources[chain.ChainMeta.Id][i].Container.ID) + currentHeight := s.getCurrentChainHeight(chainConfig.chain, i) if currentHeight <= propHeight { s.T().Logf("current block height on %s is %v, waiting to create blocks container: %s", s.valResources[chain.ChainMeta.Id][i].Container.Name[1:], currentHeight, s.valResources[chain.ChainMeta.Id][i].Container.ID) } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 3e299f0f294..ebdbed712f0 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -11,7 +11,7 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { s.Run("superfluid_vote_chainA", func() { s.submitSuperfluidProposal(chainA, "gamm/pool/1") s.depositProposal(chainA) - s.voteProposal(s.chainConfigs[0]) + s.voteProposal(chainA, s.chainConfigs[0]) // send gamm tokens to validator's other wallet (non self-delegation wallet) s.sendTx(chainA, 0, "100000000000000000000gamm/pool/1", chainA.Validators[0].PublicAddress, chainA.Validators[0].PublicAddress2) // lock tokens from validator 0 on chain A @@ -21,7 +21,7 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { // create a text prop, deposit and vote yes s.submitTextProposal(chainA, "superfluid vote overwrite test") s.depositProposal(chainA) - s.voteProposal(s.chainConfigs[0]) + s.voteProposal(chainA, s.chainConfigs[0]) // set delegator vote to no s.voteNoProposal(chainA, 0, "val2") diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index c3f08aa4af4..1bc0a6630ab 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -24,62 +24,15 @@ import ( "github.com/osmosis-labs/osmosis/v7/tests/e2e/util" ) -func (s *IntegrationTestSuite) connectIBCChains(chainA *chain.Chain, chainB *chain.Chain) { - s.T().Logf("connecting %s and %s chains via IBC", chainA.ChainMeta.Id, chainB.ChainMeta.Id) - +func (s *IntegrationTestSuite) ExecTx(chainId string, validatorIndex int, command []string, success string) (bytes.Buffer, bytes.Buffer, error) { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.hermesResource.Container.ID, - User: "root", - Cmd: []string{ - "hermes", - "create", - "channel", - chainA.ChainMeta.Id, - chainB.ChainMeta.Id, - "--port-a=transfer", - "--port-b=transfer", - }, - }) - s.Require().NoError(err) - - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - s.Require().NoErrorf( - err, - "failed connect chains; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - - s.Require().Containsf( - errBuf.String(), - "successfully opened init channel", - "failed to connect chains via IBC: %s", errBuf.String(), - ) - - s.T().Logf("connected %s and %s chains via IBC", chainA.ChainMeta.Id, chainB.ChainMeta.Id) -} - -func (s *IntegrationTestSuite) sendIBC(srcChain *chain.Chain, dstChain *chain.Chain, recipient string, token sdk.Coin) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - - s.T().Logf("sending %s from %s to %s (%s)", token, srcChain.ChainMeta.Id, dstChain.ChainMeta.Id, recipient) - balancesBPre, err := s.queryBalances(s.valResources[dstChain.ChainMeta.Id][0].Container.ID, recipient) - s.Require().NoError(err) + var containerId string + if chainId == "" { + containerId = s.hermesResource.Container.ID + } else { + containerId = s.valResources[chainId][validatorIndex].Container.ID + } var ( outBuf bytes.Buffer @@ -92,22 +45,9 @@ func (s *IntegrationTestSuite) sendIBC(srcChain *chain.Chain, dstChain *chain.Ch Context: ctx, AttachStdout: true, AttachStderr: true, - Container: s.hermesResource.Container.ID, + Container: containerId, User: "root", - Cmd: []string{ - "hermes", - "tx", - "raw", - "ft-transfer", - dstChain.ChainMeta.Id, - srcChain.ChainMeta.Id, - "transfer", // source chain port ID - "channel-0", // since only one connection/channel exists, assume 0 - token.Amount.String(), - fmt.Sprintf("--denom=%s", token.Denom), - fmt.Sprintf("--receiver=%s", recipient), - "--timeout-height-offset=1000", - }, + Cmd: command, }) s.Require().NoError(err) @@ -117,17 +57,77 @@ func (s *IntegrationTestSuite) sendIBC(srcChain *chain.Chain, dstChain *chain.Ch OutputStream: &outBuf, ErrorStream: &errBuf, }) + if err != nil { + return false + } + + if err != nil { + return false + } + + if success != "" { + return strings.Contains(outBuf.String(), success) || strings.Contains(errBuf.String(), success) + } - return strings.Contains(outBuf.String(), "Success") + return true }, time.Minute, time.Second, "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), ) + return outBuf, errBuf, nil +} + +func (s *IntegrationTestSuite) ExecQueryRPC(path string) ([]byte, error) { + var err error + var resp *http.Response + retriesLeft := 5 + for { + resp, err = http.Get(path) + + if resp.StatusCode == http.StatusServiceUnavailable { + retriesLeft-- + if retriesLeft == 0 { + return nil, err + } + time.Sleep(10 * time.Second) + } else { + break + } + } + + if err != nil { + return nil, fmt.Errorf("failed to execute HTTP request: %w", err) + } + + defer resp.Body.Close() + + bz, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + return bz, nil +} + +func (s *IntegrationTestSuite) connectIBCChains(chainA *chain.Chain, chainB *chain.Chain) { + s.T().Logf("connecting %s and %s chains via IBC", chainA.ChainMeta.Id, chainB.ChainMeta.Id) + cmd := []string{"hermes", "create", "channel", chainA.ChainMeta.Id, chainB.ChainMeta.Id, "--port-a=transfer", "--port-b=transfer"} + s.ExecTx("", 0, cmd, "successfully opened init channel") + s.T().Logf("connected %s and %s chains via IBC", chainA.ChainMeta.Id, chainB.ChainMeta.Id) +} + +func (s *IntegrationTestSuite) sendIBC(srcChain *chain.Chain, dstChain *chain.Chain, recipient string, token sdk.Coin) { + cmd := []string{"hermes", "tx", "raw", "ft-transfer", dstChain.ChainMeta.Id, srcChain.ChainMeta.Id, "transfer", "channel-0", token.Amount.String(), fmt.Sprintf("--denom=%s", token.Denom), fmt.Sprintf("--receiver=%s", recipient), "--timeout-height-offset=1000"} + s.ExecTx("", 0, cmd, "Success") + + s.T().Logf("sending %s from %s to %s (%s)", token, srcChain.ChainMeta.Id, dstChain.ChainMeta.Id, recipient) + balancesBPre, err := s.queryBalances(dstChain, 0, recipient) + s.Require().NoError(err) + s.Require().Eventually( func() bool { - balancesBPost, err := s.queryBalances(s.valResources[dstChain.ChainMeta.Id][0].Container.ID, recipient) + balancesBPost, err := s.queryBalances(dstChain, 0, recipient) s.Require().NoError(err) ibcCoin := balancesBPost.Sub(balancesBPre) if ibcCoin.Len() == 1 { @@ -150,307 +150,71 @@ func (s *IntegrationTestSuite) sendIBC(srcChain *chain.Chain, dstChain *chain.Ch func (s *IntegrationTestSuite) submitUpgradeProposal(c *chain.Chain, upgradeHeight int) { upgradeHeightStr := strconv.Itoa(upgradeHeight) - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - s.T().Logf("submitting upgrade proposal on %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) - - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][0].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "tx", "gov", "submit-proposal", "software-upgrade", upgradeVersion, fmt.Sprintf("--title=\"%s upgrade\"", upgradeVersion), "--description=\"upgrade proposal submission\"", fmt.Sprintf("--upgrade-height=%s", upgradeHeightStr), "--upgrade-info=\"\"", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", - }, - }) - s.Require().NoError(err) - - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - return strings.Contains(outBuf.String(), "code: 0") - }, - time.Minute, - time.Second, - "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - + cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "software-upgrade", upgradeVersion, fmt.Sprintf("--title=\"%s upgrade\"", upgradeVersion), "--description=\"upgrade proposal submission\"", fmt.Sprintf("--upgrade-height=%s", upgradeHeightStr), "--upgrade-info=\"\"", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json"} + s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted upgrade proposal") c.PropNumber = c.PropNumber + 1 } func (s *IntegrationTestSuite) submitSuperfluidProposal(c *chain.Chain, asset string) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - s.T().Logf("submitting superfluid proposal for asset %s on %s container: %s", asset, s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) - - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][0].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "tx", "gov", "submit-proposal", "set-superfluid-assets-proposal", fmt.Sprintf("--superfluid-assets=%s", asset), fmt.Sprintf("--title=\"%s superfluid asset\"", asset), fmt.Sprintf("--description=\"%s superfluid asset\"", asset), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), - }, - }) - s.Require().NoError(err) - - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - return strings.Contains(outBuf.String(), "code: 0") - }, - time.Minute, - time.Second, - "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - + cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "set-superfluid-assets-proposal", fmt.Sprintf("--superfluid-assets=%s", asset), fmt.Sprintf("--title=\"%s superfluid asset\"", asset), fmt.Sprintf("--description=\"%s superfluid asset\"", asset), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id)} + s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted superfluid proposal") c.PropNumber = c.PropNumber + 1 } func (s *IntegrationTestSuite) submitTextProposal(c *chain.Chain, text string) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - s.T().Logf("submitting text proposal on %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) - - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][0].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "tx", "gov", "submit-proposal", "--type=text", fmt.Sprintf("--title=\"%s\"", text), "--description=\"test text proposal\"", "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), - }, - }) - s.Require().NoError(err) - - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - return strings.Contains(outBuf.String(), "code: 0") - }, - time.Minute, - time.Second, - "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - + cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "--type=text", fmt.Sprintf("--title=\"%s\"", text), "--description=\"test text proposal\"", "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id)} + s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted text proposal") c.PropNumber = c.PropNumber + 1 } func (s *IntegrationTestSuite) depositProposal(c *chain.Chain) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - propStr := strconv.Itoa(c.PropNumber) - s.T().Logf("depositing to proposal from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) - - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][0].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "tx", "gov", "deposit", propStr, "500000000uosmo", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test", - }, - }) - s.Require().NoError(err) - - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - return strings.Contains(outBuf.String(), "code: 0") - }, - time.Minute, - time.Second, - "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - + cmd := []string{"osmosisd", "tx", "gov", "deposit", propStr, "500000000uosmo", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully deposited to proposal") } -func (s *IntegrationTestSuite) voteProposal(chainConfig *chainConfig) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - chain := chainConfig.chain - propStr := strconv.Itoa(chain.PropNumber) - - s.T().Logf("voting for upgrade proposal for chain-id: %s", chain.ChainMeta.Id) - for i := range chain.Validators { +func (s *IntegrationTestSuite) voteProposal(c *chain.Chain, chainConfig *chainConfig) { + propStr := strconv.Itoa(c.PropNumber) + s.T().Logf("voting yes on proposal for chain-id: %s", c.ChainMeta.Id) + cmd := []string{"osmosisd", "tx", "gov", "vote", propStr, "yes", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} + for i := range c.Validators { if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { continue } - - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[chain.ChainMeta.Id][i].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "tx", "gov", "vote", propStr, "yes", "--from=val", fmt.Sprintf("--chain-id=%s", chain.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test", - }, - }) - s.Require().NoError(err) - - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - return strings.Contains(outBuf.String(), "code: 0") - }, - time.Minute, - time.Second, - "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - - s.T().Logf("successfully voted for proposal from %s container: %s", s.valResources[chain.ChainMeta.Id][i].Container.Name[1:], s.valResources[chain.ChainMeta.Id][i].Container.ID) + s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") + s.T().Logf("successfully voted yes on proposal from %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) } } func (s *IntegrationTestSuite) voteNoProposal(c *chain.Chain, i int, from string) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() propStr := strconv.Itoa(c.PropNumber) - s.T().Logf("voting no for proposal for chain-id: %s", c.ChainMeta.Id) - - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][i].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "tx", "gov", "vote", propStr, "no", fmt.Sprintf("--from=%s", from), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test", - }, - }) - s.Require().NoError(err) - - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - return strings.Contains(outBuf.String(), "code: 0") - }, - time.Minute, - time.Second, - "tx returned a non-zero code; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - + s.T().Logf("voting no on proposal for chain-id: %s", c.ChainMeta.Id) + cmd := []string{"osmosisd", "tx", "gov", "vote", propStr, "no", fmt.Sprintf("--from=%s", from), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") s.T().Logf("successfully voted no for proposal from %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) - } -func (s *IntegrationTestSuite) chainStatus(containerId string) []byte { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: containerId, - User: "root", - Cmd: []string{ - "osmosisd", "status", - }, - }) +func (s *IntegrationTestSuite) chainStatus(c *chain.Chain, i int) []byte { + cmd := []string{"osmosisd", "status"} + _, errBuf, err := s.ExecTx(c.ChainMeta.Id, i, cmd, "") s.Require().NoError(err) - - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - - s.Require().NoErrorf( - err, - "failed to query height; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - - errBufByte := errBuf.Bytes() - return errBufByte + return errBuf.Bytes() } -func (s *IntegrationTestSuite) getCurrentChainHeight(containerId string) int { +func (s *IntegrationTestSuite) getCurrentChainHeight(c *chain.Chain, i int) int { var block syncInfo s.Require().Eventually( func() bool { - out := s.chainStatus(containerId) + out := s.chainStatus(c, i) err := json.Unmarshal(out, &block) if err != nil { return false @@ -466,42 +230,13 @@ func (s *IntegrationTestSuite) getCurrentChainHeight(containerId string) int { return currentHeight } -func (s *IntegrationTestSuite) queryBalances(containerId string, addr string) (sdk.Coins, error) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: containerId, - User: "root", - Cmd: []string{ - "osmosisd", "query", "bank", "balances", addr, "--output=json", - }, - }) +func (s *IntegrationTestSuite) queryBalances(c *chain.Chain, i int, addr string) (sdk.Coins, error) { + cmd := []string{"osmosisd", "query", "bank", "balances", addr, "--output=json"} + outBuf, _, err := s.ExecTx(c.ChainMeta.Id, i, cmd, "") s.Require().NoError(err) - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - - s.Require().NoErrorf( - err, - "failed to query height; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - - outBufByte := outBuf.Bytes() var balancesResp banktypes.QueryAllBalancesResponse - if err := util.Cdc.UnmarshalJSON(outBufByte, &balancesResp); err != nil { + if err := util.Cdc.UnmarshalJSON(outBuf.Bytes(), &balancesResp); err != nil { return nil, err } @@ -514,33 +249,8 @@ func (s *IntegrationTestSuite) queryPropTally(endpoint, addr string) (sdk.Int, s "%s/cosmos/gov/v1beta1/proposals/%s/tally", endpoint, addr, ) - var err error - var resp *http.Response - retriesLeft := 5 - for { - resp, err = http.Get(path) - - if resp.StatusCode == http.StatusServiceUnavailable { - retriesLeft-- - if retriesLeft == 0 { - return sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), fmt.Errorf("exceeded retry limit of %d with %d", retriesLeft, http.StatusServiceUnavailable) - } - time.Sleep(10 * time.Second) - } else { - break - } - } - - if err != nil { - return sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), fmt.Errorf("failed to execute HTTP request: %w", err) - } - - defer resp.Body.Close() - - bz, err := io.ReadAll(resp.Body) - if err != nil { - return sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), sdk.ZeroInt(), err - } + bz, err := s.ExecQueryRPC(path) + s.Require().NoError(err) var balancesResp govtypes.QueryTallyResultResponse if err := util.Cdc.UnmarshalJSON(bz, &balancesResp); err != nil { @@ -555,212 +265,53 @@ func (s *IntegrationTestSuite) queryPropTally(endpoint, addr string) (sdk.Int, s } func (s *IntegrationTestSuite) createPool(c *chain.Chain, poolFile string) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() s.T().Logf("creating pool for chain-id: %s", c.ChainMeta.Id) - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][0].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "tx", "gamm", "create-pool", fmt.Sprintf("--pool-file=/osmosis/%s", poolFile), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", - }, - }) - s.Require().NoError(err) - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - return strings.Contains(outBuf.String(), "code: 0") - }, - time.Minute, - time.Second, - "tx returned non code 0; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - + cmd := []string{"osmosisd", "tx", "gamm", "create-pool", fmt.Sprintf("--pool-file=/osmosis/%s", poolFile), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Logf("successfully created pool from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) - } func (s *IntegrationTestSuite) lockTokens(c *chain.Chain, i int, tokens string, duration string, from string) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() s.T().Logf("locking %s for %s on chain-id: %s", tokens, duration, c.ChainMeta.Id) - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][i].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--duration=%s", duration), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test", - }, - }) - s.Require().NoError(err) - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - return strings.Contains(outBuf.String(), "code: 0") - }, - time.Minute, - time.Second, - "tx returned non code 0; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - c.LockNumber = c.LockNumber + 1 + cmd := []string{"osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--duration=%s", duration), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") s.T().Logf("successfully created lock %v from %s container: %s", c.LockNumber, s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + c.LockNumber = c.LockNumber + 1 } func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, valAddress string, from string) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() lockStr := strconv.Itoa(c.LockNumber) s.T().Logf("superfluid delegating lock %s to %s on chain-id: %s", lockStr, valAddress, c.ChainMeta.Id) - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][0].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "tx", "superfluid", "delegate", lockStr, valAddress, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test", - }, - }) - s.Require().NoError(err) - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - return strings.Contains(outBuf.String(), "code: 0") - }, - 5*time.Minute, - time.Second, - "tx returned non code 0; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - + cmd := []string{"osmosisd", "tx", "superfluid", "delegate", lockStr, valAddress, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Logf("successfully superfluid delegated from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) } func (s *IntegrationTestSuite) sendTx(c *chain.Chain, i int, amount string, sendAddress string, receiveAddress string) { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() s.T().Logf("sending %s from %s to %s on chain-id: %s", amount, sendAddress, receiveAddress, c.ChainMeta.Id) - - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[c.ChainMeta.Id][i].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "tx", "bank", "send", sendAddress, receiveAddress, amount, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", - }, - }) - s.Require().NoError(err) - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - return strings.Contains(outBuf.String(), "code: 0") - }, - 5*time.Minute, - time.Second, - "tx returned non code 0; stdout: %s, stderr: %s", outBuf.String(), errBuf.String(), - ) - + cmd := []string{"osmosisd", "tx", "bank", "send", sendAddress, receiveAddress, amount, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Logf("successfully sent tx from %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) } func (s *IntegrationTestSuite) extractOperAddress(chainConfig *chainConfig) { chain := chainConfig.chain - ctx, cancel := context.WithTimeout(context.Background(), time.Minute) - defer cancel() - s.T().Logf("extracting validator operator addresses for chain-id: %s", chain.ChainMeta.Id) for i, val := range chain.Validators { if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { s.T().Logf("skipping %s validator with index %d from running...", val.Name, i) continue } - - var ( - outBuf bytes.Buffer - errBuf bytes.Buffer - ) - - s.Require().Eventually( - func() bool { - exec, err := s.dkrPool.Client.CreateExec(docker.CreateExecOptions{ - Context: ctx, - AttachStdout: true, - AttachStderr: true, - Container: s.valResources[chain.ChainMeta.Id][i].Container.ID, - User: "root", - Cmd: []string{ - "osmosisd", "debug", "addr", val.PublicKey, - }, - }) - s.Require().NoError(err) - - err = s.dkrPool.Client.StartExec(exec.ID, docker.StartExecOptions{ - Context: ctx, - Detach: false, - OutputStream: &outBuf, - ErrorStream: &errBuf, - }) - if err != nil { - return false - } - return true - }, - time.Minute, - time.Second, - ) + cmd := []string{"osmosisd", "debug", "addr", val.PublicKey} + s.T().Logf("extracting validator operator addresses for chain-id: %s", chain.ChainMeta.Id) + _, errBuf, err := s.ExecTx(chain.ChainMeta.Id, i, cmd, "") + s.Require().NoError(err) re := regexp.MustCompile("osmovaloper(.{39})") operAddr := fmt.Sprintf("%s\n", re.FindString(errBuf.String())) val.OperAddress = strings.TrimSuffix(operAddr, "\n") - } } @@ -770,33 +321,8 @@ func (s *IntegrationTestSuite) queryIntermediaryAccount(c *chain.Chain, endpoint "%s/cosmos/staking/v1beta1/validators/%s/delegations/%s", endpoint, valAddr, intAccount, ) - var err error - var resp *http.Response - retriesLeft := 5 - for { - resp, err = http.Get(path) - - if resp.StatusCode == http.StatusServiceUnavailable { - retriesLeft-- - if retriesLeft == 0 { - return 0, fmt.Errorf("exceeded retry limit of %d with %d", retriesLeft, http.StatusServiceUnavailable) - } - time.Sleep(10 * time.Second) - } else { - break - } - } - - if err != nil { - return 0, fmt.Errorf("failed to execute HTTP request: %w", err) - } - - defer resp.Body.Close() - - bz, err := io.ReadAll(resp.Body) - if err != nil { - return 0, err - } + bz, err := s.ExecQueryRPC(path) + s.Require().NoError(err) var stakingResp stakingtypes.QueryDelegationResponse if err := util.Cdc.UnmarshalJSON(bz, &stakingResp); err != nil { From 02bbe8c1b0441852b09c217d37f04698061b9c3b Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Fri, 27 May 2022 12:40:23 -0500 Subject: [PATCH 12/20] remove majority boilerplate --- Dockerfile | 2 +- tests/e2e/chain/chain.go | 3 - tests/e2e/chain/config.go | 9 ++ tests/e2e/chain/export.go | 17 ++- tests/e2e/chain_init/chain-init.Dockerfile | 1 - tests/e2e/docker/image_config.go | 2 +- tests/e2e/e2e_setup_test.go | 16 ++- tests/e2e/e2e_test.go | 122 +++++++++++---------- tests/e2e/e2e_util_test.go | 50 +++++---- tests/e2e/scripts/add_account.sh | 3 + 10 files changed, 125 insertions(+), 100 deletions(-) create mode 100755 tests/e2e/scripts/add_account.sh diff --git a/Dockerfile b/Dockerfile index 9775179a9a2..c19c32835fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build # Runner # -------------------------------------------------------- -FROM gcr.io/distroless/base-debian11:${BASE_IMG_TAG} +FROM alpine COPY --from=build /osmosis/build/osmosisd /bin/osmosisd diff --git a/tests/e2e/chain/chain.go b/tests/e2e/chain/chain.go index ab8818d6f1a..a746bcc7440 100644 --- a/tests/e2e/chain/chain.go +++ b/tests/e2e/chain/chain.go @@ -41,9 +41,6 @@ func (c *internalChain) createAndInitValidators(count int) error { if err := node.createKey("val"); err != nil { return err } - if err := node.createKey("val2"); err != nil { - return err - } if err := node.createNodeKey(); err != nil { return err } diff --git a/tests/e2e/chain/config.go b/tests/e2e/chain/config.go index daa9ed3ebcf..8b301e0702e 100644 --- a/tests/e2e/chain/config.go +++ b/tests/e2e/chain/config.go @@ -180,6 +180,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } appGenState[banktypes.ModuleName] = bz + // modify stake module genesis params var stakeGenState staketypes.GenesisState if err := util.Cdc.UnmarshalJSON(appGenState[staketypes.ModuleName], &stakeGenState); err != nil { return err @@ -200,6 +201,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } appGenState[staketypes.ModuleName] = sz + // modify pool incentives module genesis params var pooliGenState poolitypes.GenesisState if err := util.Cdc.UnmarshalJSON(appGenState[poolitypes.ModuleName], &pooliGenState); err != nil { return err @@ -222,6 +224,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } appGenState[poolitypes.ModuleName] = pz + // modify incentives module genesis params var incentivesGenState incentivestypes.GenesisState if err := util.Cdc.UnmarshalJSON(appGenState[incentivestypes.ModuleName], &incentivesGenState); err != nil { return err @@ -245,6 +248,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } appGenState[incentivestypes.ModuleName] = iz + // modify mint module genesis params var mintGenState minttypes.GenesisState if err := util.Cdc.UnmarshalJSON(appGenState[minttypes.ModuleName], &mintGenState); err != nil { return err @@ -259,6 +263,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } appGenState[minttypes.ModuleName] = mz + // modify txfees module genesis params var txfeesGenState txfeestypes.GenesisState if err := util.Cdc.UnmarshalJSON(appGenState[txfeestypes.ModuleName], &txfeesGenState); err != nil { return err @@ -272,6 +277,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } appGenState[txfeestypes.ModuleName] = tz + // modify gamm module genesis params var gammGenState gammtypes.GenesisState if err := util.Cdc.UnmarshalJSON(appGenState[gammtypes.ModuleName], &gammGenState); err != nil { return err @@ -285,6 +291,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } appGenState[gammtypes.ModuleName] = gaz + // modify epoch module genesis params var epochGenState epochtypes.GenesisState if err := util.Cdc.UnmarshalJSON(appGenState[epochtypes.ModuleName], &epochGenState); err != nil { return err @@ -318,6 +325,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } appGenState[epochtypes.ModuleName] = ez + // modify crisis module genesis params var crisisGenState crisistypes.GenesisState if err := util.Cdc.UnmarshalJSON(appGenState[crisistypes.ModuleName], &crisisGenState); err != nil { return err @@ -331,6 +339,7 @@ func initGenesis(c *internalChain, votingPeriod time.Duration) error { } appGenState[crisistypes.ModuleName] = cz + // modify gov module genesis params var govGenState govtypes.GenesisState if err := util.Cdc.UnmarshalJSON(appGenState[govtypes.ModuleName], &govGenState); err != nil { return err diff --git a/tests/e2e/chain/export.go b/tests/e2e/chain/export.go index b2ddab9e9ac..d4587234e5f 100644 --- a/tests/e2e/chain/export.go +++ b/tests/e2e/chain/export.go @@ -8,21 +8,18 @@ type ChainMeta struct { } type Validator struct { - Name string `json:"name"` - ConfigDir string `json:"configDir"` - Index int `json:"index"` - Mnemonic string `json:"mnemonic"` - PublicAddress string `json:"publicAddress"` - PublicAddress2 string `json:"publicAddress2"` - PublicKey string `json:"publicKey"` - OperAddress string `json:"operAddress"` + Name string `json:"name"` + ConfigDir string `json:"configDir"` + Index int `json:"index"` + Mnemonic string `json:"mnemonic"` + PublicAddress string `json:"publicAddress"` + PublicKey string `json:"publicKey"` + OperAddress string `json:"operAddress"` } type Chain struct { ChainMeta ChainMeta `json:"chainMeta"` Validators []*Validator `json:"validators"` - PropNumber int `json:"propNumber"` - LockNumber int `json:"lockNumber"` } func (c *ChainMeta) configDir() string { diff --git a/tests/e2e/chain_init/chain-init.Dockerfile b/tests/e2e/chain_init/chain-init.Dockerfile index e5b86262413..4e192d6c670 100644 --- a/tests/e2e/chain_init/chain-init.Dockerfile +++ b/tests/e2e/chain_init/chain-init.Dockerfile @@ -26,7 +26,6 @@ RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build-e2e-chain-init ## Deploy image FROM ubuntu -RUN apt-get update && apt-get install -y jq moreutils COPY --from=build /osmosis/build/chain_init /bin/chain_init diff --git a/tests/e2e/docker/image_config.go b/tests/e2e/docker/image_config.go index 5d43d894b71..9c14346760f 100644 --- a/tests/e2e/docker/image_config.go +++ b/tests/e2e/docker/image_config.go @@ -31,7 +31,7 @@ const ( previousVersionOsmoTag = "v8.0.0-2-debug" // Pre-upgrade repo/tag for osmosis initialization (this should be one version below upgradeVersion) previousVersionInitRepository = "osmolabs/osmosis-init" - previousVersionInitTag = "v8.0.0-2-osmo" + previousVersionInitTag = "v8.0.0-4-osmo" // Hermes repo/version for relayer relayerRepository = "osmolabs/hermes" relayerTag = "0.13.0" diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 3ced2533774..59588f9721a 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -33,12 +33,8 @@ type syncInfo struct { SyncInfo status `json:"SyncInfo"` } -type valinfo struct { - VotingPower string `json:"VotingPower"` -} - type operInfo struct { - Bech32Val string `json:"Bech32 Val"` + Bech32Val string `json:"bech32_val"` } type chainConfig struct { @@ -50,6 +46,8 @@ type chainConfig struct { // This is needed for testing functionality like state-sync where we would // like to start a node during tests post-initialization. skipRunValidatorIndexes map[int]struct{} + propNumber int + lockNumber int chain *chain.Chain } @@ -175,7 +173,7 @@ func (s *IntegrationTestSuite) SetupSuite() { for i, chainConfig := range s.chainConfigs { s.runValidators(chainConfig, s.dockerImages.OsmosisRepository, s.dockerImages.OsmosisTag, i*10) - s.extractOperAddress(chainConfig) + s.extractValidatorOperatorAddress(chainConfig) } // Run a relayer between every possible pair of chains. @@ -485,9 +483,9 @@ func (s *IntegrationTestSuite) upgrade() { for _, chainConfig := range s.chainConfigs { currentHeight := s.getCurrentChainHeight(chainConfig.chain, 0) chainConfig.propHeight = currentHeight + int(chainConfig.votingPeriod) + int(propSubmitBlocks) + int(propBufferBlocks) - s.submitUpgradeProposal(chainConfig.chain, chainConfig.propHeight) - s.depositProposal(chainConfig.chain) - s.voteProposal(chainConfig.chain, chainConfig) + s.submitUpgradeProposal(chainConfig) + s.depositProposal(chainConfig) + s.voteProposal(chainConfig) } // wait till all chains halt at upgrade height diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index ebdbed712f0..d94e98f7108 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -4,64 +4,76 @@ import ( "fmt" "strconv" "time" + + "github.com/osmosis-labs/osmosis/v7/tests/e2e/chain" ) -func (s *IntegrationTestSuite) TestSuperfluidVoting() { +func (s *IntegrationTestSuite) TestIBCTokenTransfer() { chainA := s.chainConfigs[0].chain - s.Run("superfluid_vote_chainA", func() { - s.submitSuperfluidProposal(chainA, "gamm/pool/1") - s.depositProposal(chainA) - s.voteProposal(chainA, s.chainConfigs[0]) - // send gamm tokens to validator's other wallet (non self-delegation wallet) - s.sendTx(chainA, 0, "100000000000000000000gamm/pool/1", chainA.Validators[0].PublicAddress, chainA.Validators[0].PublicAddress2) - // lock tokens from validator 0 on chain A - s.lockTokens(chainA, 0, "100000000000000000000gamm/pool/1", "240s", "val2") - // superfluid delegate from validator 0 non self-delegation wallet to validator 1 on chain A - s.superfluidDelegate(chainA, s.chainConfigs[0].chain.Validators[1].OperAddress, "val2") - // create a text prop, deposit and vote yes - s.submitTextProposal(chainA, "superfluid vote overwrite test") - s.depositProposal(chainA) - s.voteProposal(chainA, s.chainConfigs[0]) - // set delegator vote to no - s.voteNoProposal(chainA, 0, "val2") + chainB := s.chainConfigs[1].chain + + // compare coins of receiver pre and post IBC send + // diff should only be the amount sent + s.sendIBC(chainA, chainB, chainB.Validators[0].PublicAddress, chain.OsmoToken) +} + +func (s *IntegrationTestSuite) TestSuperfluidVoting() { + chainA := s.chainConfigs[0] + s.submitSuperfluidProposal(chainA, "gamm/pool/1") + s.depositProposal(chainA) + s.voteProposal(chainA) + s.ExecTx(chainA.chain.ChainMeta.Id, 0, []string{"chmod", "+x", "./add_account.sh"}, "") + s.ExecTx(chainA.chain.ChainMeta.Id, 0, []string{"./add_account.sh"}, "") + // send gamm tokens to validator's other wallet (non self-delegation wallet) + s.sendTx(chainA.chain, 0, "100000000000000000000gamm/pool/1", chainA.chain.Validators[0].PublicAddress, "osmo12smx2wdlyttvyzvzg54y2vnqwq2qjateuf7thj") + // lock tokens from validator 0 on chain A + s.lockTokens(chainA, 0, "100000000000000000000gamm/pool/1", "240s", "wallet") + // superfluid delegate from validator 0 non self-delegation wallet to validator 1 on chain A + s.superfluidDelegate(chainA, s.chainConfigs[0].chain.Validators[1].OperAddress, "wallet") + // create a text prop, deposit and vote yes + s.submitTextProposal(chainA, "superfluid vote overwrite test") + s.depositProposal(chainA) + s.voteProposal(chainA) + // set delegator vote to no + s.voteNoProposal(chainA, 0, "wallet") + + chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[chainA.chain.ChainMeta.Id][0].GetHostPort("1317/tcp")) + sfProposalNumber := strconv.Itoa(chainA.propNumber) + s.Require().Eventually( + func() bool { + noTotal, yesTotal, noWithVetoTotal, abstainTotal, err := s.queryPropTally(chainAAPIEndpoint, sfProposalNumber) + if err != nil { + return false + } + if abstainTotal.Int64()+noTotal.Int64()+noWithVetoTotal.Int64()+yesTotal.Int64() <= 0 { + return false + } + return true + }, + 1*time.Minute, + time.Second, + "Osmosis node failed to retrieve prop tally", + ) + noTotal, _, _, _, _ := s.queryPropTally(chainAAPIEndpoint, sfProposalNumber) + noTotalFinal, err := strconv.Atoi(noTotal.String()) + s.Require().NoError(err) - chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[chainA.ChainMeta.Id][0].GetHostPort("1317/tcp")) - sfProposalNumber := strconv.Itoa(chainA.PropNumber) - s.Require().Eventually( - func() bool { - noTotal, yesTotal, noWithVetoTotal, abstainTotal, err := s.queryPropTally(chainAAPIEndpoint, sfProposalNumber) - if err != nil { - return false - } - if abstainTotal.Int64()+noTotal.Int64()+noWithVetoTotal.Int64()+yesTotal.Int64() <= 0 { - return false - } - return true - }, - 1*time.Minute, - time.Second, - "Osmosis node failed to retrieve prop tally", - ) - noTotal, _, _, _, _ := s.queryPropTally(chainAAPIEndpoint, sfProposalNumber) - noTotalFinal, err := strconv.Atoi(noTotal.String()) - s.Require().NoError(err) + s.Require().Eventually( + func() bool { + intAccountBalance, err := s.queryIntermediaryAccount(chainA.chain, chainAAPIEndpoint, "gamm/pool/1", chainA.chain.Validators[1].OperAddress) + s.Require().NoError(err) + if err != nil { + return false + } + if noTotalFinal != intAccountBalance { + fmt.Printf("noTotalFinal %v does not match intAccountBalance %v", noTotalFinal, intAccountBalance) + return false + } + return true + }, + 1*time.Minute, + time.Second, + "superfluid delegation vote overwrite not working as expected", + ) - s.Require().Eventually( - func() bool { - intAccountBalance, err := s.queryIntermediaryAccount(chainA, chainAAPIEndpoint, "gamm/pool/1", chainA.Validators[1].OperAddress) - s.Require().NoError(err) - if err != nil { - return false - } - if noTotalFinal != intAccountBalance { - fmt.Printf("noTotalFinal %v does not match intAccountBalance %v", noTotalFinal, intAccountBalance) - return false - } - return true - }, - 1*time.Minute, - time.Second, - "superfluid delegation vote overwrite not working as expected", - ) - }) } diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index 1bc0a6630ab..db78681558e 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -57,6 +57,8 @@ func (s *IntegrationTestSuite) ExecTx(chainId string, validatorIndex int, comman OutputStream: &outBuf, ErrorStream: &errBuf, }) + fmt.Printf("OUTBUFF %s", outBuf.String()) + fmt.Printf("ERRBUFF %s", errBuf.String()) if err != nil { return false } @@ -148,45 +150,50 @@ func (s *IntegrationTestSuite) sendIBC(srcChain *chain.Chain, dstChain *chain.Ch s.T().Log("successfully sent IBC tokens") } -func (s *IntegrationTestSuite) submitUpgradeProposal(c *chain.Chain, upgradeHeight int) { - upgradeHeightStr := strconv.Itoa(upgradeHeight) +func (s *IntegrationTestSuite) submitUpgradeProposal(config *chainConfig) { + c := config.chain + upgradeHeightStr := strconv.Itoa(config.propHeight) s.T().Logf("submitting upgrade proposal on %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "software-upgrade", upgradeVersion, fmt.Sprintf("--title=\"%s upgrade\"", upgradeVersion), "--description=\"upgrade proposal submission\"", fmt.Sprintf("--upgrade-height=%s", upgradeHeightStr), "--upgrade-info=\"\"", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json"} s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted upgrade proposal") - c.PropNumber = c.PropNumber + 1 + config.propNumber = config.propNumber + 1 } -func (s *IntegrationTestSuite) submitSuperfluidProposal(c *chain.Chain, asset string) { +func (s *IntegrationTestSuite) submitSuperfluidProposal(config *chainConfig, asset string) { + c := config.chain s.T().Logf("submitting superfluid proposal for asset %s on %s container: %s", asset, s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "set-superfluid-assets-proposal", fmt.Sprintf("--superfluid-assets=%s", asset), fmt.Sprintf("--title=\"%s superfluid asset\"", asset), fmt.Sprintf("--description=\"%s superfluid asset\"", asset), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id)} s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted superfluid proposal") - c.PropNumber = c.PropNumber + 1 + config.propNumber = config.propNumber + 1 } -func (s *IntegrationTestSuite) submitTextProposal(c *chain.Chain, text string) { +func (s *IntegrationTestSuite) submitTextProposal(config *chainConfig, text string) { + c := config.chain s.T().Logf("submitting text proposal on %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "--type=text", fmt.Sprintf("--title=\"%s\"", text), "--description=\"test text proposal\"", "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id)} s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted text proposal") - c.PropNumber = c.PropNumber + 1 + config.propNumber = config.propNumber + 1 } -func (s *IntegrationTestSuite) depositProposal(c *chain.Chain) { - propStr := strconv.Itoa(c.PropNumber) +func (s *IntegrationTestSuite) depositProposal(config *chainConfig) { + c := config.chain + propStr := strconv.Itoa(config.propNumber) s.T().Logf("depositing to proposal from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) cmd := []string{"osmosisd", "tx", "gov", "deposit", propStr, "500000000uosmo", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully deposited to proposal") } -func (s *IntegrationTestSuite) voteProposal(c *chain.Chain, chainConfig *chainConfig) { - propStr := strconv.Itoa(c.PropNumber) +func (s *IntegrationTestSuite) voteProposal(config *chainConfig) { + c := config.chain + propStr := strconv.Itoa(config.propNumber) s.T().Logf("voting yes on proposal for chain-id: %s", c.ChainMeta.Id) cmd := []string{"osmosisd", "tx", "gov", "vote", propStr, "yes", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} for i := range c.Validators { - if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { + if _, ok := config.skipRunValidatorIndexes[i]; ok { continue } s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") @@ -194,8 +201,9 @@ func (s *IntegrationTestSuite) voteProposal(c *chain.Chain, chainConfig *chainCo } } -func (s *IntegrationTestSuite) voteNoProposal(c *chain.Chain, i int, from string) { - propStr := strconv.Itoa(c.PropNumber) +func (s *IntegrationTestSuite) voteNoProposal(config *chainConfig, i int, from string) { + c := config.chain + propStr := strconv.Itoa(config.propNumber) s.T().Logf("voting no on proposal for chain-id: %s", c.ChainMeta.Id) cmd := []string{"osmosisd", "tx", "gov", "vote", propStr, "no", fmt.Sprintf("--from=%s", from), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") @@ -271,17 +279,19 @@ func (s *IntegrationTestSuite) createPool(c *chain.Chain, poolFile string) { s.T().Logf("successfully created pool from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) } -func (s *IntegrationTestSuite) lockTokens(c *chain.Chain, i int, tokens string, duration string, from string) { +func (s *IntegrationTestSuite) lockTokens(config *chainConfig, i int, tokens string, duration string, from string) { + c := config.chain s.T().Logf("locking %s for %s on chain-id: %s", tokens, duration, c.ChainMeta.Id) cmd := []string{"osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--duration=%s", duration), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") - s.T().Logf("successfully created lock %v from %s container: %s", c.LockNumber, s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) - c.LockNumber = c.LockNumber + 1 + s.T().Logf("successfully created lock %v from %s container: %s", config.lockNumber, s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + config.lockNumber = config.lockNumber + 1 } -func (s *IntegrationTestSuite) superfluidDelegate(c *chain.Chain, valAddress string, from string) { - lockStr := strconv.Itoa(c.LockNumber) +func (s *IntegrationTestSuite) superfluidDelegate(config *chainConfig, valAddress string, from string) { + c := config.chain + lockStr := strconv.Itoa(config.lockNumber) s.T().Logf("superfluid delegating lock %s to %s on chain-id: %s", lockStr, valAddress, c.ChainMeta.Id) cmd := []string{"osmosisd", "tx", "superfluid", "delegate", lockStr, valAddress, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") @@ -297,7 +307,7 @@ func (s *IntegrationTestSuite) sendTx(c *chain.Chain, i int, amount string, send } -func (s *IntegrationTestSuite) extractOperAddress(chainConfig *chainConfig) { +func (s *IntegrationTestSuite) extractValidatorOperatorAddress(chainConfig *chainConfig) { chain := chainConfig.chain for i, val := range chain.Validators { diff --git a/tests/e2e/scripts/add_account.sh b/tests/e2e/scripts/add_account.sh new file mode 100755 index 00000000000..92aa8c78d3a --- /dev/null +++ b/tests/e2e/scripts/add_account.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo 'bottom loan skill merry east cradle onion journey palm apology verb edit desert impose absurd oil bubble sweet glove shallow size build burst effort' | osmosisd keys add wallet --recover --keyring-backend test From 976741602cd3a8c47b451eb4687edab4f657793e Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Fri, 27 May 2022 12:50:48 -0500 Subject: [PATCH 13/20] move docker file back to distroless --- tests/localosmosis/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/localosmosis/Dockerfile b/tests/localosmosis/Dockerfile index 85f681e5889..5bf5297b1f6 100644 --- a/tests/localosmosis/Dockerfile +++ b/tests/localosmosis/Dockerfile @@ -30,7 +30,7 @@ RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build # Runner # -------------------------------------------------------- -FROM alpine +FROM gcr.io/distroless/base-debian11:${BASE_IMG_TAG} COPY --from=build /osmosis/build/osmosisd /bin/osmosisd COPY /tests/localosmosis/setup.sh /setup.sh From a4cabddb323c008e07968bf7200b45402b70ccc4 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Fri, 27 May 2022 15:30:50 -0500 Subject: [PATCH 14/20] no longer use bash to add account --- Dockerfile | 2 +- tests/e2e/e2e_test.go | 5 ++--- tests/e2e/e2e_util_test.go | 15 ++++++++++++++- tests/e2e/scripts/.bash_history | 8 ++++++++ tests/e2e/scripts/add_account.sh | 3 --- tests/localosmosis/Dockerfile | 2 +- 6 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 tests/e2e/scripts/.bash_history delete mode 100755 tests/e2e/scripts/add_account.sh diff --git a/Dockerfile b/Dockerfile index c19c32835fb..9775179a9a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build # Runner # -------------------------------------------------------- -FROM alpine +FROM gcr.io/distroless/base-debian11:${BASE_IMG_TAG} COPY --from=build /osmosis/build/osmosisd /bin/osmosisd diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index d94e98f7108..15705a38c21 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -22,10 +22,9 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { s.submitSuperfluidProposal(chainA, "gamm/pool/1") s.depositProposal(chainA) s.voteProposal(chainA) - s.ExecTx(chainA.chain.ChainMeta.Id, 0, []string{"chmod", "+x", "./add_account.sh"}, "") - s.ExecTx(chainA.chain.ChainMeta.Id, 0, []string{"./add_account.sh"}, "") + walletAddr := s.createWallet(chainA.chain, 0, "wallet") // send gamm tokens to validator's other wallet (non self-delegation wallet) - s.sendTx(chainA.chain, 0, "100000000000000000000gamm/pool/1", chainA.chain.Validators[0].PublicAddress, "osmo12smx2wdlyttvyzvzg54y2vnqwq2qjateuf7thj") + s.sendTx(chainA.chain, 0, "100000000000000000000gamm/pool/1", chainA.chain.Validators[0].PublicAddress, walletAddr) // lock tokens from validator 0 on chain A s.lockTokens(chainA, 0, "100000000000000000000gamm/pool/1", "240s", "wallet") // superfluid delegate from validator 0 non self-delegation wallet to validator 1 on chain A diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index db78681558e..b273548fce8 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -302,7 +302,7 @@ func (s *IntegrationTestSuite) superfluidDelegate(config *chainConfig, valAddres func (s *IntegrationTestSuite) sendTx(c *chain.Chain, i int, amount string, sendAddress string, receiveAddress string) { s.T().Logf("sending %s from %s to %s on chain-id: %s", amount, sendAddress, receiveAddress, c.ChainMeta.Id) cmd := []string{"osmosisd", "tx", "bank", "send", sendAddress, receiveAddress, amount, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test"} - s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") + s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") s.T().Logf("successfully sent tx from %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) } @@ -345,3 +345,16 @@ func (s *IntegrationTestSuite) queryIntermediaryAccount(c *chain.Chain, endpoint return intAccountBalance, err } + +func (s *IntegrationTestSuite) createWallet(c *chain.Chain, index int, walletName string) string { + cmd := []string{"osmosisd", "keys", "add", walletName, "--keyring-backend=test"} + outBuf, errBuf, err := s.ExecTx(c.ChainMeta.Id, index, cmd, "") + fmt.Printf("OUTBUF %s\n", outBuf.String()) + fmt.Printf("ERRBUF %s\n", errBuf.String()) + s.Require().NoError(err) + re := regexp.MustCompile("osmo1(.{38})") + walletAddr := fmt.Sprintf("%s\n", re.FindString(outBuf.String())) + walletAddr = strings.TrimSuffix(walletAddr, "\n") + fmt.Printf("WALADDR %s\n", walletAddr) + return walletAddr +} diff --git a/tests/e2e/scripts/.bash_history b/tests/e2e/scripts/.bash_history new file mode 100644 index 00000000000..8d21e633824 --- /dev/null +++ b/tests/e2e/scripts/.bash_history @@ -0,0 +1,8 @@ +osmosisd keys list --keyring-backend test +osmosisd keys add wallet +exit +ls +osmosisd keys list --keyring-backend test +osmosisd q bank balances osmo16ssxe0l899487ye2rjss9yf0y7lgz9djucyadn +osmosisd tx bank send val osmo133uej2dmeukrsx9du6kvgmltcg2xg7dsyssf7q 100000000000000000000gamm/pool/1 --chain-id osmo-test-a --from val -b block --keyring-backend test +exit diff --git a/tests/e2e/scripts/add_account.sh b/tests/e2e/scripts/add_account.sh deleted file mode 100755 index 92aa8c78d3a..00000000000 --- a/tests/e2e/scripts/add_account.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -echo 'bottom loan skill merry east cradle onion journey palm apology verb edit desert impose absurd oil bubble sweet glove shallow size build burst effort' | osmosisd keys add wallet --recover --keyring-backend test diff --git a/tests/localosmosis/Dockerfile b/tests/localosmosis/Dockerfile index 5bf5297b1f6..3a4645f5d27 100644 --- a/tests/localosmosis/Dockerfile +++ b/tests/localosmosis/Dockerfile @@ -30,7 +30,7 @@ RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build # Runner # -------------------------------------------------------- -FROM gcr.io/distroless/base-debian11:${BASE_IMG_TAG} +FROM ubuntu COPY --from=build /osmosis/build/osmosisd /bin/osmosisd COPY /tests/localosmosis/setup.sh /setup.sh From c3ea67665047777dfe6229322e00c8359ec1219d Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Fri, 27 May 2022 15:44:54 -0500 Subject: [PATCH 15/20] remove debugging print statements --- tests/e2e/e2e_util_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index b273548fce8..40fa3226e99 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -57,8 +57,6 @@ func (s *IntegrationTestSuite) ExecTx(chainId string, validatorIndex int, comman OutputStream: &outBuf, ErrorStream: &errBuf, }) - fmt.Printf("OUTBUFF %s", outBuf.String()) - fmt.Printf("ERRBUFF %s", errBuf.String()) if err != nil { return false } @@ -348,9 +346,7 @@ func (s *IntegrationTestSuite) queryIntermediaryAccount(c *chain.Chain, endpoint func (s *IntegrationTestSuite) createWallet(c *chain.Chain, index int, walletName string) string { cmd := []string{"osmosisd", "keys", "add", walletName, "--keyring-backend=test"} - outBuf, errBuf, err := s.ExecTx(c.ChainMeta.Id, index, cmd, "") - fmt.Printf("OUTBUF %s\n", outBuf.String()) - fmt.Printf("ERRBUF %s\n", errBuf.String()) + outBuf, _, err := s.ExecTx(c.ChainMeta.Id, index, cmd, "") s.Require().NoError(err) re := regexp.MustCompile("osmo1(.{38})") walletAddr := fmt.Sprintf("%s\n", re.FindString(outBuf.String())) From 6c0e355260571bc8a559a1e56fb7da0e47f7bc27 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Fri, 27 May 2022 15:48:10 -0500 Subject: [PATCH 16/20] Delete .bash_history --- tests/e2e/scripts/.bash_history | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 tests/e2e/scripts/.bash_history diff --git a/tests/e2e/scripts/.bash_history b/tests/e2e/scripts/.bash_history deleted file mode 100644 index 8d21e633824..00000000000 --- a/tests/e2e/scripts/.bash_history +++ /dev/null @@ -1,8 +0,0 @@ -osmosisd keys list --keyring-backend test -osmosisd keys add wallet -exit -ls -osmosisd keys list --keyring-backend test -osmosisd q bank balances osmo16ssxe0l899487ye2rjss9yf0y7lgz9djucyadn -osmosisd tx bank send val osmo133uej2dmeukrsx9du6kvgmltcg2xg7dsyssf7q 100000000000000000000gamm/pool/1 --chain-id osmo-test-a --from val -b block --keyring-backend test -exit From 4c4358f19fff6612f3d9dd0d132d307bf86ce802 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Fri, 27 May 2022 16:02:07 -0500 Subject: [PATCH 17/20] remove extra line in docker file --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9775179a9a2..b1d1331a642 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ - # syntax=docker/dockerfile:1 ARG BASE_IMG_TAG=nonroot From e209efb4d67cbd2391736ea6544655c3801b43ef Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Sat, 28 May 2022 19:47:18 -0500 Subject: [PATCH 18/20] Apply suggestions from code review Co-authored-by: Roman --- tests/e2e/e2e_setup_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 59588f9721a..f242954288b 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -33,7 +33,7 @@ type syncInfo struct { SyncInfo status `json:"SyncInfo"` } -type operInfo struct { +type validatorOperatorInfo struct { Bech32Val string `json:"bech32_val"` } @@ -46,8 +46,8 @@ type chainConfig struct { // This is needed for testing functionality like state-sync where we would // like to start a node during tests post-initialization. skipRunValidatorIndexes map[int]struct{} - propNumber int - lockNumber int + latestProposalNumber int + latestLockNumber int chain *chain.Chain } From 360abcf3b256f8ebff41d1eddf04d96ffd5fd8b6 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Sat, 28 May 2022 19:59:33 -0500 Subject: [PATCH 19/20] code review suggestions --- tests/e2e/e2e_setup_test.go | 6 +++--- tests/e2e/e2e_test.go | 2 +- tests/e2e/e2e_util_test.go | 31 ++++++++++++++----------------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index f242954288b..7eedf42988c 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -46,8 +46,8 @@ type chainConfig struct { // This is needed for testing functionality like state-sync where we would // like to start a node during tests post-initialization. skipRunValidatorIndexes map[int]struct{} - latestProposalNumber int - latestLockNumber int + latestProposalNumber int + latestLockNumber int chain *chain.Chain } @@ -173,7 +173,7 @@ func (s *IntegrationTestSuite) SetupSuite() { for i, chainConfig := range s.chainConfigs { s.runValidators(chainConfig, s.dockerImages.OsmosisRepository, s.dockerImages.OsmosisTag, i*10) - s.extractValidatorOperatorAddress(chainConfig) + s.extractValidatorOperatorAddresses(chainConfig) } // Run a relayer between every possible pair of chains. diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 15705a38c21..12609cdfa6c 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -37,7 +37,7 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { s.voteNoProposal(chainA, 0, "wallet") chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[chainA.chain.ChainMeta.Id][0].GetHostPort("1317/tcp")) - sfProposalNumber := strconv.Itoa(chainA.propNumber) + sfProposalNumber := strconv.Itoa(chainA.latestProposalNumber) s.Require().Eventually( func() bool { noTotal, yesTotal, noWithVetoTotal, abstainTotal, err := s.queryPropTally(chainAAPIEndpoint, sfProposalNumber) diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index 40fa3226e99..9b809f42ce6 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -155,7 +155,7 @@ func (s *IntegrationTestSuite) submitUpgradeProposal(config *chainConfig) { cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "software-upgrade", upgradeVersion, fmt.Sprintf("--title=\"%s upgrade\"", upgradeVersion), "--description=\"upgrade proposal submission\"", fmt.Sprintf("--upgrade-height=%s", upgradeHeightStr), "--upgrade-info=\"\"", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json"} s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted upgrade proposal") - config.propNumber = config.propNumber + 1 + config.latestProposalNumber = config.latestProposalNumber + 1 } func (s *IntegrationTestSuite) submitSuperfluidProposal(config *chainConfig, asset string) { @@ -164,7 +164,7 @@ func (s *IntegrationTestSuite) submitSuperfluidProposal(config *chainConfig, ass cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "set-superfluid-assets-proposal", fmt.Sprintf("--superfluid-assets=%s", asset), fmt.Sprintf("--title=\"%s superfluid asset\"", asset), fmt.Sprintf("--description=\"%s superfluid asset\"", asset), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id)} s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted superfluid proposal") - config.propNumber = config.propNumber + 1 + config.latestProposalNumber = config.latestProposalNumber + 1 } func (s *IntegrationTestSuite) submitTextProposal(config *chainConfig, text string) { @@ -173,12 +173,12 @@ func (s *IntegrationTestSuite) submitTextProposal(config *chainConfig, text stri cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "--type=text", fmt.Sprintf("--title=\"%s\"", text), "--description=\"test text proposal\"", "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id)} s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted text proposal") - config.propNumber = config.propNumber + 1 + config.latestProposalNumber = config.latestProposalNumber + 1 } func (s *IntegrationTestSuite) depositProposal(config *chainConfig) { c := config.chain - propStr := strconv.Itoa(config.propNumber) + propStr := strconv.Itoa(config.latestProposalNumber) s.T().Logf("depositing to proposal from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) cmd := []string{"osmosisd", "tx", "gov", "deposit", propStr, "500000000uosmo", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") @@ -187,7 +187,7 @@ func (s *IntegrationTestSuite) depositProposal(config *chainConfig) { func (s *IntegrationTestSuite) voteProposal(config *chainConfig) { c := config.chain - propStr := strconv.Itoa(config.propNumber) + propStr := strconv.Itoa(config.latestProposalNumber) s.T().Logf("voting yes on proposal for chain-id: %s", c.ChainMeta.Id) cmd := []string{"osmosisd", "tx", "gov", "vote", propStr, "yes", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} for i := range c.Validators { @@ -201,7 +201,7 @@ func (s *IntegrationTestSuite) voteProposal(config *chainConfig) { func (s *IntegrationTestSuite) voteNoProposal(config *chainConfig, i int, from string) { c := config.chain - propStr := strconv.Itoa(config.propNumber) + propStr := strconv.Itoa(config.latestProposalNumber) s.T().Logf("voting no on proposal for chain-id: %s", c.ChainMeta.Id) cmd := []string{"osmosisd", "tx", "gov", "vote", propStr, "no", fmt.Sprintf("--from=%s", from), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") @@ -242,9 +242,8 @@ func (s *IntegrationTestSuite) queryBalances(c *chain.Chain, i int, addr string) s.Require().NoError(err) var balancesResp banktypes.QueryAllBalancesResponse - if err := util.Cdc.UnmarshalJSON(outBuf.Bytes(), &balancesResp); err != nil { - return nil, err - } + err = util.Cdc.UnmarshalJSON(outBuf.Bytes(), &balancesResp) + s.Require().NoError(err) return balancesResp.GetBalances(), nil @@ -282,14 +281,14 @@ func (s *IntegrationTestSuite) lockTokens(config *chainConfig, i int, tokens str s.T().Logf("locking %s for %s on chain-id: %s", tokens, duration, c.ChainMeta.Id) cmd := []string{"osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--duration=%s", duration), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") - s.T().Logf("successfully created lock %v from %s container: %s", config.lockNumber, s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) - config.lockNumber = config.lockNumber + 1 + s.T().Logf("successfully created lock %v from %s container: %s", config.latestLockNumber, s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + config.latestLockNumber = config.latestLockNumber + 1 } func (s *IntegrationTestSuite) superfluidDelegate(config *chainConfig, valAddress string, from string) { c := config.chain - lockStr := strconv.Itoa(config.lockNumber) + lockStr := strconv.Itoa(config.latestLockNumber) s.T().Logf("superfluid delegating lock %s to %s on chain-id: %s", lockStr, valAddress, c.ChainMeta.Id) cmd := []string{"osmosisd", "tx", "superfluid", "delegate", lockStr, valAddress, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") @@ -305,7 +304,7 @@ func (s *IntegrationTestSuite) sendTx(c *chain.Chain, i int, amount string, send } -func (s *IntegrationTestSuite) extractValidatorOperatorAddress(chainConfig *chainConfig) { +func (s *IntegrationTestSuite) extractValidatorOperatorAddresses(chainConfig *chainConfig) { chain := chainConfig.chain for i, val := range chain.Validators { @@ -333,9 +332,8 @@ func (s *IntegrationTestSuite) queryIntermediaryAccount(c *chain.Chain, endpoint s.Require().NoError(err) var stakingResp stakingtypes.QueryDelegationResponse - if err := util.Cdc.UnmarshalJSON(bz, &stakingResp); err != nil { - return 0, err - } + err = util.Cdc.UnmarshalJSON(bz, &stakingResp) + s.Require().NoError(err) intAccBalance := stakingResp.DelegationResponse.Balance.Amount.String() intAccountBalance, err := strconv.Atoi(intAccBalance) @@ -351,6 +349,5 @@ func (s *IntegrationTestSuite) createWallet(c *chain.Chain, index int, walletNam re := regexp.MustCompile("osmo1(.{38})") walletAddr := fmt.Sprintf("%s\n", re.FindString(outBuf.String())) walletAddr = strings.TrimSuffix(walletAddr, "\n") - fmt.Printf("WALADDR %s\n", walletAddr) return walletAddr } From b9b14efbb0c20d6ee77510fbfd7cc9a9f627c58c Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Mon, 30 May 2022 19:49:19 +0000 Subject: [PATCH 20/20] further validator abstractions --- tests/e2e/chain/export.go | 1 - tests/e2e/e2e_setup_test.go | 124 ++++++++++++++------------- tests/e2e/e2e_test.go | 17 ++-- tests/e2e/e2e_util_test.go | 161 +++++++++++++++++------------------- 4 files changed, 151 insertions(+), 152 deletions(-) diff --git a/tests/e2e/chain/export.go b/tests/e2e/chain/export.go index d4587234e5f..5f715889e37 100644 --- a/tests/e2e/chain/export.go +++ b/tests/e2e/chain/export.go @@ -14,7 +14,6 @@ type Validator struct { Mnemonic string `json:"mnemonic"` PublicAddress string `json:"publicAddress"` PublicKey string `json:"publicKey"` - OperAddress string `json:"operAddress"` } type Chain struct { diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 7eedf42988c..16d541d6181 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -33,8 +33,9 @@ type syncInfo struct { SyncInfo status `json:"SyncInfo"` } -type validatorOperatorInfo struct { - Bech32Val string `json:"bech32_val"` +type validatorConfig struct { + validator chain.Validator + operatorAddress string } type chainConfig struct { @@ -48,7 +49,8 @@ type chainConfig struct { skipRunValidatorIndexes map[int]struct{} latestProposalNumber int latestLockNumber int - chain *chain.Chain + meta chain.ChainMeta + validators []*validatorConfig } const ( @@ -179,7 +181,7 @@ func (s *IntegrationTestSuite) SetupSuite() { // Run a relayer between every possible pair of chains. for i := 0; i < len(s.chainConfigs); i++ { for j := i + 1; j < len(s.chainConfigs); j++ { - s.runIBCRelayer(s.chainConfigs[i].chain, s.chainConfigs[j].chain) + s.runIBCRelayer(s.chainConfigs[i], s.chainConfigs[j]) } } @@ -213,7 +215,7 @@ func (s *IntegrationTestSuite) TearDownSuite() { s.Require().NoError(s.dkrPool.RemoveNetwork(s.dkrNet)) for _, chainConfig := range s.chainConfigs { - os.RemoveAll(chainConfig.chain.ChainMeta.DataDir) + os.RemoveAll(chainConfig.meta.DataDir) } for _, td := range s.tmpDirs { @@ -222,25 +224,24 @@ func (s *IntegrationTestSuite) TearDownSuite() { } func (s *IntegrationTestSuite) runValidators(chainConfig *chainConfig, dockerRepository, dockerTag string, portOffset int) { - chain := chainConfig.chain - s.T().Logf("starting %s validator containers...", chain.ChainMeta.Id) - s.valResources[chain.ChainMeta.Id] = make([]*dockertest.Resource, len(chain.Validators)-len(chainConfig.skipRunValidatorIndexes)) + s.T().Logf("starting %s validator containers...", chainConfig.meta.Id) + s.valResources[chainConfig.meta.Id] = make([]*dockertest.Resource, len(chainConfig.validators)-len(chainConfig.skipRunValidatorIndexes)) pwd, err := os.Getwd() s.Require().NoError(err) - for i, val := range chain.Validators { + for i, val := range chainConfig.validators { // Skip some validators from running during set up. // This is needed for testing functionality like // state-sunc where we might want to start some validators during tests. if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { - s.T().Logf("skipping %s validator with index %d from running...", val.Name, i) + s.T().Logf("skipping %s validator with index %d from running...", val.validator.Name, i) continue } runOpts := &dockertest.RunOptions{ - Name: val.Name, + Name: val.validator.Name, NetworkID: s.dkrNet.Network.ID, Mounts: []string{ - fmt.Sprintf("%s/:/osmosis/.osmosisd", val.ConfigDir), + fmt.Sprintf("%s/:/osmosis/.osmosisd", val.validator.ConfigDir), fmt.Sprintf("%s/scripts:/osmosis", pwd), }, Repository: dockerRepository, @@ -251,7 +252,7 @@ func (s *IntegrationTestSuite) runValidators(chainConfig *chainConfig, dockerRep } // expose the first validator for debugging and communication - if val.Index == 0 { + if val.validator.Index == 0 { runOpts.PortBindings = map[docker.Port][]docker.PortBinding{ "1317/tcp": {{HostIP: "", HostPort: fmt.Sprintf("%d", 1317+portOffset)}}, "6060/tcp": {{HostIP: "", HostPort: fmt.Sprintf("%d", 6060+portOffset)}}, @@ -269,7 +270,7 @@ func (s *IntegrationTestSuite) runValidators(chainConfig *chainConfig, dockerRep resource, err := s.dkrPool.RunWithOptions(runOpts, noRestart) s.Require().NoError(err) - s.valResources[chain.ChainMeta.Id][i] = resource + s.valResources[chainConfig.meta.Id][i] = resource s.T().Logf("started %s validator container: %s", resource.Container.Name[1:], resource.Container.ID) } @@ -299,15 +300,15 @@ func (s *IntegrationTestSuite) runValidators(chainConfig *chainConfig, dockerRep ) } -func (s *IntegrationTestSuite) runIBCRelayer(chainA *chain.Chain, chainB *chain.Chain) { +func (s *IntegrationTestSuite) runIBCRelayer(chainA *chainConfig, chainB *chainConfig) { s.T().Log("starting Hermes relayer container...") tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-hermes-") s.Require().NoError(err) s.tmpDirs = append(s.tmpDirs, tmpDir) - osmoAVal := chainA.Validators[0] - osmoBVal := chainB.Validators[0] + osmoAVal := chainA.validators[0].validator + osmoBVal := chainB.validators[0].validator hermesCfgPath := path.Join(tmpDir, "hermes") s.Require().NoError(os.MkdirAll(hermesCfgPath, 0o755)) @@ -319,7 +320,7 @@ func (s *IntegrationTestSuite) runIBCRelayer(chainA *chain.Chain, chainB *chain. s.hermesResource, err = s.dkrPool.RunWithOptions( &dockertest.RunOptions{ - Name: fmt.Sprintf("%s-%s-relayer", chainA.ChainMeta.Id, chainB.ChainMeta.Id), + Name: fmt.Sprintf("%s-%s-relayer", chainA.meta.Id, chainB.meta.Id), Repository: s.dockerImages.RelayerRepository, Tag: s.dockerImages.RelayerTag, NetworkID: s.dkrNet.Network.ID, @@ -337,12 +338,12 @@ func (s *IntegrationTestSuite) runIBCRelayer(chainA *chain.Chain, chainB *chain. "3031/tcp": {{HostIP: "", HostPort: "3031"}}, }, Env: []string{ - fmt.Sprintf("OSMO_A_E2E_CHAIN_ID=%s", chainA.ChainMeta.Id), - fmt.Sprintf("OSMO_B_E2E_CHAIN_ID=%s", chainB.ChainMeta.Id), + fmt.Sprintf("OSMO_A_E2E_CHAIN_ID=%s", chainA.meta.Id), + fmt.Sprintf("OSMO_B_E2E_CHAIN_ID=%s", chainB.meta.Id), fmt.Sprintf("OSMO_A_E2E_VAL_MNEMONIC=%s", osmoAVal.Mnemonic), fmt.Sprintf("OSMO_B_E2E_VAL_MNEMONIC=%s", osmoBVal.Mnemonic), - fmt.Sprintf("OSMO_A_E2E_VAL_HOST=%s", s.valResources[chainA.ChainMeta.Id][0].Container.Name[1:]), - fmt.Sprintf("OSMO_B_E2E_VAL_HOST=%s", s.valResources[chainB.ChainMeta.Id][0].Container.Name[1:]), + fmt.Sprintf("OSMO_A_E2E_VAL_HOST=%s", s.valResources[chainA.meta.Id][0].Container.Name[1:]), + fmt.Sprintf("OSMO_B_E2E_VAL_HOST=%s", s.valResources[chainB.meta.Id][0].Container.Name[1:]), }, Entrypoint: []string{ "sh", @@ -436,12 +437,13 @@ func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs [ fileName := fmt.Sprintf("%v/%v-encode", tmpDir, chainId) s.T().Logf("serialized init file for chain-id %v: %v", chainId, fileName) - + var initializedChain chain.Chain // loop through the reading and unmarshaling of the init file a total of maxRetries or until error is nil // without this, test attempts to unmarshal file before docker container is finished writing for i := 0; i < maxRetries; i++ { encJson, _ := os.ReadFile(fileName) - err = json.Unmarshal(encJson, &newChainConfig.chain) + // err = json.Unmarshal(encJson, &newChainConfig.validators) + err = json.Unmarshal(encJson, &initializedChain) if err == nil { break } @@ -456,6 +458,14 @@ func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs [ } s.Require().NoError(s.dkrPool.Purge(s.initResource)) + newChainConfig.meta.DataDir = initializedChain.ChainMeta.DataDir + newChainConfig.meta.Id = initializedChain.ChainMeta.Id + + newChainConfig.validators = make([]*validatorConfig, 0, len(initializedChain.Validators)) + for _, val := range initializedChain.Validators { + newChainConfig.validators = append(newChainConfig.validators, &validatorConfig{validator: *val}) + } + s.chainConfigs = append(s.chainConfigs, &newChainConfig) } @@ -481,7 +491,7 @@ func (s *IntegrationTestSuite) upgrade() { // submit, deposit, and vote for upgrade proposal // prop height = current height + voting period + time it takes to submit proposal + small buffer for _, chainConfig := range s.chainConfigs { - currentHeight := s.getCurrentChainHeight(chainConfig.chain, 0) + currentHeight := s.getCurrentChainHeight(chainConfig, 0) chainConfig.propHeight = currentHeight + int(chainConfig.votingPeriod) + int(propSubmitBlocks) + int(propBufferBlocks) s.submitUpgradeProposal(chainConfig) s.depositProposal(chainConfig) @@ -490,21 +500,21 @@ func (s *IntegrationTestSuite) upgrade() { // wait till all chains halt at upgrade height for _, chainConfig := range s.chainConfigs { - curChain := chainConfig.chain + curChain := chainConfig - for i := range chainConfig.chain.Validators { + for i := range chainConfig.validators { if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { continue } // use counter to ensure no new blocks are being created counter := 0 - s.T().Logf("waiting to reach upgrade height on %s validator container: %s", s.valResources[curChain.ChainMeta.Id][i].Container.Name[1:], s.valResources[curChain.ChainMeta.Id][i].Container.ID) + s.T().Logf("waiting to reach upgrade height on %s validator container: %s", s.valResources[curChain.meta.Id][i].Container.Name[1:], s.valResources[curChain.meta.Id][i].Container.ID) s.Require().Eventually( func() bool { - currentHeight := s.getCurrentChainHeight(chainConfig.chain, i) + currentHeight := s.getCurrentChainHeight(chainConfig, i) if currentHeight != chainConfig.propHeight { - s.T().Logf("current block height on %s is %v, waiting for block %v container: %s", s.valResources[curChain.ChainMeta.Id][i].Container.Name[1:], currentHeight, chainConfig.propHeight, s.valResources[curChain.ChainMeta.Id][i].Container.ID) + s.T().Logf("current block height on %s is %v, waiting for block %v container: %s", s.valResources[curChain.meta.Id][i].Container.Name[1:], currentHeight, chainConfig.propHeight, s.valResources[curChain.meta.Id][i].Container.ID) } if currentHeight > chainConfig.propHeight { panic("chain did not halt at upgrade height") @@ -517,23 +527,23 @@ func (s *IntegrationTestSuite) upgrade() { 5*time.Minute, time.Second, ) - s.T().Logf("reached upgrade height on %s container: %s", s.valResources[curChain.ChainMeta.Id][i].Container.Name[1:], s.valResources[curChain.ChainMeta.Id][i].Container.ID) + s.T().Logf("reached upgrade height on %s container: %s", s.valResources[curChain.meta.Id][i].Container.Name[1:], s.valResources[curChain.meta.Id][i].Container.ID) } } // remove all containers so we can upgrade them to the new version for _, chainConfig := range s.chainConfigs { - curChain := chainConfig.chain - for valIdx := range curChain.Validators { + curChain := chainConfig + for valIdx := range curChain.validators { if _, ok := chainConfig.skipRunValidatorIndexes[valIdx]; ok { continue } var opts docker.RemoveContainerOptions - opts.ID = s.valResources[curChain.ChainMeta.Id][valIdx].Container.ID + opts.ID = s.valResources[curChain.meta.Id][valIdx].Container.ID opts.Force = true s.dkrPool.Client.RemoveContainer(opts) - s.T().Logf("removed container: %s", s.valResources[curChain.ChainMeta.Id][valIdx].Container.Name[1:]) + s.T().Logf("removed container: %s", s.valResources[curChain.meta.Id][valIdx].Container.Name[1:]) } } @@ -545,75 +555,75 @@ func (s *IntegrationTestSuite) upgrade() { func (s *IntegrationTestSuite) upgradeContainers(chainConfig *chainConfig, propHeight int) { // upgrade containers to the locally compiled daemon - chain := chainConfig.chain - s.T().Logf("starting upgrade for chain-id: %s...", chain.ChainMeta.Id) + chain := chainConfig + s.T().Logf("starting upgrade for chain-id: %s...", chain.meta.Id) pwd, err := os.Getwd() s.Require().NoError(err) - for i, val := range chain.Validators { + for i, val := range chain.validators { if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { continue } runOpts := &dockertest.RunOptions{ - Name: val.Name, + Name: val.validator.Name, Repository: dockerconfig.LocalOsmoRepository, Tag: dockerconfig.LocalOsmoTag, NetworkID: s.dkrNet.Network.ID, User: "root:root", Mounts: []string{ - fmt.Sprintf("%s/:/osmosis/.osmosisd", val.ConfigDir), + fmt.Sprintf("%s/:/osmosis/.osmosisd", val.validator.ConfigDir), fmt.Sprintf("%s/scripts:/osmosis", pwd), }, } resource, err := s.dkrPool.RunWithOptions(runOpts, noRestart) s.Require().NoError(err) - s.valResources[chain.ChainMeta.Id][i] = resource + s.valResources[chain.meta.Id][i] = resource s.T().Logf("started %s validator container: %s", resource.Container.Name[1:], resource.Container.ID) } // check that we are creating blocks again - for i := range chain.Validators { + for i := range chain.validators { if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { continue } s.Require().Eventually( func() bool { - currentHeight := s.getCurrentChainHeight(chainConfig.chain, i) + currentHeight := s.getCurrentChainHeight(chainConfig, i) if currentHeight <= propHeight { - s.T().Logf("current block height on %s is %v, waiting to create blocks container: %s", s.valResources[chain.ChainMeta.Id][i].Container.Name[1:], currentHeight, s.valResources[chain.ChainMeta.Id][i].Container.ID) + s.T().Logf("current block height on %s is %v, waiting to create blocks container: %s", s.valResources[chain.meta.Id][i].Container.Name[1:], currentHeight, s.valResources[chainConfig.meta.Id][i].Container.ID) } return currentHeight > propHeight }, 5*time.Minute, time.Second, ) - s.T().Logf("upgrade successful on %s validator container: %s", s.valResources[chain.ChainMeta.Id][i].Container.Name[1:], s.valResources[chain.ChainMeta.Id][i].Container.ID) + s.T().Logf("upgrade successful on %s validator container: %s", s.valResources[chain.meta.Id][i].Container.Name[1:], s.valResources[chain.meta.Id][i].Container.ID) } } func (s *IntegrationTestSuite) createPreUpgradeState() { - chainA := s.chainConfigs[0].chain - chainB := s.chainConfigs[1].chain + chainA := s.chainConfigs[0] + chainB := s.chainConfigs[1] - s.sendIBC(chainA, chainB, chainB.Validators[0].PublicAddress, chain.OsmoToken) - s.sendIBC(chainB, chainA, chainA.Validators[0].PublicAddress, chain.OsmoToken) - s.sendIBC(chainA, chainB, chainB.Validators[0].PublicAddress, chain.StakeToken) - s.sendIBC(chainB, chainA, chainA.Validators[0].PublicAddress, chain.StakeToken) + s.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, chain.OsmoToken) + s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, chain.OsmoToken) + s.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, chain.StakeToken) + s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, chain.StakeToken) s.createPool(chainA, "pool1A.json") s.createPool(chainB, "pool1B.json") } func (s *IntegrationTestSuite) runPostUpgradeTests() { - chainA := s.chainConfigs[0].chain - chainB := s.chainConfigs[1].chain + chainA := s.chainConfigs[0] + chainB := s.chainConfigs[1] - s.sendIBC(chainA, chainB, chainB.Validators[0].PublicAddress, chain.OsmoToken) - s.sendIBC(chainB, chainA, chainA.Validators[0].PublicAddress, chain.OsmoToken) - s.sendIBC(chainA, chainB, chainB.Validators[0].PublicAddress, chain.StakeToken) - s.sendIBC(chainB, chainA, chainA.Validators[0].PublicAddress, chain.StakeToken) + s.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, chain.OsmoToken) + s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, chain.OsmoToken) + s.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, chain.StakeToken) + s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, chain.StakeToken) s.createPool(chainA, "pool2A.json") s.createPool(chainB, "pool2B.json") } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 12609cdfa6c..f7a69798ef3 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -9,12 +9,11 @@ import ( ) func (s *IntegrationTestSuite) TestIBCTokenTransfer() { - chainA := s.chainConfigs[0].chain - chainB := s.chainConfigs[1].chain - + chainA := s.chainConfigs[0] + chainB := s.chainConfigs[1] // compare coins of receiver pre and post IBC send // diff should only be the amount sent - s.sendIBC(chainA, chainB, chainB.Validators[0].PublicAddress, chain.OsmoToken) + s.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, chain.OsmoToken) } func (s *IntegrationTestSuite) TestSuperfluidVoting() { @@ -22,13 +21,13 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { s.submitSuperfluidProposal(chainA, "gamm/pool/1") s.depositProposal(chainA) s.voteProposal(chainA) - walletAddr := s.createWallet(chainA.chain, 0, "wallet") + walletAddr := s.createWallet(chainA, 0, "wallet") // send gamm tokens to validator's other wallet (non self-delegation wallet) - s.sendTx(chainA.chain, 0, "100000000000000000000gamm/pool/1", chainA.chain.Validators[0].PublicAddress, walletAddr) + s.sendTx(chainA, 0, "100000000000000000000gamm/pool/1", chainA.validators[0].validator.PublicAddress, walletAddr) // lock tokens from validator 0 on chain A s.lockTokens(chainA, 0, "100000000000000000000gamm/pool/1", "240s", "wallet") // superfluid delegate from validator 0 non self-delegation wallet to validator 1 on chain A - s.superfluidDelegate(chainA, s.chainConfigs[0].chain.Validators[1].OperAddress, "wallet") + s.superfluidDelegate(chainA, chainA.validators[1].operatorAddress, "wallet") // create a text prop, deposit and vote yes s.submitTextProposal(chainA, "superfluid vote overwrite test") s.depositProposal(chainA) @@ -36,7 +35,7 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { // set delegator vote to no s.voteNoProposal(chainA, 0, "wallet") - chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[chainA.chain.ChainMeta.Id][0].GetHostPort("1317/tcp")) + chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[chainA.meta.Id][0].GetHostPort("1317/tcp")) sfProposalNumber := strconv.Itoa(chainA.latestProposalNumber) s.Require().Eventually( func() bool { @@ -59,7 +58,7 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() { s.Require().Eventually( func() bool { - intAccountBalance, err := s.queryIntermediaryAccount(chainA.chain, chainAAPIEndpoint, "gamm/pool/1", chainA.chain.Validators[1].OperAddress) + intAccountBalance, err := s.queryIntermediaryAccount(chainA, chainAAPIEndpoint, "gamm/pool/1", chainA.validators[1].operatorAddress) s.Require().NoError(err) if err != nil { return false diff --git a/tests/e2e/e2e_util_test.go b/tests/e2e/e2e_util_test.go index 9b809f42ce6..ade23c11196 100644 --- a/tests/e2e/e2e_util_test.go +++ b/tests/e2e/e2e_util_test.go @@ -110,18 +110,18 @@ func (s *IntegrationTestSuite) ExecQueryRPC(path string) ([]byte, error) { return bz, nil } -func (s *IntegrationTestSuite) connectIBCChains(chainA *chain.Chain, chainB *chain.Chain) { - s.T().Logf("connecting %s and %s chains via IBC", chainA.ChainMeta.Id, chainB.ChainMeta.Id) - cmd := []string{"hermes", "create", "channel", chainA.ChainMeta.Id, chainB.ChainMeta.Id, "--port-a=transfer", "--port-b=transfer"} +func (s *IntegrationTestSuite) connectIBCChains(chainA *chainConfig, chainB *chainConfig) { + s.T().Logf("connecting %s and %s chains via IBC", chainA.meta.Id, chainB.meta.Id) + cmd := []string{"hermes", "create", "channel", chainA.meta.Id, chainB.meta.Id, "--port-a=transfer", "--port-b=transfer"} s.ExecTx("", 0, cmd, "successfully opened init channel") - s.T().Logf("connected %s and %s chains via IBC", chainA.ChainMeta.Id, chainB.ChainMeta.Id) + s.T().Logf("connected %s and %s chains via IBC", chainA.meta.Id, chainB.meta.Id) } -func (s *IntegrationTestSuite) sendIBC(srcChain *chain.Chain, dstChain *chain.Chain, recipient string, token sdk.Coin) { - cmd := []string{"hermes", "tx", "raw", "ft-transfer", dstChain.ChainMeta.Id, srcChain.ChainMeta.Id, "transfer", "channel-0", token.Amount.String(), fmt.Sprintf("--denom=%s", token.Denom), fmt.Sprintf("--receiver=%s", recipient), "--timeout-height-offset=1000"} +func (s *IntegrationTestSuite) sendIBC(srcChain *chainConfig, dstChain *chainConfig, recipient string, token sdk.Coin) { + cmd := []string{"hermes", "tx", "raw", "ft-transfer", dstChain.meta.Id, srcChain.meta.Id, "transfer", "channel-0", token.Amount.String(), fmt.Sprintf("--denom=%s", token.Denom), fmt.Sprintf("--receiver=%s", recipient), "--timeout-height-offset=1000"} s.ExecTx("", 0, cmd, "Success") - s.T().Logf("sending %s from %s to %s (%s)", token, srcChain.ChainMeta.Id, dstChain.ChainMeta.Id, recipient) + s.T().Logf("sending %s from %s to %s (%s)", token, srcChain.meta.Id, dstChain.meta.Id, recipient) balancesBPre, err := s.queryBalances(dstChain, 0, recipient) s.Require().NoError(err) @@ -148,75 +148,69 @@ func (s *IntegrationTestSuite) sendIBC(srcChain *chain.Chain, dstChain *chain.Ch s.T().Log("successfully sent IBC tokens") } -func (s *IntegrationTestSuite) submitUpgradeProposal(config *chainConfig) { - c := config.chain - upgradeHeightStr := strconv.Itoa(config.propHeight) - s.T().Logf("submitting upgrade proposal on %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) - cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "software-upgrade", upgradeVersion, fmt.Sprintf("--title=\"%s upgrade\"", upgradeVersion), "--description=\"upgrade proposal submission\"", fmt.Sprintf("--upgrade-height=%s", upgradeHeightStr), "--upgrade-info=\"\"", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json"} - s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") +func (s *IntegrationTestSuite) submitUpgradeProposal(c *chainConfig) { + upgradeHeightStr := strconv.Itoa(c.propHeight) + s.T().Logf("submitting upgrade proposal on %s container: %s", s.valResources[c.meta.Id][0].Container.Name[1:], s.valResources[c.meta.Id][0].Container.ID) + cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "software-upgrade", upgradeVersion, fmt.Sprintf("--title=\"%s upgrade\"", upgradeVersion), "--description=\"upgrade proposal submission\"", fmt.Sprintf("--upgrade-height=%s", upgradeHeightStr), "--upgrade-info=\"\"", fmt.Sprintf("--chain-id=%s", c.meta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json"} + s.ExecTx(c.meta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted upgrade proposal") - config.latestProposalNumber = config.latestProposalNumber + 1 + c.latestProposalNumber = c.latestProposalNumber + 1 } -func (s *IntegrationTestSuite) submitSuperfluidProposal(config *chainConfig, asset string) { - c := config.chain - s.T().Logf("submitting superfluid proposal for asset %s on %s container: %s", asset, s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) - cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "set-superfluid-assets-proposal", fmt.Sprintf("--superfluid-assets=%s", asset), fmt.Sprintf("--title=\"%s superfluid asset\"", asset), fmt.Sprintf("--description=\"%s superfluid asset\"", asset), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id)} - s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") +func (s *IntegrationTestSuite) submitSuperfluidProposal(c *chainConfig, asset string) { + s.T().Logf("submitting superfluid proposal for asset %s on %s container: %s", asset, s.valResources[c.meta.Id][0].Container.Name[1:], s.valResources[c.meta.Id][0].Container.ID) + cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "set-superfluid-assets-proposal", fmt.Sprintf("--superfluid-assets=%s", asset), fmt.Sprintf("--title=\"%s superfluid asset\"", asset), fmt.Sprintf("--description=\"%s superfluid asset\"", asset), "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.meta.Id)} + s.ExecTx(c.meta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted superfluid proposal") - config.latestProposalNumber = config.latestProposalNumber + 1 + c.latestProposalNumber = c.latestProposalNumber + 1 } -func (s *IntegrationTestSuite) submitTextProposal(config *chainConfig, text string) { - c := config.chain - s.T().Logf("submitting text proposal on %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) - cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "--type=text", fmt.Sprintf("--title=\"%s\"", text), "--description=\"test text proposal\"", "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id)} - s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") +func (s *IntegrationTestSuite) submitTextProposal(c *chainConfig, text string) { + s.T().Logf("submitting text proposal on %s container: %s", s.valResources[c.meta.Id][0].Container.Name[1:], s.valResources[c.meta.Id][0].Container.ID) + cmd := []string{"osmosisd", "tx", "gov", "submit-proposal", "--type=text", fmt.Sprintf("--title=\"%s\"", text), "--description=\"test text proposal\"", "--from=val", "-b=block", "--yes", "--keyring-backend=test", "--log_format=json", fmt.Sprintf("--chain-id=%s", c.meta.Id)} + s.ExecTx(c.meta.Id, 0, cmd, "code: 0") s.T().Log("successfully submitted text proposal") - config.latestProposalNumber = config.latestProposalNumber + 1 + c.latestProposalNumber = c.latestProposalNumber + 1 } -func (s *IntegrationTestSuite) depositProposal(config *chainConfig) { - c := config.chain - propStr := strconv.Itoa(config.latestProposalNumber) - s.T().Logf("depositing to proposal from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) - cmd := []string{"osmosisd", "tx", "gov", "deposit", propStr, "500000000uosmo", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} - s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") +func (s *IntegrationTestSuite) depositProposal(c *chainConfig) { + propStr := strconv.Itoa(c.latestProposalNumber) + s.T().Logf("depositing to proposal from %s container: %s", s.valResources[c.meta.Id][0].Container.Name[1:], s.valResources[c.meta.Id][0].Container.ID) + cmd := []string{"osmosisd", "tx", "gov", "deposit", propStr, "500000000uosmo", "--from=val", fmt.Sprintf("--chain-id=%s", c.meta.Id), "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(c.meta.Id, 0, cmd, "code: 0") s.T().Log("successfully deposited to proposal") } -func (s *IntegrationTestSuite) voteProposal(config *chainConfig) { - c := config.chain - propStr := strconv.Itoa(config.latestProposalNumber) - s.T().Logf("voting yes on proposal for chain-id: %s", c.ChainMeta.Id) - cmd := []string{"osmosisd", "tx", "gov", "vote", propStr, "yes", "--from=val", fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} - for i := range c.Validators { - if _, ok := config.skipRunValidatorIndexes[i]; ok { +func (s *IntegrationTestSuite) voteProposal(c *chainConfig) { + propStr := strconv.Itoa(c.latestProposalNumber) + s.T().Logf("voting yes on proposal for chain-id: %s", c.meta.Id) + cmd := []string{"osmosisd", "tx", "gov", "vote", propStr, "yes", "--from=val", fmt.Sprintf("--chain-id=%s", c.meta.Id), "-b=block", "--yes", "--keyring-backend=test"} + for i := range c.validators { + if _, ok := c.skipRunValidatorIndexes[i]; ok { continue } - s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") - s.T().Logf("successfully voted yes on proposal from %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + s.ExecTx(c.meta.Id, i, cmd, "code: 0") + s.T().Logf("successfully voted yes on proposal from %s container: %s", s.valResources[c.meta.Id][i].Container.Name[1:], s.valResources[c.meta.Id][i].Container.ID) } } -func (s *IntegrationTestSuite) voteNoProposal(config *chainConfig, i int, from string) { - c := config.chain - propStr := strconv.Itoa(config.latestProposalNumber) - s.T().Logf("voting no on proposal for chain-id: %s", c.ChainMeta.Id) - cmd := []string{"osmosisd", "tx", "gov", "vote", propStr, "no", fmt.Sprintf("--from=%s", from), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "-b=block", "--yes", "--keyring-backend=test"} - s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") - s.T().Logf("successfully voted no for proposal from %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) +func (s *IntegrationTestSuite) voteNoProposal(c *chainConfig, i int, from string) { + propStr := strconv.Itoa(c.latestProposalNumber) + s.T().Logf("voting no on proposal for chain-id: %s", c.meta.Id) + cmd := []string{"osmosisd", "tx", "gov", "vote", propStr, "no", fmt.Sprintf("--from=%s", from), fmt.Sprintf("--chain-id=%s", c.meta.Id), "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(c.meta.Id, i, cmd, "code: 0") + s.T().Logf("successfully voted no for proposal from %s container: %s", s.valResources[c.meta.Id][i].Container.Name[1:], s.valResources[c.meta.Id][i].Container.ID) } -func (s *IntegrationTestSuite) chainStatus(c *chain.Chain, i int) []byte { +func (s *IntegrationTestSuite) chainStatus(c *chainConfig, i int) []byte { cmd := []string{"osmosisd", "status"} - _, errBuf, err := s.ExecTx(c.ChainMeta.Id, i, cmd, "") + _, errBuf, err := s.ExecTx(c.meta.Id, i, cmd, "") s.Require().NoError(err) return errBuf.Bytes() } -func (s *IntegrationTestSuite) getCurrentChainHeight(c *chain.Chain, i int) int { +func (s *IntegrationTestSuite) getCurrentChainHeight(c *chainConfig, i int) int { var block syncInfo s.Require().Eventually( func() bool { @@ -236,9 +230,9 @@ func (s *IntegrationTestSuite) getCurrentChainHeight(c *chain.Chain, i int) int return currentHeight } -func (s *IntegrationTestSuite) queryBalances(c *chain.Chain, i int, addr string) (sdk.Coins, error) { +func (s *IntegrationTestSuite) queryBalances(c *chainConfig, i int, addr string) (sdk.Coins, error) { cmd := []string{"osmosisd", "query", "bank", "balances", addr, "--output=json"} - outBuf, _, err := s.ExecTx(c.ChainMeta.Id, i, cmd, "") + outBuf, _, err := s.ExecTx(c.meta.Id, i, cmd, "") s.Require().NoError(err) var balancesResp banktypes.QueryAllBalancesResponse @@ -269,60 +263,57 @@ func (s *IntegrationTestSuite) queryPropTally(endpoint, addr string) (sdk.Int, s return noTotal, yesTotal, noWithVetoTotal, abstainTotal, nil } -func (s *IntegrationTestSuite) createPool(c *chain.Chain, poolFile string) { - s.T().Logf("creating pool for chain-id: %s", c.ChainMeta.Id) - cmd := []string{"osmosisd", "tx", "gamm", "create-pool", fmt.Sprintf("--pool-file=/osmosis/%s", poolFile), fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test"} - s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") - s.T().Logf("successfully created pool from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) +func (s *IntegrationTestSuite) createPool(c *chainConfig, poolFile string) { + s.T().Logf("creating pool for chain-id: %s", c.meta.Id) + cmd := []string{"osmosisd", "tx", "gamm", "create-pool", fmt.Sprintf("--pool-file=/osmosis/%s", poolFile), fmt.Sprintf("--chain-id=%s", c.meta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(c.meta.Id, 0, cmd, "code: 0") + s.T().Logf("successfully created pool from %s container: %s", s.valResources[c.meta.Id][0].Container.Name[1:], s.valResources[c.meta.Id][0].Container.ID) } func (s *IntegrationTestSuite) lockTokens(config *chainConfig, i int, tokens string, duration string, from string) { - c := config.chain - s.T().Logf("locking %s for %s on chain-id: %s", tokens, duration, c.ChainMeta.Id) - cmd := []string{"osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--duration=%s", duration), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} - s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") - s.T().Logf("successfully created lock %v from %s container: %s", config.latestLockNumber, s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) + s.T().Logf("locking %s for %s on chain-id: %s", tokens, duration, config.meta.Id) + cmd := []string{"osmosisd", "tx", "lockup", "lock-tokens", tokens, fmt.Sprintf("--chain-id=%s", config.meta.Id), fmt.Sprintf("--duration=%s", duration), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(config.meta.Id, i, cmd, "code: 0") + s.T().Logf("successfully created lock %v from %s container: %s", config.latestLockNumber, s.valResources[config.meta.Id][i].Container.Name[1:], s.valResources[config.meta.Id][i].Container.ID) config.latestLockNumber = config.latestLockNumber + 1 } func (s *IntegrationTestSuite) superfluidDelegate(config *chainConfig, valAddress string, from string) { - c := config.chain lockStr := strconv.Itoa(config.latestLockNumber) - s.T().Logf("superfluid delegating lock %s to %s on chain-id: %s", lockStr, valAddress, c.ChainMeta.Id) - cmd := []string{"osmosisd", "tx", "superfluid", "delegate", lockStr, valAddress, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} - s.ExecTx(c.ChainMeta.Id, 0, cmd, "code: 0") - s.T().Logf("successfully superfluid delegated from %s container: %s", s.valResources[c.ChainMeta.Id][0].Container.Name[1:], s.valResources[c.ChainMeta.Id][0].Container.ID) + s.T().Logf("superfluid delegating lock %s to %s on chain-id: %s", lockStr, valAddress, config.meta.Id) + cmd := []string{"osmosisd", "tx", "superfluid", "delegate", lockStr, valAddress, fmt.Sprintf("--chain-id=%s", config.meta.Id), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(config.meta.Id, 0, cmd, "code: 0") + s.T().Logf("successfully superfluid delegated from %s container: %s", s.valResources[config.meta.Id][0].Container.Name[1:], s.valResources[config.meta.Id][0].Container.ID) } -func (s *IntegrationTestSuite) sendTx(c *chain.Chain, i int, amount string, sendAddress string, receiveAddress string) { - s.T().Logf("sending %s from %s to %s on chain-id: %s", amount, sendAddress, receiveAddress, c.ChainMeta.Id) - cmd := []string{"osmosisd", "tx", "bank", "send", sendAddress, receiveAddress, amount, fmt.Sprintf("--chain-id=%s", c.ChainMeta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test"} - s.ExecTx(c.ChainMeta.Id, i, cmd, "code: 0") - s.T().Logf("successfully sent tx from %s container: %s", s.valResources[c.ChainMeta.Id][i].Container.Name[1:], s.valResources[c.ChainMeta.Id][i].Container.ID) +func (s *IntegrationTestSuite) sendTx(c *chainConfig, i int, amount string, sendAddress string, receiveAddress string) { + s.T().Logf("sending %s from %s to %s on chain-id: %s", amount, sendAddress, receiveAddress, c.meta.Id) + cmd := []string{"osmosisd", "tx", "bank", "send", sendAddress, receiveAddress, amount, fmt.Sprintf("--chain-id=%s", c.meta.Id), "--from=val", "-b=block", "--yes", "--keyring-backend=test"} + s.ExecTx(c.meta.Id, i, cmd, "code: 0") + s.T().Logf("successfully sent tx from %s container: %s", s.valResources[c.meta.Id][i].Container.Name[1:], s.valResources[c.meta.Id][i].Container.ID) } -func (s *IntegrationTestSuite) extractValidatorOperatorAddresses(chainConfig *chainConfig) { - chain := chainConfig.chain +func (s *IntegrationTestSuite) extractValidatorOperatorAddresses(config *chainConfig) { - for i, val := range chain.Validators { - if _, ok := chainConfig.skipRunValidatorIndexes[i]; ok { - s.T().Logf("skipping %s validator with index %d from running...", val.Name, i) + for i, val := range config.validators { + if _, ok := config.skipRunValidatorIndexes[i]; ok { + s.T().Logf("skipping %s validator with index %d from running...", val.validator.Name, i) continue } - cmd := []string{"osmosisd", "debug", "addr", val.PublicKey} - s.T().Logf("extracting validator operator addresses for chain-id: %s", chain.ChainMeta.Id) - _, errBuf, err := s.ExecTx(chain.ChainMeta.Id, i, cmd, "") + cmd := []string{"osmosisd", "debug", "addr", val.validator.PublicKey} + s.T().Logf("extracting validator operator addresses for chain-id: %s", config.meta.Id) + _, errBuf, err := s.ExecTx(config.meta.Id, i, cmd, "") s.Require().NoError(err) re := regexp.MustCompile("osmovaloper(.{39})") operAddr := fmt.Sprintf("%s\n", re.FindString(errBuf.String())) - val.OperAddress = strings.TrimSuffix(operAddr, "\n") + config.validators[i].operatorAddress = strings.TrimSuffix(operAddr, "\n") } } -func (s *IntegrationTestSuite) queryIntermediaryAccount(c *chain.Chain, endpoint string, denom string, valAddr string) (int, error) { +func (s *IntegrationTestSuite) queryIntermediaryAccount(c *chainConfig, endpoint string, denom string, valAddr string) (int, error) { intAccount := superfluidtypes.GetSuperfluidIntermediaryAccountAddr(denom, valAddr) path := fmt.Sprintf( "%s/cosmos/staking/v1beta1/validators/%s/delegations/%s", @@ -342,9 +333,9 @@ func (s *IntegrationTestSuite) queryIntermediaryAccount(c *chain.Chain, endpoint } -func (s *IntegrationTestSuite) createWallet(c *chain.Chain, index int, walletName string) string { +func (s *IntegrationTestSuite) createWallet(c *chainConfig, index int, walletName string) string { cmd := []string{"osmosisd", "keys", "add", walletName, "--keyring-backend=test"} - outBuf, _, err := s.ExecTx(c.ChainMeta.Id, index, cmd, "") + outBuf, _, err := s.ExecTx(c.meta.Id, index, cmd, "") s.Require().NoError(err) re := regexp.MustCompile("osmo1(.{38})") walletAddr := fmt.Sprintf("%s\n", re.FindString(outBuf.String()))