Skip to content

Commit

Permalink
refactor: begin modularizing e2e tests in preparation for upgrade (#1293
Browse files Browse the repository at this point in the history
)

* begin modularizing e2e test in preparation for upgrade

* rename common package to util

* move chain related constants from util to chain package

* fix genesis.go

* exctract initNodes into the genesis package

* remove genesis package, move all logic to chain

* continue cleaning up chain package and refactoring e2e

* store chains in a slice

* reuse common cdc from util package

* lexicographical reorder of functions in config.go of chain package

* clean up names
  • Loading branch information
p0mvn committed Apr 24, 2022
1 parent c448549 commit 6b6d5b5
Show file tree
Hide file tree
Showing 14 changed files with 672 additions and 622 deletions.
125 changes: 0 additions & 125 deletions tests/e2e/chain.go

This file was deleted.

94 changes: 94 additions & 0 deletions tests/e2e/chain/chain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package chain

import (
"fmt"
"io/ioutil"
)

const (
keyringPassphrase = "testpassphrase"
keyringAppName = "testnet"
)

type Chain struct {
DataDir string
Id string
Validators []*Validator
}

func new(id string) (*Chain, error) {
tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-")
if err != nil {
return nil, err
}

return &Chain{
Id: id,
DataDir: tmpDir,
}, nil
}

func (c *Chain) configDir() string {
return fmt.Sprintf("%s/%s", c.DataDir, c.Id)
}

func (c *Chain) 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 *Chain) 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 *Chain) createValidator(index int) *Validator {
return &Validator{
chain: c,
index: index,
moniker: fmt.Sprintf("%s-osmosis-%d", c.Id, index),
}
}
14 changes: 8 additions & 6 deletions tests/e2e/util.go → tests/e2e/chain/chain_util.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
package e2e
package chain

import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec/unknownproto"
sdktx "github.com/cosmos/cosmos-sdk/types/tx"

"github.com/osmosis-labs/osmosis/v7/tests/e2e/util"
)

func decodeTx(txBytes []byte) (*sdktx.Tx, error) {
var raw sdktx.TxRaw

// reject all unknown proto fields in the root TxRaw
err := unknownproto.RejectUnknownFieldsStrict(txBytes, &raw, encodingConfig.InterfaceRegistry)
err := unknownproto.RejectUnknownFieldsStrict(txBytes, &raw, util.EncodingConfig.InterfaceRegistry)
if err != nil {
return nil, fmt.Errorf("failed to reject unknown fields: %w", err)
}

if err := cdc.Unmarshal(txBytes, &raw); err != nil {
if err := util.Cdc.Unmarshal(txBytes, &raw); err != nil {
return nil, err
}

var body sdktx.TxBody
if err := cdc.Unmarshal(raw.BodyBytes, &body); err != nil {
if err := util.Cdc.Unmarshal(raw.BodyBytes, &body); err != nil {
return nil, fmt.Errorf("failed to decode tx: %w", err)
}

var authInfo sdktx.AuthInfo

// reject all unknown proto fields in AuthInfo
err = unknownproto.RejectUnknownFieldsStrict(raw.AuthInfoBytes, &authInfo, encodingConfig.InterfaceRegistry)
err = unknownproto.RejectUnknownFieldsStrict(raw.AuthInfoBytes, &authInfo, util.EncodingConfig.InterfaceRegistry)
if err != nil {
return nil, fmt.Errorf("failed to reject unknown fields: %w", err)
}

if err := cdc.Unmarshal(raw.AuthInfoBytes, &authInfo); err != nil {
if err := util.Cdc.Unmarshal(raw.AuthInfoBytes, &authInfo); err != nil {
return nil, fmt.Errorf("failed to decode auth info: %w", err)
}

Expand Down
Loading

0 comments on commit 6b6d5b5

Please sign in to comment.