From 0fd98e45051d42c91ab1b8e6f6cfcde687578404 Mon Sep 17 00:00:00 2001 From: Greg Szabo Date: Tue, 2 Feb 2021 04:26:50 -0500 Subject: [PATCH 1/2] Created abci test harness --- .cargo/config | 1 + tools/abci-test/Makefile.toml | 76 +++++-------------- tools/abci-test/run.sh | 41 ---------- tools/docker/README.md | 20 +++++ .../.gitignore | 0 tools/docker/abci-harness-0.34.0/Dockerfile | 31 ++++++++ tools/docker/abci-harness-0.34.0/entrypoint | 40 ++++++++++ tools/docker/kvstore-rs/Dockerfile | 9 --- tools/docker/tendermint-0.34.0/.gitignore | 1 + .../Dockerfile | 0 .../entrypoint | 0 11 files changed, 112 insertions(+), 107 deletions(-) delete mode 100755 tools/abci-test/run.sh rename tools/docker/{tendermint-v0.34.0 => abci-harness-0.34.0}/.gitignore (100%) create mode 100644 tools/docker/abci-harness-0.34.0/Dockerfile create mode 100755 tools/docker/abci-harness-0.34.0/entrypoint delete mode 100644 tools/docker/kvstore-rs/Dockerfile create mode 100644 tools/docker/tendermint-0.34.0/.gitignore rename tools/docker/{tendermint-v0.34.0 => tendermint-0.34.0}/Dockerfile (100%) rename tools/docker/{tendermint-v0.34.0 => tendermint-0.34.0}/entrypoint (100%) diff --git a/.cargo/config b/.cargo/config index 06136c7ca..3a3045ebd 100644 --- a/.cargo/config +++ b/.cargo/config @@ -2,4 +2,5 @@ build-all = "build --workspace --all-targets --" build-wasm-tendermint = "build -p tendermint --manifest-path tendermint/Cargo.toml --target wasm32-unknown-unknown --release --no-default-features --" build-wasm-light-client = "build -p tendermint-light-client --manifest-path light-client/Cargo.toml --target wasm32-unknown-unknown --release --no-default-features --" +build-abci = "build --manifest-path abci/Cargo.toml --bin kvstore-rs --features binary,kvstore-app" test-all-features = "test --all-features --no-fail-fast" diff --git a/tools/abci-test/Makefile.toml b/tools/abci-test/Makefile.toml index 178c64e87..8289d36a3 100644 --- a/tools/abci-test/Makefile.toml +++ b/tools/abci-test/Makefile.toml @@ -1,80 +1,42 @@ [env] -TENDERMINT_CONTAINER = "abci-test-tendermint" -TENDERMINT_IMAGE = "informaldev/tendermint:0.34.0" -KVSTORE_CONTAINER = "abci-test-kvstore" -KVSTORE_IMAGE = "informaldev/kvstore-rs:0.18.0" +CONTAINER_NAME = "abci-test" +DOCKER_IMAGE = "informaldev/abci-harness:0.34.0" +HOST_RPC_PORT = 26657 CARGO_MAKE_WAIT_MILLISECONDS = 3500 [tasks.default] clear = true -dependencies = [ - "docker-up", - "wait", - "run", - "docker-down" -] +dependencies = [ "docker-up", "wait", "test", "docker-down" ] -[tasks.run] -command = "cargo" -args = [ "run", "--", "--verbose" ] +[tasks.build-linux-abci] +command = "docker" +args = [ "run", "--rm", "--volume", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/..:/usr/src/myapp", "--workdir", "/usr/src/myapp", "rust:latest", "cargo", "build-abci" ] [tasks.docker-down] dependencies = [ "docker-stop", "docker-rm" ] [tasks.docker-up] -dependencies = [ "kvstore-up", "tendermint-up" ] - -[tasks.kvstore-up] -command = "docker" -args = [ - "run", - "--name", "${KVSTORE_CONTAINER}", - "--rm", - "--net=host", - "--detach", - "${KVSTORE_IMAGE}", - "--verbose" -] - -[tasks.tendermint-up] command = "docker" -args = [ - "run", - "--name", "${TENDERMINT_CONTAINER}", - "--rm", - "--net=host", - "--detach", - "${TENDERMINT_IMAGE}", - "node", - "--proxy_app", "tcp://127.0.0.1:26658" -] +args = ["run", "--name", "${CONTAINER_NAME}", "--rm", "--publish", "26657:${HOST_RPC_PORT}", "--volume", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/../target/debug:/abci", "--detach", "${DOCKER_IMAGE}", "--verbose" ] +dependencies = ["docker-up-stop-old", "docker-up-rm-old"] -[tasks.kvstore-stop] -command = "docker" -args = [ "stop", "-t", "3", "${KVSTORE_CONTAINER}" ] -ignore_errors = true -private = true +[tasks.test] +args = ["run", "--all-features"] -[tasks.tendermint-stop] -command = "docker" -args = [ "stop", "${TENDERMINT_CONTAINER}" ] -ignore_errors = true -private = true - -[tasks.kvstore-rm] +[tasks.docker-stop] command = "docker" -args = [ "rm", "--force", "${KVSTORE_CONTAINER}" ] +args = ["stop", "${CONTAINER_NAME}"] ignore_errors = true private = true -[tasks.tendermint-rm] +[tasks.docker-rm] command = "docker" -args = [ "rm", "--force", "${TENDERMINT_CONTAINER}" ] +args = ["rm", "--force", "${CONTAINER_NAME}"] ignore_errors = true private = true -[tasks.docker-stop] -dependencies = [ "tendermint-stop", "kvstore-stop" ] +[tasks.docker-up-stop-old] +alias = "docker-stop" -[tasks.docker-rm] -dependencies = [ "tendermint-rm", "kvstore-rm" ] +[tasks.docker-up-rm-old] +alias = "docker-rm" diff --git a/tools/abci-test/run.sh b/tools/abci-test/run.sh deleted file mode 100755 index 43f0cb79a..000000000 --- a/tools/abci-test/run.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -set -e - -TENDERMINT_CONTAINER=${TENDERMINT_CONTAINER:-"abci-test-tendermint"} -TENDERMINT_IMAGE=${TENDERMINT_IMAGE:-"informaldev/tendermint:0.34.0"} -KVSTORE_RS_LOG=${KVSTORE_RS_LOG:-"/tmp/kvstore-rs.log"} - -echo "Building and running kvstore-rs..." -cd ../../abci -cargo build --bin kvstore-rs --features binary,kvstore-app -cargo run --bin kvstore-rs --features binary,kvstore-app -- -v >${KVSTORE_RS_LOG} 2>&1 & -export KVSTORE_PID=$! -sleep 1 - -echo "Starting Tendermint..." -docker run \ - --rm \ - --name ${TENDERMINT_CONTAINER} \ - --net=host \ - --detach \ - ${TENDERMINT_IMAGE} \ - node --proxy_app tcp://127.0.0.1:26658 -sleep 3 - -echo "Running ABCI test harness..." -set +e -cd ../tools/abci-test -cargo run -- -v - -echo "Stopping Tendermint..." -docker stop ${TENDERMINT_CONTAINER} - -echo "Stopping kvstore-rs" -kill ${KVSTORE_PID} - -echo "" -echo "kvstore-rs logs:" -echo "" -cat ${KVSTORE_RS_LOG} - -echo "Done." diff --git a/tools/docker/README.md b/tools/docker/README.md index c3f90bfdc..b1dfeddae 100644 --- a/tools/docker/README.md +++ b/tools/docker/README.md @@ -24,3 +24,23 @@ Both wallets have `uatom`, `stake` and `n0token` added. Both wallets have an initial signed transaction created for easier population of the network before testing. These transactions will send uatom tokens from c0 -> c1 and vice versa. They are both signed as `sequence 0` in the wallet, so they can only be executed as the first transaction of the corresponding wallet. + +# abci-harness +This image is used during CI testing in the abci-rs crate. +It tests compatibility with the Tendermint Go implementation. +It derives from the Tendermint Docker image above, but it expects a volume attached at `/abci` that contains the ABCI +application to be tested. The name of the ABCI application is `kvstore-rs` by default. This can be changed by setting the +`ABCI_APP` environment variable. + +The image will fire up a Tendermint node (auto-creating the configuration) and then execute the ABCI application +from the attached volume. It logs the Tendermint node log into kvstore-rs.tendermint and the ABCI application log into +kvstore-rs.log on the attached volume. + +This image has both the `muslc` and `glibc` libraries installed for easy testing of dynamically linked binaries. + +Example: +```bash +docker run -it --rm -v $PWD/target/debug:/abci -p 26657:26657 informaldev/abci-harness:0.34.0 +``` + +The image version reflects the Tendermint Go binary version. diff --git a/tools/docker/tendermint-v0.34.0/.gitignore b/tools/docker/abci-harness-0.34.0/.gitignore similarity index 100% rename from tools/docker/tendermint-v0.34.0/.gitignore rename to tools/docker/abci-harness-0.34.0/.gitignore diff --git a/tools/docker/abci-harness-0.34.0/Dockerfile b/tools/docker/abci-harness-0.34.0/Dockerfile new file mode 100644 index 000000000..3dde3efdc --- /dev/null +++ b/tools/docker/abci-harness-0.34.0/Dockerfile @@ -0,0 +1,31 @@ +FROM alpine:3.13.1 +LABEL maintainer="hello@informal.systems" + +ENV TMHOME=/tendermint +#GLIBC for Alpine from: https://github.com/sgerrand/alpine-pkg-glibc +RUN wget https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \ + -O /etc/apk/keys/sgerrand.rsa.pub && \ + wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.32-r0/glibc-2.32-r0.apk \ + https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.32-r0/glibc-bin-2.32-r0.apk \ + https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.32-r0/glibc-i18n-2.32-r0.apk && \ + apk add --no-cache glibc-2.32-r0.apk glibc-bin-2.32-r0.apk glibc-i18n-2.32-r0.apk && \ + rm glibc-2.32-r0.apk glibc-bin-2.32-r0.apk glibc-i18n-2.32-r0.apk && \ + /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8 && \ + apk --no-cache add jq bash file && \ + wget https://github.com/freshautomations/sconfig/releases/download/v0.1.0/sconfig_linux_amd64 \ + -O /usr/bin/sconfig && \ + chmod 755 /usr/bin/sconfig && \ + addgroup tendermint && \ + adduser -S -G tendermint tendermint -h "$TMHOME" +USER tendermint +WORKDIR $TMHOME + +EXPOSE 26656 26657 26658 26660 +STOPSIGNAL SIGTERM + +ARG TENDERMINT=tendermint +COPY $TENDERMINT /usr/bin/tendermint + +COPY entrypoint /usr/bin/entrypoint +ENTRYPOINT ["/usr/bin/entrypoint"] +VOLUME [ "$TMHOME", "/abci" ] diff --git a/tools/docker/abci-harness-0.34.0/entrypoint b/tools/docker/abci-harness-0.34.0/entrypoint new file mode 100755 index 000000000..a5ed98bb2 --- /dev/null +++ b/tools/docker/abci-harness-0.34.0/entrypoint @@ -0,0 +1,40 @@ +#!/usr/bin/env sh +set -euo pipefail + +ABCI_PATH="/abci/${ABCI_APP:-kvstore-rs}" + +if [ ! -x "${ABCI_PATH}" ]; then + echo "Could not find executable ABCI app at ${ABCI_PATH} ." + echo "Add a volume with the file and use the ABCI_APP environment variable to point to a different file." + exit 1 +else + FILE_TYPE="$(file -b "${ABCI_PATH}")" + if [ -n "${FILE_TYPE##ELF 64-bit*}" ]; then + echo "File is not an ELF 64-bit binary (${FILE_TYPE})." + echo "Build the ABCI application for Linux using Docker:" + echo "docker run -it --rm --user \"\$(id -u)\":\"\$(id -g)\" -v \"\$PWD\":/usr/src/myapp -w /usr/src/myapp rust:latest cargo build-abci" + exit 1 + fi +fi + +if [ ! -d "${TMHOME}/config" ]; then + + echo "Running tendermint init to create configuration." + /usr/bin/tendermint init + + sconfig -s ${TMHOME}/config/config.toml \ + moniker=${MONIKER:-dockernode} \ + consensus.timeout_commit=500ms \ + rpc.laddr=tcp://0.0.0.0:26657 \ + p2p.addr_book_strict=false \ + instrumentation.prometheus=true + + sconfig -s ${TMHOME}/config/genesis.json \ + chain_id=${CHAIN_ID:-dockerchain} \ + consensus_params.block.time_iota_ms=500 + +fi + +exec /usr/bin/tendermint node 2>&1 > "${ABCI_PATH}.tendermint" & + +exec "${ABCI_PATH}" "$@" 2>&1 | tee "${ABCI_PATH}.log" diff --git a/tools/docker/kvstore-rs/Dockerfile b/tools/docker/kvstore-rs/Dockerfile deleted file mode 100644 index 27c15f015..000000000 --- a/tools/docker/kvstore-rs/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM rust:1.49-slim-buster AS build -LABEL maintainer="hello@informal.systems" -COPY . /tendermint-rs/ -WORKDIR /tendermint-rs/abci -RUN cargo build --release --bin kvstore-rs --features binary,kvstore-app - -FROM debian:buster-slim -COPY --from=build /tendermint-rs/target/release/kvstore-rs /usr/local/bin/kvstore-rs -ENTRYPOINT [ "/usr/local/bin/kvstore-rs" ] diff --git a/tools/docker/tendermint-0.34.0/.gitignore b/tools/docker/tendermint-0.34.0/.gitignore new file mode 100644 index 000000000..0c8c39bef --- /dev/null +++ b/tools/docker/tendermint-0.34.0/.gitignore @@ -0,0 +1 @@ +tendermint \ No newline at end of file diff --git a/tools/docker/tendermint-v0.34.0/Dockerfile b/tools/docker/tendermint-0.34.0/Dockerfile similarity index 100% rename from tools/docker/tendermint-v0.34.0/Dockerfile rename to tools/docker/tendermint-0.34.0/Dockerfile diff --git a/tools/docker/tendermint-v0.34.0/entrypoint b/tools/docker/tendermint-0.34.0/entrypoint similarity index 100% rename from tools/docker/tendermint-v0.34.0/entrypoint rename to tools/docker/tendermint-0.34.0/entrypoint From b336b15bb4d20b7d0c4b43d2de99bb5701c9e464 Mon Sep 17 00:00:00 2001 From: Greg Szabo Date: Tue, 2 Feb 2021 09:32:21 -0500 Subject: [PATCH 2/2] cargo make additions and docs --- tools/abci-test/Makefile.toml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/abci-test/Makefile.toml b/tools/abci-test/Makefile.toml index 8289d36a3..a33e677fd 100644 --- a/tools/abci-test/Makefile.toml +++ b/tools/abci-test/Makefile.toml @@ -4,6 +4,11 @@ DOCKER_IMAGE = "informaldev/abci-harness:0.34.0" HOST_RPC_PORT = 26657 CARGO_MAKE_WAIT_MILLISECONDS = 3500 +# abci-test infrastructure: +# cargo make build-linux-abci - build the ABCI app using Docker (helpful on a Mac) +# cargo make - run the test harness and all tests. Expects a Linux ABCI app already built. +# cargo make docker-up-debug - troubleshoot the infra setup (useful to see docker error messages or the kvstore log). + [tasks.default] clear = true dependencies = [ "docker-up", "wait", "test", "docker-down" ] @@ -20,6 +25,11 @@ command = "docker" args = ["run", "--name", "${CONTAINER_NAME}", "--rm", "--publish", "26657:${HOST_RPC_PORT}", "--volume", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/../target/debug:/abci", "--detach", "${DOCKER_IMAGE}", "--verbose" ] dependencies = ["docker-up-stop-old", "docker-up-rm-old"] +[tasks.docker-up-debug] +command = "docker" +args = ["run", "--name", "${CONTAINER_NAME}", "--rm", "--publish", "26657:${HOST_RPC_PORT}", "--volume", "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/../target/debug:/abci", "${DOCKER_IMAGE}", "--verbose" ] +dependencies = ["docker-up-stop-old", "docker-up-rm-old"] + [tasks.test] args = ["run", "--all-features"]