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: chain initialization refactor for extensibility #1898

Merged
merged 10 commits into from
Jun 30, 2022
Merged
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ build-contract-tests-hooks:
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./cmd/contract_tests

build-e2e-chain-init:
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./tests/e2e/chain_init

go-mod-cache: go.sum
@echo "--> Download go modules to local cache"
@go mod download
Expand Down Expand Up @@ -245,11 +241,15 @@ test-e2e-skip-upgrade:
benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_UNIT)

build-e2e-script:
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./tests/e2e/initialization/$(E2E_SCRIPT_NAME)

docker-build-debug:
@docker build -t osmosis:debug --build-arg BASE_IMG_TAG=debug -f Dockerfile .

docker-build-e2e-chain-init:
@docker build -t osmosis-e2e-chain-init:debug -f tests/e2e/chain_init/chain-init.Dockerfile .
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 .

###############################################################################
### Linting ###
Expand Down
47 changes: 7 additions & 40 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ that utilize the testing suite.
Currently, there is a single test in `e2e_test.go` to query the balances
of a validator.

## `chain` Package
## `initialization` Package

The `chain` package introduces the logic necessary for initializing a
The `initialization` package introduces the logic necessary for initializing a
chain by creating a genesis file and all required configuration files
such as the `app.toml`. This package directly depends on the Osmosis
codebase.
Expand All @@ -58,48 +58,13 @@ in the `chain` package.

## Running Locally

### To build the binary that initializes the chain
### To build chain initialization image

make build-e2e-chain-init

- The produced binary is an entrypoint to the
`osmosis-e2e-chain-init:debug` image.

### To build the image for initializing the chain (`osmosis-e2e-chain-init:debug`)

<!-- markdownlint-disable MD046 -->
```sh
make docker-build-e2e-chain-init
```

### To run the chain initialization container locally

```sh
mkdir < path >
docker run -v < path >:/tmp/osmo-test osmosis-e2e-chain-init:debug --data-dir=/tmp/osmo-test
sudo rm -r < path > # must be root to clean up
```

- runs a container with a volume mounted at \< path \> where all chain
initialization files are placed.
- \< path \> must be absolute.
- `--data-dir` flag is needed for outputting the files into a
directory inside the container

Example:

<!-- markdownlint-disable MD046 -->
```sh
docker run\
-v /home/roman/cosmos/osmosis/tmp:/tmp/osmo-test \
osmosis-e2e-chain-init:debug \
--data-dir=/tmp/

osmo-test
```
Please refer to `tests/e2e/initialization/README.md`

### To build the debug Osmosis image

```sh
make docker-build-e2e-debug

### Environment variables
Expand Down Expand Up @@ -144,6 +109,8 @@ This debug configuration helps to run e2e tests locally and skip the desired tes
"OSMOSIS_E2E_SKIP_IBC": "true",
"OSMOSIS_E2E_SKIP_UPGRADE": "true",
"OSMOSIS_E2E_SKIP_CLEANUP": "true",
"OSMOSIS_E2E_UPGRADE_VERSION": "v10",
"OSMOSIS_E2E_FORK_HEIGHT": "4713065" # this is v10 fork height.
}
}
```
2 changes: 1 addition & 1 deletion tests/e2e/containers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
previousVersionOsmoTag = "v10.0.0-debug"
// Pre-upgrade repo/tag for osmosis initialization (this should be one version below upgradeVersion)
previousVersionInitRepository = "osmolabs/osmosis-e2e-init-chain"
previousVersionInitTag = "v10.0.0"
previousVersionInitTag = "v10.0.0-e2e-v1"
// Hermes repo/version for relayer
relayerRepository = "osmolabs/hermes"
relayerTag = "0.13.0"
Expand Down
13 changes: 13 additions & 0 deletions tests/e2e/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"os"
"regexp"
"strings"
"testing"
"time"
Expand All @@ -25,6 +26,8 @@ type Manager struct {
valResources map[string][]*dockertest.Resource
}

var errRegex = regexp.MustCompile(`(E|e)rror`)

// NewManager creates a new Manager instance and initializes
// all Docker specific utilies. Returns an error if initialiation fails.
func NewManager(isUpgrade bool, isFork bool) (docker *Manager, err error) {
Expand Down Expand Up @@ -88,6 +91,16 @@ func (m *Manager) ExecCmd(t *testing.T, chainId string, validatorIndex int, comm
return false
}

errBufString := errBuf.String()

// Note that this does not match all errors.
// This only works if CLI outpurs "Error" or "error"
// to stderr.
if errRegex.MatchString(errBufString) {
t.Log(errBufString)
return false
}

p0mvn marked this conversation as resolved.
Show resolved Hide resolved
if success != "" {
return strings.Contains(outBuf.String(), success) || strings.Contains(errBuf.String(), success)
}
Expand Down
42 changes: 23 additions & 19 deletions tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

rpchttp "github.com/tendermint/tendermint/rpc/client/http"

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

Expand All @@ -33,7 +33,7 @@ type syncInfo struct {
}

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

Expand All @@ -49,7 +49,7 @@ type chainConfig struct {
skipRunValidatorIndexes map[int]struct{}
latestProposalNumber int
latestLockNumber int
meta chain.ChainMeta
meta initialization.ChainMeta
validators []*validatorConfig
}

Expand Down Expand Up @@ -80,7 +80,7 @@ const (

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{
validatorConfigsChainA = []*initialization.ValidatorConfig{
{
Pruning: "default",
PruningKeepRecent: "0",
Expand Down Expand Up @@ -110,7 +110,7 @@ var (
SnapshotKeepRecent: 0,
},
}
validatorConfigsChainB = []*chain.ValidatorConfig{
validatorConfigsChainB = []*initialization.ValidatorConfig{
{
Pruning: "default",
PruningKeepRecent: "0",
Expand Down Expand Up @@ -208,13 +208,13 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.containerManager, err = containers.NewManager(!s.skipUpgrade, s.isFork)
require.NoError(s.T(), err)

s.configureChain(chain.ChainAID, validatorConfigsChainA, map[int]struct{}{
s.configureChain(initialization.ChainAID, validatorConfigsChainA, map[int]struct{}{
3: {}, // skip validator at index 3
})

// We don't need a second chain if IBC is disabled
if !s.skipIBC {
s.configureChain(chain.ChainBID, validatorConfigsChainB, map[int]struct{}{})
s.configureChain(initialization.ChainBID, validatorConfigsChainB, map[int]struct{}{})
}

for i, chainConfig := range s.chainConfigs {
Expand Down Expand Up @@ -375,7 +375,7 @@ func (s *IntegrationTestSuite) runIBCRelayer(chainA *chainConfig, chainB *chainC
s.connectIBCChains(chainA, chainB)
}

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

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

if s.skipUpgrade {
initializedChain, err := chain.Init(chainId, tmpDir, validatorConfigs, time.Duration(newChainConfig.votingPeriod), s.forkHeight)
initializedChain, err := initialization.Init(chainId, tmpDir, validatorConfigs, time.Duration(newChainConfig.votingPeriod), s.forkHeight)
s.Require().NoError(err)
s.initializeChainConfig(&newChainConfig, initializedChain)
return
Expand All @@ -412,7 +412,7 @@ 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
var initializedChain initialization.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++ {
Expand All @@ -437,7 +437,7 @@ func (s *IntegrationTestSuite) configureChain(chainId string, validatorConfigs [
s.initializeChainConfig(&newChainConfig, &initializedChain)
}

func (s *IntegrationTestSuite) initializeChainConfig(chainConfig *chainConfig, initializedChain *chain.Chain) {
func (s *IntegrationTestSuite) initializeChainConfig(chainConfig *chainConfig, initializedChain *initialization.Chain) {
chainConfig.meta.DataDir = initializedChain.ChainMeta.DataDir
chainConfig.meta.Id = initializedChain.ChainMeta.Id

Expand Down Expand Up @@ -598,22 +598,26 @@ func (s *IntegrationTestSuite) createPreUpgradeState() {
chainA := s.chainConfigs[0]
chainB := s.chainConfigs[1]

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.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, initialization.OsmoToken)
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")
}

func (s *IntegrationTestSuite) runPostUpgradeTests() {
if s.skipIBC {
return
}

chainA := s.chainConfigs[0]
chainB := s.chainConfigs[1]

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.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, initialization.OsmoToken)
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")
}
4 changes: 2 additions & 2 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"time"

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

func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
Expand All @@ -17,7 +17,7 @@ func (s *IntegrationTestSuite) TestIBCTokenTransfer() {
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].validator.PublicAddress, chain.OsmoToken)
s.sendIBC(chainA, chainB, chainB.validators[0].validator.PublicAddress, initialization.OsmoToken)
}

func (s *IntegrationTestSuite) TestSuperfluidVoting() {
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 @@ -17,7 +17,7 @@ import (

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/initialization"
"github.com/osmosis-labs/osmosis/v7/tests/e2e/util"
)

Expand Down Expand Up @@ -77,7 +77,7 @@ func (s *IntegrationTestSuite) sendIBC(srcChain *chainConfig, dstChain *chainCon
if ibcCoin.Len() == 1 {
tokenPre := balancesBPre.AmountOfNoDenomValidation(ibcCoin[0].Denom)
tokenPost := balancesBPost.AmountOfNoDenomValidation(ibcCoin[0].Denom)
resPre := chain.OsmoToken.Amount
resPre := initialization.OsmoToken.Amount
resPost := tokenPost.Sub(tokenPre)
return resPost.Uint64() == resPre.Uint64()
} else {
Expand Down
Loading