Skip to content

Commit

Permalink
begin modularizing e2e test in preparation for upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Apr 19, 2022
1 parent 4e12c8e commit a1e8fa7
Show file tree
Hide file tree
Showing 13 changed files with 525 additions and 497 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/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/common"
)

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, common.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 := common.Cdc.Unmarshal(txBytes, &raw); err != nil {
return nil, err
}

var body sdktx.TxBody
if err := cdc.Unmarshal(raw.BodyBytes, &body); err != nil {
if err := common.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, common.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 := common.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 a1e8fa7

Please sign in to comment.