From 528ecde30043d69654b81f1b776763c1a446c521 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 22 Apr 2022 16:12:21 -0400 Subject: [PATCH 1/9] pull chain temp folder creation our of chain to e2e package --- tests/e2e/chain/chain.go | 10 ++-------- tests/e2e/chain/main.go | 5 +++-- tests/e2e/e2e_setup_test.go | 4 +++- 3 files changed, 8 insertions(+), 11 deletions(-) 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..c789e6e2dc3 100644 --- a/tests/e2e/chain/main.go +++ b/tests/e2e/chain/main.go @@ -1,7 +1,8 @@ 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/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) } From 9371b3a3f9e9d62a31f15592c9f927ac2105c5a8 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 22 Apr 2022 16:12:59 -0400 Subject: [PATCH 2/9] create image and makefile steps to initialize chain state --- Makefile | 7 +++++++ tests/e2e/upgrade/init-e2e.Dockerfile | 23 +++++++++++++++++++++++ tests/e2e/upgrade/main.go | 21 +++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/e2e/upgrade/init-e2e.Dockerfile create mode 100644 tests/e2e/upgrade/main.go diff --git a/Makefile b/Makefile index 5be2f5454a9..7cdbd3c31f6 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-upgrade: + mkdir -p $(BUILDDIR) + go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./tests/e2e/upgrade + 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-init: + @docker build -t osmosis-e2e:debug --build-arg BASE_IMG_TAG=debug -f tests/e2e//upgrade/init-e2e.Dockerfile . + ############################################################################### ### Linting ### ############################################################################### diff --git a/tests/e2e/upgrade/init-e2e.Dockerfile b/tests/e2e/upgrade/init-e2e.Dockerfile new file mode 100644 index 00000000000..320445f85a7 --- /dev/null +++ b/tests/e2e/upgrade/init-e2e.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-upgrade + +## Deploy image +FROM ubuntu + +COPY --from=build /osmosis/build/upgrade /bin/upgrade + +ENV HOME /osmosis +WORKDIR $HOME + +CMD [ "upgrade" ] diff --git a/tests/e2e/upgrade/main.go b/tests/e2e/upgrade/main.go new file mode 100644 index 00000000000..849647edbdc --- /dev/null +++ b/tests/e2e/upgrade/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "io/ioutil" + + "github.com/osmosis-labs/osmosis/v7/tests/e2e/chain" +) + +func main() { + tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-") + if err != nil { + panic(err) + } + + chain, err := chain.Init(chain.ChainAID, tmpDir) + if err != nil { + panic(err) + } + fmt.Println(chain) +} From e8b133946bd46b43c8c3e5ff08fbcb3f39cd5779 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 22 Apr 2022 16:30:11 -0400 Subject: [PATCH 3/9] allow for running the upgrade initialization in Docker by providing a data dir --- tests/e2e/upgrade/init-e2e.Dockerfile | 2 +- tests/e2e/upgrade/main.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/e2e/upgrade/init-e2e.Dockerfile b/tests/e2e/upgrade/init-e2e.Dockerfile index 320445f85a7..34f68bd3125 100644 --- a/tests/e2e/upgrade/init-e2e.Dockerfile +++ b/tests/e2e/upgrade/init-e2e.Dockerfile @@ -20,4 +20,4 @@ COPY --from=build /osmosis/build/upgrade /bin/upgrade ENV HOME /osmosis WORKDIR $HOME -CMD [ "upgrade" ] +ENTRYPOINT [ "upgrade" ] diff --git a/tests/e2e/upgrade/main.go b/tests/e2e/upgrade/main.go index 849647edbdc..054469b1e84 100644 --- a/tests/e2e/upgrade/main.go +++ b/tests/e2e/upgrade/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "io/ioutil" @@ -8,6 +9,14 @@ import ( ) func main() { + var dataDir string + flag.StringVar(&dataDir, "data-dir", "", "chain data directory") + flag.Parse() + + if len(dataDir) == 0 { + panic("data-dir is required") + } + tmpDir, err := ioutil.TempDir("", "osmosis-e2e-testnet-") if err != nil { panic(err) From f5f9d9dd1fc954ad3ecaf9a32d8303e906cf7a03 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 22 Apr 2022 17:42:44 -0400 Subject: [PATCH 4/9] improve abstractions for chain initialization and add README --- Makefile | 8 +-- tests/e2e/README.md | 53 ++++++++++++++++++- .../chain-init.Dockerfile} | 6 +-- tests/e2e/{upgrade => chain_init}/main.go | 7 ++- 4 files changed, 61 insertions(+), 13 deletions(-) rename tests/e2e/{upgrade/init-e2e.Dockerfile => chain_init/chain-init.Dockerfile} (80%) rename tests/e2e/{upgrade => chain_init}/main.go (71%) diff --git a/Makefile b/Makefile index 7cdbd3c31f6..83491d806b9 100644 --- a/Makefile +++ b/Makefile @@ -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" @@ -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 ### diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 846d854bdd4..c6a8cbafbf8 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 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. @@ -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 +``` diff --git a/tests/e2e/upgrade/init-e2e.Dockerfile b/tests/e2e/chain_init/chain-init.Dockerfile similarity index 80% rename from tests/e2e/upgrade/init-e2e.Dockerfile rename to tests/e2e/chain_init/chain-init.Dockerfile index 34f68bd3125..91e5346b0df 100644 --- a/tests/e2e/upgrade/init-e2e.Dockerfile +++ b/tests/e2e/chain_init/chain-init.Dockerfile @@ -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" ] diff --git a/tests/e2e/upgrade/main.go b/tests/e2e/chain_init/main.go similarity index 71% rename from tests/e2e/upgrade/main.go rename to tests/e2e/chain_init/main.go index 054469b1e84..edb26b0c199 100644 --- a/tests/e2e/upgrade/main.go +++ b/tests/e2e/chain_init/main.go @@ -3,7 +3,7 @@ package main import ( "flag" "fmt" - "io/ioutil" + "os" "github.com/osmosis-labs/osmosis/v7/tests/e2e/chain" ) @@ -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) } From b62ebf47e0c1a564997dc47d028efbfcaec73d43 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 22 Apr 2022 17:54:38 -0400 Subject: [PATCH 5/9] add to README --- tests/e2e/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/e2e/README.md b/tests/e2e/README.md index c6a8cbafbf8..6690ecf9354 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -51,8 +51,11 @@ 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 +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. - `--data-dir` flag is needed for outputting the files into a directory inside the container ##### To build the debug Osmosis image: From 757c1a74537a9b149d04d239d714e3fe90420476 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 22 Apr 2022 17:58:32 -0400 Subject: [PATCH 6/9] add to README --- tests/e2e/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 6690ecf9354..63af9e488e8 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -56,6 +56,7 @@ docker run -v < path >:/tmp/osmo-test osmosis-e2e-chain-init:debug --data-dir=/t 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 ##### To build the debug Osmosis image: From 97611011b057ecb78619cd040c251ed3fa88b379 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 22 Apr 2022 18:10:11 -0400 Subject: [PATCH 7/9] improve README --- tests/e2e/README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 63af9e488e8..8cca9f9724e 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -8,7 +8,7 @@ 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 +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 @@ -23,7 +23,7 @@ Currently, there is a single test in `e2e_test.go` to query the balances of a va ## `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. +file and all required configuration files such as the `app.toml`. This package directly depends on the Osmosis codebase. ## `upgrade` Package @@ -31,7 +31,7 @@ The `upgrade` package starts chain initialization. In addition, there is a Docke 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. +The decoupling between chain initialization and start-up allows to minimize the differences between our test suite and the production environment. # Running Locally @@ -59,6 +59,11 @@ sudo rm -r < path > # must be root to clean up - < 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: ``` From a9a2fa25b386b9eb540f77c1ba8bf5c3ccedef3f Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 22 Apr 2022 18:13:30 -0400 Subject: [PATCH 8/9] typo in README --- tests/e2e/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 8cca9f9724e..a3de35e60dd 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -27,7 +27,7 @@ file and all required configuration files such as the `app.toml`. This package d ## `upgrade` Package -The `upgrade` package starts chain initialization. In addition, there is a Dockerfile `init-e2e.Dockerfile. +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. From e10016cd97733e33c1c573661141bd13aa6a2e93 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 22 Apr 2022 18:17:52 -0400 Subject: [PATCH 9/9] fmt and lint --- tests/e2e/chain/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/chain/main.go b/tests/e2e/chain/main.go index c789e6e2dc3..20453d7186d 100644 --- a/tests/e2e/chain/main.go +++ b/tests/e2e/chain/main.go @@ -1,7 +1,6 @@ package chain func Init(id, dataDir string) (*Chain, error) { - chain, err := new(id, dataDir) if err != nil { return nil, err