Skip to content

Commit

Permalink
refactor integration test setup (#462)
Browse files Browse the repository at this point in the history
* refactor integration tests

Refactor integrations tests to build a docker image with the specified configurations locally rather than relying on a remote docker image

* fix akash test

* remove unnecessary comments

* Update Makefile

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
  • Loading branch information
colin-axner and fedekunze authored Mar 22, 2021
1 parent 87cef08 commit 58174f4
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 25 deletions.
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 ]
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -104,4 +104,3 @@ check-swagger:

update-swagger-docs: check-swagger
swagger generate spec -o ./docs/swagger-ui/swagger.yaml

14 changes: 14 additions & 0 deletions test/setup/Dockerfile.akashtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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

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}}
20 changes: 20 additions & 0 deletions test/setup/Dockerfile.gaiatest
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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}}
35 changes: 35 additions & 0 deletions test/setup/akash-setup.sh
Original file line number Diff line number Diff line change
@@ -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

35 changes: 35 additions & 0 deletions test/setup/gaia-setup.sh
Original file line number Diff line number Diff line change
@@ -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

16 changes: 5 additions & 11 deletions test/test_chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
dockerfile: "./setup/Dockerfile.gaiatest",
timeout: 3 * time.Second,
rpcPort: "26657",
accountPrefix: "cosmos",
Expand All @@ -35,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",
Expand All @@ -55,8 +50,7 @@ type (
// testChainConfig represents the chain specific docker and codec configurations
// required.
testChainConfig struct {
dockerImage string
dockerTag string
dockerfile string
rpcPort string
timeout time.Duration
accountPrefix string
Expand Down
14 changes: 7 additions & 7 deletions test/test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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()}},
},
Expand All @@ -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(tc.t.dockerfile, dockerOpts)
require.NoError(t, err)

c.Log(fmt.Sprintf("- [%s] SPUN UP IN CONTAINER %s from %s", c.ChainID,
Expand Down

0 comments on commit 58174f4

Please sign in to comment.