Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: refactor initialization with single node logic #1963

Merged
merged 6 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ docker-build-debug:
docker-build-e2e-init-chain:
@docker build -t osmosis-e2e-init-chain:debug --build-arg E2E_SCRIPT_NAME=chain -f tests/e2e/initialization/init.Dockerfile .

docker-build-e2e-init-node:
@docker build -t osmosis-e2e-init-node:debug --build-arg E2E_SCRIPT_NAME=node -f tests/e2e/initialization/init.Dockerfile .

###############################################################################
### Linting ###
###############################################################################
Expand Down
36 changes: 25 additions & 11 deletions tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type syncInfo struct {
}

type validatorConfig struct {
validator initialization.Validator
validator initialization.Node
operatorAddress string
}

Expand Down Expand Up @@ -76,57 +76,71 @@ const (

var (
// whatever number of validator configs get posted here are how many validators that will spawn on chain A and B respectively
validatorConfigsChainA = []*initialization.ValidatorConfig{
validatorConfigsChainA = []*initialization.NodeConfig{
{
Name: "prune-default-snapshot",
Pruning: "default",
PruningKeepRecent: "0",
PruningInterval: "0",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: true,
},
{
Name: "prune-nothing-snapshot",
Pruning: "nothing",
PruningKeepRecent: "0",
PruningInterval: "0",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: true,
},
{
Name: "prune-custom-10000-13-snapshot",
Pruning: "custom",
PruningKeepRecent: "10000",
PruningInterval: "13",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: true,
},
{
Name: "prune-everything-no-snapshot",
Pruning: "everything",
PruningKeepRecent: "0",
PruningInterval: "0",
SnapshotInterval: 0,
SnapshotKeepRecent: 0,
IsValidator: true,
},
}
validatorConfigsChainB = []*initialization.ValidatorConfig{
validatorConfigsChainB = []*initialization.NodeConfig{
{
Name: "prune-default-snapshot",
Pruning: "default",
PruningKeepRecent: "0",
PruningInterval: "0",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: true,
},
{
Name: "prune-nothing-snapshot",
Pruning: "nothing",
PruningKeepRecent: "0",
PruningInterval: "0",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: true,
},
{
Name: "prune-custom-snapshot",
Pruning: "custom",
PruningKeepRecent: "10000",
PruningInterval: "13",
SnapshotInterval: 1500,
SnapshotKeepRecent: 2,
IsValidator: true,
},
}
)
Expand Down Expand Up @@ -363,7 +377,7 @@ func (s *IntegrationTestSuite) runIBCRelayer(chainA *chainConfig, chainB *chainC
s.connectIBCChains(chainA, chainB)
}

func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs []*initialization.ValidatorConfig, skipValidatorIndexes map[int]struct{}) {
func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs []*initialization.NodeConfig, skipValidatorIndexes map[int]struct{}) {
s.T().Logf("starting e2e infrastructure for chain-id: %s", chainId)
tmpDir, err := os.MkdirTemp("", "osmosis-e2e-testnet-")

Expand All @@ -384,7 +398,7 @@ func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs [
// via Docker.

if s.skipUpgrade {
initializedChain, err := initialization.Init(chainId, tmpDir, validatorConfigs, time.Duration(newChainConfig.votingPeriod), s.forkHeight)
initializedChain, err := initialization.InitChain(chainId, tmpDir, validatorConfigs, time.Duration(newChainConfig.votingPeriod), s.forkHeight)
s.Require().NoError(err)
s.initializeChainConfig(&newChainConfig, initializedChain)
return
Expand Down Expand Up @@ -428,8 +442,8 @@ func (s *IntegrationTestSuite) initializeChainConfig(chainConfig *chainConfig, i
chainConfig.meta.DataDir = initializedChain.ChainMeta.DataDir
chainConfig.meta.Id = initializedChain.ChainMeta.Id

chainConfig.validators = make([]*validatorConfig, 0, len(initializedChain.Validators))
for _, val := range initializedChain.Validators {
chainConfig.validators = make([]*validatorConfig, 0, len(initializedChain.Nodes))
for _, val := range initializedChain.Nodes {
chainConfig.validators = append(chainConfig.validators, &validatorConfig{validator: *val})
}

Expand Down Expand Up @@ -569,8 +583,8 @@ func (s *IntegrationTestSuite) createPreUpgradeState() {
s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, initialization.OsmoToken)
s.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, initialization.StakeToken)
s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, initialization.StakeToken)
s.createPool(chainA, "pool1A.json")
s.createPool(chainB, "pool1B.json")
s.createPool(chainA, "pool1A.json", initialization.ValidatorWalletName)
s.createPool(chainB, "pool1B.json", initialization.ValidatorWalletName)
}

func (s *IntegrationTestSuite) runPostUpgradeTests() {
Expand All @@ -585,6 +599,6 @@ func (s *IntegrationTestSuite) runPostUpgradeTests() {
s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, initialization.OsmoToken)
s.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, initialization.StakeToken)
s.sendIBC(chainB, chainA, chainA.validators[0].validator.PublicAddress, initialization.StakeToken)
s.createPool(chainA, "pool2A.json")
s.createPool(chainB, "pool2B.json")
s.createPool(chainA, "pool2A.json", initialization.ValidatorWalletName)
s.createPool(chainB, "pool2B.json", initialization.ValidatorWalletName)
}
9 changes: 5 additions & 4 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,25 @@ func (s *IntegrationTestSuite) TestSuperfluidVoting() {
// TODO: https://github.com/osmosis-labs/osmosis/issues/1843
s.T().Skip("Superfluid tests are broken when upgrade is skipped. To be fixed in #1843")
}
const walletName = "superfluid-wallet"

chainA := s.chainConfigs[0]
s.submitSuperfluidProposal(chainA, "gamm/pool/1")
s.depositProposal(chainA)
s.voteProposal(chainA)
walletAddr := s.createWallet(chainA, 0, "wallet")
walletAddr := s.createWallet(chainA, 0, walletName)
// send gamm tokens to validator's other wallet (non self-delegation wallet)
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")
s.lockTokens(chainA, 0, "100000000000000000000gamm/pool/1", "240s", walletName)
// superfluid delegate from validator 0 non self-delegation wallet to validator 1 on chain A
s.superfluidDelegate(chainA, chainA.validators[1].operatorAddress, "wallet")
s.superfluidDelegate(chainA, chainA.validators[1].operatorAddress, walletName)
// 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")
s.voteNoProposal(chainA, 0, walletName)

hostPort, err := s.containerManager.GetValidatorHostPort(chainA.meta.Id, 0, "1317/tcp")
s.Require().NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/e2e_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ func (s *IntegrationTestSuite) queryPropTally(endpoint, addr string) (sdk.Int, s
return noTotal, yesTotal, noWithVetoTotal, abstainTotal, nil
}

func (s *IntegrationTestSuite) createPool(c *chainConfig, poolFile string) {
func (s *IntegrationTestSuite) createPool(c *chainConfig, poolFile string, from 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"}
cmd := []string{"osmosisd", "tx", "gamm", "create-pool", fmt.Sprintf("--pool-file=/osmosis/%s", poolFile), fmt.Sprintf("--chain-id=%s", c.meta.Id), fmt.Sprintf("--from=%s", from), "-b=block", "--yes", "--keyring-backend=test"}
_, _, err := s.containerManager.ExecCmd(s.T(), c.meta.Id, 0, cmd, "code: 0")
s.Require().NoError(err)
validatorResource, exists := s.containerManager.GetValidatorResource(c.meta.Id, 0)
Expand Down
52 changes: 7 additions & 45 deletions tests/e2e/initialization/chain.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package initialization

import (
"fmt"
)

const (
keyringPassphrase = "testpassphrase"
keyringAppName = "testnet"
Expand All @@ -12,8 +8,8 @@ const (
// internalChain contains the same info as chain, but with the validator structs instead using the internal validator
// representation, with more derived data
type internalChain struct {
chainMeta ChainMeta
validators []*internalValidator
chainMeta ChainMeta
nodes []*internalNode
}

func new(id, dataDir string) (*internalChain, error) {
Expand All @@ -26,48 +22,14 @@ func new(id, dataDir string) (*internalChain, error) {
}, nil
}

func (c *internalChain) createAndInitValidators(count int) error {
for i := 0; i < count; i++ {
node := c.createValidator(i)

// generate genesis files
if err := node.init(); err != nil {
return err
}

c.validators = append(c.validators, node)

// create keys
if err := node.createKey("val"); err != nil {
return err
}
if err := node.createNodeKey(); err != nil {
return err
}
if err := node.createConsensusKey(); err != nil {
return err
}
}

return nil
}

func (c *internalChain) createValidator(index int) *internalValidator {
return &internalValidator{
chain: c,
index: index,
moniker: fmt.Sprintf("%s-osmosis-%d", c.chainMeta.Id, index),
}
}

func (c *internalChain) export() *Chain {
exportValidators := make([]*Validator, 0, len(c.validators))
for _, v := range c.validators {
exportValidators = append(exportValidators, v.export())
exportNodes := make([]*Node, 0, len(c.nodes))
for _, v := range c.nodes {
exportNodes = append(exportNodes, v.export())
}

return &Chain{
ChainMeta: c.chainMeta,
Validators: exportValidators,
ChainMeta: c.chainMeta,
Nodes: exportNodes,
}
}
4 changes: 2 additions & 2 deletions tests/e2e/initialization/chain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func main() {
var (
valConfig []*initialization.ValidatorConfig
valConfig []*initialization.NodeConfig
dataDir string
chainId string
config string
Expand Down Expand Up @@ -41,7 +41,7 @@ func main() {
panic(err)
}

createdChain, err := initialization.Init(chainId, dataDir, valConfig, votingPeriod, forkHeight)
createdChain, err := initialization.InitChain(chainId, dataDir, valConfig, votingPeriod, forkHeight)
if err != nil {
panic(err)
}
Expand Down
Loading