diff --git a/Makefile b/Makefile index 5be2f5454a9..83491d806b9 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 ### ############################################################################### diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 846d854bdd4..a3de35e60dd 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -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. @@ -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 +``` diff --git a/tests/e2e/chain/chain.go b/tests/e2e/chain/chain.go index b43bbbf5ce9..0a4e0d3f4f3 100644 --- a/tests/e2e/chain/chain.go +++ b/tests/e2e/chain/chain.go @@ -2,7 +2,6 @@ package chain import ( "fmt" - "io/ioutil" ) const ( @@ -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 } diff --git a/tests/e2e/chain/main.go b/tests/e2e/chain/main.go index 3f9a341d638..20453d7186d 100644 --- a/tests/e2e/chain/main.go +++ b/tests/e2e/chain/main.go @@ -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 } diff --git a/tests/e2e/chain_init/chain-init.Dockerfile b/tests/e2e/chain_init/chain-init.Dockerfile new file mode 100644 index 00000000000..91e5346b0df --- /dev/null +++ b/tests/e2e/chain_init/chain-init.Dockerfile @@ -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 --from=build /osmosis/build/chain_init /bin/chain_init + +ENV HOME /osmosis +WORKDIR $HOME + +ENTRYPOINT [ "chain_init" ] diff --git a/tests/e2e/chain_init/main.go b/tests/e2e/chain_init/main.go new file mode 100644 index 00000000000..edb26b0c199 --- /dev/null +++ b/tests/e2e/chain_init/main.go @@ -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) +} diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index 2885c31a330..b3f8988df21 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -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) }