From cfd3eabdb7d4d247f3ae1ff6744b7cab4f7cee38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 18 Mar 2021 16:49:56 +0100 Subject: [PATCH 1/4] refactor integration tests Refactor integrations tests to build a docker image with the specified configurations locally rather than relying on a remote docker image --- Dockerfile | 7 ++----- Makefile | 2 +- test/setup/Dockerfile.gaiatest | 24 +++++++++++++++++++++++ test/setup/gaia-setup.sh | 35 ++++++++++++++++++++++++++++++++++ test/test_chains.go | 11 ++++------- test/test_setup.go | 14 +++++++------- 6 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 test/setup/Dockerfile.gaiatest create mode 100755 test/setup/gaia-setup.sh diff --git a/Dockerfile b/Dockerfile index c2d006efc..cb35bb960 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,10 +7,10 @@ COPY . . # Update and install needed deps prioir to installing the binary. RUN apk update && \ - apk --no-cache add make=4.2.1-r2 git=2.24.3-r0 && \ + apk --no-cache add make git && \ make install -FROM alpine:edge +FROM alpine:latest ENV RELAYER /relayer @@ -26,6 +26,3 @@ WORKDIR $RELAYER COPY --from=BUILD /go/bin/rly /usr/bin/rly ENTRYPOINT ["/usr/bin/rly"] - -# Make config available ofr mutaitons -VOLUME [ $RELAYER ] diff --git a/Makefile b/Makefile index e2fe1cfd0..f1acf9bac 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//') COMMIT := $(shell git log -1 --format='%H') SDKCOMMIT := $(shell go list -m -u -f '{{.Version}}' github.com/cosmos/cosmos-sdk) -GAIA_VERSION := v4.0.0 +GAIA_VERSION := v4.1.0 AKASH_VERSION := jack/update-sdk WASMD_VERSION := v0.14.1 diff --git a/test/setup/Dockerfile.gaiatest b/test/setup/Dockerfile.gaiatest new file mode 100644 index 000000000..78d7b7f6c --- /dev/null +++ b/test/setup/Dockerfile.gaiatest @@ -0,0 +1,24 @@ +# Simple usage with a mounted data directory: +# > docker build -t gaia . +# > docker run -it -p 46657:46657 -p 46656:46656 -v ~/.gaia:/root/.gaia gaia gaiad init +# > docker run -it -p 46657:46657 -p 46656:46656 -v ~/.gaia:/root/.gaia gaia gaiad start +FROM tendermint/gaia:v4.1.0 + +# Set up dependencies +ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 + +USER root + +# Install minimum necessary dependencies, build Cosmos SDK, remove packages +RUN apk add --no-cache $PACKAGES + +USER gaia + +WORKDIR /gaia + +COPY ./gaia-setup.sh . + +EXPOSE 26657 + +ENTRYPOINT [ "./gaia-setup.sh" ] +# NOTE: to run this image, docker run -d -p 26657:26657 ./single-node.sh {{chain_id}} {{genesis_account}} diff --git a/test/setup/gaia-setup.sh b/test/setup/gaia-setup.sh new file mode 100755 index 000000000..ea9e4c689 --- /dev/null +++ b/test/setup/gaia-setup.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +set -o errexit -o nounset + +CHAINID=$1 +GENACCT=$2 + +if [ -z "$1" ]; then + echo "Need to input chain id..." + exit 1 +fi + +if [ -z "$2" ]; then + echo "Need to input genesis account address..." + exit 1 +fi + +# Build genesis file incl account for passed address +coins="10000000000stake,100000000000samoleans" +gaiad init --chain-id $CHAINID $CHAINID +gaiad keys add validator --keyring-backend="test" +gaiad add-genesis-account $(gaiad keys show validator -a --keyring-backend="test") $coins +gaiad add-genesis-account $GENACCT $coins +gaiad gentx validator 5000000000stake --keyring-backend="test" --chain-id $CHAINID +gaiad collect-gentxs + +# Set proper defaults and change ports +sed -i 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' ~/.gaia/config/config.toml +sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' ~/.gaia/config/config.toml +sed -i 's/timeout_propose = "3s"/timeout_propose = "1s"/g' ~/.gaia/config/config.toml +sed -i 's/index_all_keys = false/index_all_keys = true/g' ~/.gaia/config/config.toml + +# Start the gaia +gaiad start --pruning=nothing + diff --git a/test/test_chains.go b/test/test_chains.go index 0f996a4d1..87792ca87 100644 --- a/test/test_chains.go +++ b/test/test_chains.go @@ -12,17 +12,13 @@ import ( ) var ( - // Chains built using SDK v0.41.0 - - // GAIA BLOCK TIMEOUTS are located in the single node setup script on gaia - // https://github.com/cosmos/gaia/blob/main/contrib/single-node.sh + // GAIA BLOCK TIMEOUTS are located in the gaia setup script in the + // setup directory. // timeout_commit = "1000ms" // timeout_propose = "1000ms" // 3 second relayer timeout works well with these block times gaiaTestConfig = testChainConfig{ - // This is built from contrib/Dockerfile.test from the gaia repository: - dockerImage: "colinaxner/gaiatest", - dockerTag: "v4.0.0", + // This is built from Dockerfile.gaiatest in setup dir timeout: 3 * time.Second, rpcPort: "26657", accountPrefix: "cosmos", @@ -57,6 +53,7 @@ type ( testChainConfig struct { dockerImage string dockerTag string + entrypoint string rpcPort string timeout time.Duration accountPrefix string diff --git a/test/test_setup.go b/test/test_setup.go index ed4565b4b..22fa38787 100644 --- a/test/test_setup.go +++ b/test/test_setup.go @@ -78,8 +78,7 @@ func removeTestContainer(pool *dockertest.Pool, containerName string) error { containers, err := pool.Client.ListContainers(dc.ListContainersOptions{ All: true, Filters: map[string][]string{ - "name": {containerName}, - "label": {"io.iqlusion.relayer.test=true"}, + "name": {containerName}, }, }) if err != nil { @@ -103,6 +102,8 @@ func removeTestContainer(pool *dockertest.Pool, containerName string) error { } // spinUpTestContainer spins up a test container with the given configuration +// A docker image is built for each chain using its provided configuration. +// This image is then ran using the options set below. func spinUpTestContainer(t *testing.T, rchan chan<- *dockertest.Resource, pool *dockertest.Pool, c *ry.Chain, dir string, wg *sync.WaitGroup, tc testChain) { defer wg.Done() @@ -126,16 +127,15 @@ func spinUpTestContainer(t *testing.T, rchan chan<- *dockertest.Resource, // create the test key require.NoError(t, c.CreateTestKey()) - containerName := fmt.Sprintf("%s-%s", c.ChainID, t.Name()) + containerName := c.ChainID // setup docker options dockerOpts := &dockertest.RunOptions{ Name: containerName, - Repository: tc.t.dockerImage, - Tag: tc.t.dockerTag, + Repository: containerName, // Name must match Repository + Tag: "latest", // Must match docker default build tag ExposedPorts: []string{tc.t.rpcPort, c.GetRPCPort()}, Cmd: []string{c.ChainID, c.MustGetAddress().String()}, - Labels: map[string]string{"io.iqlusion.relayer.test": "true"}, PortBindings: map[dc.Port][]dc.PortBinding{ dc.Port(tc.t.rpcPort): {{HostPort: c.GetRPCPort()}}, }, @@ -145,7 +145,7 @@ func spinUpTestContainer(t *testing.T, rchan chan<- *dockertest.Resource, require.NoError(t, removeTestContainer(pool, containerName)) // create the proper docker image with port forwarding setup - resource, err = pool.RunWithOptions(dockerOpts) + resource, err = pool.BuildAndRunWithOptions("./setup/Dockerfile.gaiatest", dockerOpts) require.NoError(t, err) c.Log(fmt.Sprintf("- [%s] SPUN UP IN CONTAINER %s from %s", c.ChainID, From f1e78088e99bdef02c3110d894436718c7fcd989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 18 Mar 2021 17:16:38 +0100 Subject: [PATCH 2/4] fix akash test --- test/setup/Dockerfile.akashtest | 21 ++++++++++++++++++++ test/setup/Dockerfile.gaiatest | 4 ---- test/setup/akash-setup.sh | 35 +++++++++++++++++++++++++++++++++ test/test_chains.go | 9 +++------ test/test_setup.go | 2 +- 5 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 test/setup/Dockerfile.akashtest create mode 100755 test/setup/akash-setup.sh diff --git a/test/setup/Dockerfile.akashtest b/test/setup/Dockerfile.akashtest new file mode 100644 index 000000000..b149e832e --- /dev/null +++ b/test/setup/Dockerfile.akashtest @@ -0,0 +1,21 @@ +# https://hub.docker.com/r/ovrclk/akash/tags?page=1&ordering=last_updated +FROM ovrclk/akash:0.10.0 + +# Set up dependencies +ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 + +USER root + +# Install minimum necessary dependencies, build Cosmos SDK, remove packages +#RUN apk add --no-cache $PACKAGES + +#USER akash + +#WORKDIR /akash + +COPY ./akash-setup.sh . + +EXPOSE 26657 + +ENTRYPOINT [ "./akash-setup.sh" ] +# NOTE: to run this image, docker run -d -p 26657:26657 ./single-node.sh {{chain_id}} {{genesis_account}} diff --git a/test/setup/Dockerfile.gaiatest b/test/setup/Dockerfile.gaiatest index 78d7b7f6c..34bef1cb1 100644 --- a/test/setup/Dockerfile.gaiatest +++ b/test/setup/Dockerfile.gaiatest @@ -1,7 +1,3 @@ -# Simple usage with a mounted data directory: -# > docker build -t gaia . -# > docker run -it -p 46657:46657 -p 46656:46656 -v ~/.gaia:/root/.gaia gaia gaiad init -# > docker run -it -p 46657:46657 -p 46656:46656 -v ~/.gaia:/root/.gaia gaia gaiad start FROM tendermint/gaia:v4.1.0 # Set up dependencies diff --git a/test/setup/akash-setup.sh b/test/setup/akash-setup.sh new file mode 100755 index 000000000..741575922 --- /dev/null +++ b/test/setup/akash-setup.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +set -o errexit -o nounset + +CHAINID=$1 +GENACCT=$2 + +if [ -z "$1" ]; then + echo "Need to input chain id..." + exit 1 +fi + +if [ -z "$2" ]; then + echo "Need to input genesis account address..." + exit 1 +fi + +# Build genesis file incl account for passed address +coins="10000000000stake,100000000000samoleans" +akash init --chain-id $CHAINID $CHAINID +akash keys add validator --keyring-backend="test" +akash add-genesis-account $(akash keys show validator -a --keyring-backend="test") $coins +akash add-genesis-account $GENACCT $coins +akash gentx validator 5000000000stake --keyring-backend="test" --chain-id $CHAINID +akash collect-gentxs + +# Set proper defaults and change ports +sed -i 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' ~/.akash/config/config.toml +sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' ~/.akash/config/config.toml +sed -i 's/timeout_propose = "3s"/timeout_propose = "1s"/g' ~/.akash/config/config.toml +sed -i 's/index_all_keys = false/index_all_keys = true/g' ~/.akash/config/config.toml + +# Start the akash +akash start --pruning=nothing + diff --git a/test/test_chains.go b/test/test_chains.go index 87792ca87..ec12d2609 100644 --- a/test/test_chains.go +++ b/test/test_chains.go @@ -18,7 +18,7 @@ var ( // timeout_propose = "1000ms" // 3 second relayer timeout works well with these block times gaiaTestConfig = testChainConfig{ - // This is built from Dockerfile.gaiatest in setup dir + dockerfile: "./setup/Dockerfile.gaiatest", timeout: 3 * time.Second, rpcPort: "26657", accountPrefix: "cosmos", @@ -31,8 +31,7 @@ var ( // 3 second relayer timeout works well with these block times // This is built from contrib/Dockerfile.test from the akash repository: akashTestConfig = testChainConfig{ - dockerImage: "colinaxner/akashtest", - dockerTag: "latest", + dockerfile: "./setup/Dockerfile.akashtest", timeout: 3 * time.Second, rpcPort: "26657", accountPrefix: "akash", @@ -51,9 +50,7 @@ type ( // testChainConfig represents the chain specific docker and codec configurations // required. testChainConfig struct { - dockerImage string - dockerTag string - entrypoint string + dockerfile string rpcPort string timeout time.Duration accountPrefix string diff --git a/test/test_setup.go b/test/test_setup.go index 22fa38787..2ad86f60f 100644 --- a/test/test_setup.go +++ b/test/test_setup.go @@ -145,7 +145,7 @@ func spinUpTestContainer(t *testing.T, rchan chan<- *dockertest.Resource, require.NoError(t, removeTestContainer(pool, containerName)) // create the proper docker image with port forwarding setup - resource, err = pool.BuildAndRunWithOptions("./setup/Dockerfile.gaiatest", dockerOpts) + resource, err = pool.BuildAndRunWithOptions(tc.t.dockerfile, dockerOpts) require.NoError(t, err) c.Log(fmt.Sprintf("- [%s] SPUN UP IN CONTAINER %s from %s", c.ChainID, From 504cc929f637177fc33b309abd4e1eb140d4d27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Thu, 18 Mar 2021 17:18:06 +0100 Subject: [PATCH 3/4] remove unnecessary comments --- test/setup/Dockerfile.akashtest | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/setup/Dockerfile.akashtest b/test/setup/Dockerfile.akashtest index b149e832e..9ee7666fd 100644 --- a/test/setup/Dockerfile.akashtest +++ b/test/setup/Dockerfile.akashtest @@ -6,13 +6,6 @@ ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 USER root -# Install minimum necessary dependencies, build Cosmos SDK, remove packages -#RUN apk add --no-cache $PACKAGES - -#USER akash - -#WORKDIR /akash - COPY ./akash-setup.sh . EXPOSE 26657 From 7c766ae471eac7ff75e1e8c918b60a319086fb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 22 Mar 2021 14:39:41 +0100 Subject: [PATCH 4/4] Update Makefile Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f1acf9bac..985a86fe6 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//') COMMIT := $(shell git log -1 --format='%H') SDKCOMMIT := $(shell go list -m -u -f '{{.Version}}' github.com/cosmos/cosmos-sdk) GAIA_VERSION := v4.1.0 -AKASH_VERSION := jack/update-sdk +AKASH_VERSION := v0.10.2 WASMD_VERSION := v0.14.1 GOPATH := $(shell go env GOPATH) @@ -104,4 +104,3 @@ check-swagger: update-swagger-docs: check-swagger swagger generate spec -o ./docs/swagger-ui/swagger.yaml -