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

refactor: implement Dockerized chain initialization in e2e tests #1330

Merged
merged 9 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ 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 @@ -241,6 +245,9 @@ benchmark:
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 .

###############################################################################
### Linting ###
###############################################################################
Expand Down
62 changes: 60 additions & 2 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# End-to-end Tests

The package e2e defines an integration testing suite used for full end-to-end
testing functionality.
# Structure

## `e2e` Package

The `e2e` package defines an integration testing suite used for full end-to-end
testing functionality. This package is decoupled from depending on the Osmosis codebase.
It initializes the chains for testing via Docker files. As a result, the test suite may
provide the desired Osmosis version to Docker containers during the initialization.
This design allows for the opportunity of testing chain upgrades in the future by providing
an older Osmosis version to the container, performing the chain upgrade, and running the latest test suite.

The file e2e_suite_test.go defines the testing suite and contains the core
bootstrapping logic that creates a testing environment via Docker containers.
Expand All @@ -11,3 +19,53 @@ The file e2e_test.go contains the actual end-to-end integration tests that
utilize the testing suite.

Currently, there is a single test in `e2e_test.go` to query the balances of a validator.

## `chain` Package

The `chain` 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.

## `upgrade` Package

The `upgrade` package starts chain initialization. In addition, there is a Dockerfile `init-e2e.Dockerfile`.
When executed, its container produces all files necessary for starting up a new chain.
These resulting files can be mounted on a volume and propagated to our production osmosis container to start the `osmosisd` service.

The decoupling between chain initialization and start-up allows to minimize the differences between our test suite and the production environment.

# Running Locally

##### To build the binary that initializes the chain:

```
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`):

```
make docker-build-e2e-chain-init
```

##### To run the chain initialization container locally:

```
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:
```
docker run -v /home/roman/cosmos/osmosis/tmp:/tmp/osmo-test osmosis-e2e-chain-init:debug --data-dir=/tmp/osmo-test
```

##### To build the debug Osmosis image:

```
make docker-build-e2e-debug
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved
```
10 changes: 2 additions & 8 deletions tests/e2e/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package chain

import (
"fmt"
"io/ioutil"
)

const (
Expand All @@ -16,15 +15,10 @@ type Chain struct {
Validators []*Validator
}

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

func new(id, dataDir string) (*Chain, error) {
return &Chain{
Id: id,
DataDir: tmpDir,
DataDir: dataDir,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/chain/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package chain

func Init(id string) (*Chain, error) {
chain, err := new(id)
func Init(id, dataDir string) (*Chain, error) {
chain, err := new(id, dataDir)
if err != nil {
return nil, err
}
Expand Down
23 changes: 23 additions & 0 deletions tests/e2e/chain_init/chain-init.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# syntax=docker/dockerfile:1

## Build Image
FROM golang:1.18-bullseye as build

WORKDIR /osmosis
COPY . /osmosis

# From https://github.com/CosmWasm/wasmd/blob/master/Dockerfile
# For more details see https://github.com/CosmWasm/wasmvm#builds-of-libwasmvm
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0-beta7/libwasmvm_muslc.a /lib/libwasmvm_muslc.a
RUN sha256sum /lib/libwasmvm_muslc.a | grep d0152067a5609bfdfb3f0d5d6c0f2760f79d5f2cd7fd8513cafa9932d22eb350
RUN BUILD_TAGS=muslc make build-e2e-chain-init

## Deploy image
FROM ubuntu
Copy link
Member Author

@p0mvn p0mvn Apr 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose changing this to distroless once the development of the entire upgrade functionality is complete. I find ubuntu to be the easiest one to debug on

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, that's fine for now.


COPY --from=build /osmosis/build/chain_init /bin/chain_init

ENV HOME /osmosis
WORKDIR $HOME

ENTRYPOINT [ "chain_init" ]
29 changes: 29 additions & 0 deletions tests/e2e/chain_init/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"flag"
"fmt"
"os"

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

func main() {
var dataDir string
flag.StringVar(&dataDir, "data-dir", "", "chain data directory")
flag.Parse()

if len(dataDir) == 0 {
panic("data-dir is required")
}

if err := os.MkdirAll(dataDir, 0o755); err != nil {
panic(err)
}

chain, err := chain.Init(chain.ChainAID, dataDir)
if err != nil {
panic(err)
}
fmt.Println(chain)
}
4 changes: 3 additions & 1 deletion tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ func (s *IntegrationTestSuite) runIBCRelayer() {

func (s *IntegrationTestSuite) configureChain(chainId string) {
s.T().Logf("starting e2e infrastructure for chain-id: %s", chainId)
newChain, err := chain.Init(chainId)
tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-")
s.Require().NoError(err)
newChain, err := chain.Init(chainId, tmpDir)
s.chains = append(s.chains, newChain)
s.Require().NoError(err)
}
Expand Down