Skip to content

Commit

Permalink
e2e: refactor initialization with single node logic (backport #1963) (#…
Browse files Browse the repository at this point in the history
…1975)

* e2e: refactor initialization with single node logic

* lint and remove redundant getters from node

* restore accidental change

* rename init to InitChain

* persistentPeers typo
  • Loading branch information
p0mvn authored Jul 5, 2022
1 parent 2b58b48 commit f2f590a
Show file tree
Hide file tree
Showing 13 changed files with 537 additions and 297 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,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 @@ -34,7 +34,7 @@ type syncInfo struct {
}

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

Expand Down Expand Up @@ -70,57 +70,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 @@ -252,7 +266,7 @@ func (s *IntegrationTestSuite) runValidators(chainConfig *chainConfig, dockerRep
}

// expose the first validator for debugging and communication
if val.validator.Index == 0 {
if i == 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)}},
Expand Down Expand Up @@ -395,7 +409,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 := ioutil.TempDir("", "osmosis-e2e-testnet-")

Expand Down Expand Up @@ -461,8 +475,8 @@ func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs [
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 = make([]*validatorConfig, 0, len(initializedChain.Nodes))
for _, val := range initializedChain.Nodes {
newChainConfig.validators = append(newChainConfig.validators, &validatorConfig{validator: *val})
}

Expand Down Expand Up @@ -612,8 +626,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 @@ -624,6 +638,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 @@ -17,23 +17,24 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
}

func (s *IntegrationTestSuite) TestSuperfluidVoting() {
const walletName = "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)

chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[chainA.meta.Id][0].GetHostPort("1317/tcp"))
sfProposalNumber := strconv.Itoa(chainA.latestProposalNumber)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ 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"}
s.ExecTx(c.meta.Id, 0, cmd, "code: 0")
Expand Down
79 changes: 7 additions & 72 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,75 +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) createAndInitValidatorsWithMnemonics(count int, mnemonics []string) error {
for i := 0; i < count; i++ {
// create node
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.createKeyFromMnemonic("val", mnemonics[i]); 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

0 comments on commit f2f590a

Please sign in to comment.