Skip to content

Commit

Permalink
improve abstractions for chain initialization and add README
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Apr 22, 2022
1 parent dabb683 commit cf0d8a3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ build-contract-tests-hooks:
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./cmd/contract_tests

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

go-mod-cache: go.sum
@echo "--> Download go modules to local cache"
Expand Down Expand Up @@ -245,8 +245,8 @@ benchmark:
docker-build-debug:
@docker build -t osmosis:debug --build-arg BASE_IMG_TAG=debug -f Dockerfile .

docker-build-e2e-init:
@docker build -t osmosis-e2e:debug --build-arg BASE_IMG_TAG=debug -f tests/e2e//upgrade/init-e2e.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
53 changes: 51 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 for 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,44 @@ 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.tool. 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 bringing our test suite as close to the production environment as possible.

# 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:

```
docker run osmosis-e2e-chain-init:debug --data-dir=/tmp/osmo-test
```
- `--data-dir` flag is needed for outputting the files into a directory inside the container

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

```
make docker-build-e2e-debug
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ COPY . /osmosis
# 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-upgrade
RUN BUILD_TAGS=muslc make build-e2e-chain-init

## Deploy image
FROM ubuntu

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

ENV HOME /osmosis
WORKDIR $HOME

ENTRYPOINT [ "upgrade" ]
ENTRYPOINT [ "chain_init" ]
7 changes: 3 additions & 4 deletions tests/e2e/upgrade/main.go → tests/e2e/chain_init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"

"github.com/osmosis-labs/osmosis/v7/tests/e2e/chain"
)
Expand All @@ -17,12 +17,11 @@ func main() {
panic("data-dir is required")
}

tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-")
if err != nil {
if err := os.MkdirAll(dataDir, 0o755); err != nil {
panic(err)
}

chain, err := chain.Init(chain.ChainAID, tmpDir)
chain, err := chain.Init(chain.ChainAID, dataDir)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit cf0d8a3

Please sign in to comment.