From f5c0b2cadcbc3995a6a91180a61fceb27afc4546 Mon Sep 17 00:00:00 2001 From: sampocs Date: Thu, 15 Sep 2022 09:28:18 -0500 Subject: [PATCH] Docker net multiple host (#213) --- .gitmodules | 6 +- Dockerfile.gaia | 13 +- Dockerfile.hermes | 8 +- Dockerfile.icq | 5 +- Dockerfile.juno | 30 +++ Dockerfile.osmo | 31 +++ Dockerfile.relayer | 9 +- Dockerfile.stride | 4 +- Makefile | 5 +- deps/relayer | 2 +- docker-compose.yml | 69 ++++++- scripts/README.md | 69 +++++++ scripts/account_vars.sh | 20 +- scripts/build.sh | 80 ++++---- scripts/config/hermes_config.toml | 46 ++++- scripts/config/ica.json | 31 +++ scripts/config/icq_config.yaml | 28 +++ scripts/config/relayer_config.yaml | 54 +++++- scripts/create_channels.sh | 19 ++ scripts/create_logs.sh | 36 ++-- scripts/{init_gaia.sh => init_chain.sh} | 100 +++++++--- scripts/init_relayers.sh | 40 ++-- scripts/init_stride.sh | 140 -------------- scripts/register_host.sh | 55 +++--- scripts/start_chain.sh | 38 ++++ scripts/start_network.sh | 59 +++--- scripts/test-util/1.sh | 8 + scripts/test-util/2.sh | 6 + scripts/tests/1.sh | 11 -- scripts/tests/2.sh | 8 - scripts/tests/3.sh | 33 ---- scripts/tests/basic_tests.bats | 147 -------------- scripts/tests/gaia_tests.bats | 242 ++++++++++++++++++++++++ scripts/tests/ica_redeem.sh | 53 ------ scripts/tests/juno_tests.bats | 238 +++++++++++++++++++++++ scripts/tests/local_tests.bats | 146 -------------- scripts/tests/osmo_tests.bats | 235 +++++++++++++++++++++++ scripts/tests/run_all_tests.sh | 6 +- scripts/vars.sh | 178 +++++++++++++---- 39 files changed, 1532 insertions(+), 776 deletions(-) create mode 100644 Dockerfile.juno create mode 100644 Dockerfile.osmo create mode 100644 scripts/config/ica.json create mode 100644 scripts/create_channels.sh rename scripts/{init_gaia.sh => init_chain.sh} (52%) delete mode 100755 scripts/init_stride.sh create mode 100644 scripts/start_chain.sh create mode 100644 scripts/test-util/1.sh create mode 100644 scripts/test-util/2.sh delete mode 100755 scripts/tests/1.sh delete mode 100755 scripts/tests/2.sh delete mode 100755 scripts/tests/3.sh delete mode 100755 scripts/tests/basic_tests.bats create mode 100644 scripts/tests/gaia_tests.bats delete mode 100755 scripts/tests/ica_redeem.sh create mode 100644 scripts/tests/juno_tests.bats delete mode 100644 scripts/tests/local_tests.bats create mode 100755 scripts/tests/osmo_tests.bats diff --git a/.gitmodules b/.gitmodules index e53bd2e08..886af1abe 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,8 +8,8 @@ path = deps/hermes url = git@github.com:informalsystems/ibc-rs.git [submodule "deps/relayer"] - # Commit: f56b9b6e5c9b8eaf6d4f93ee6497a3b1e13a9faf - # Tag: v2.0.0 + # Commit: 65d6065e8016e420c0ddaf9141b5c834e01804c0 + # Branch: andrew/client_icq path = deps/relayer url = git@github.com:cosmos/relayer.git [submodule "deps/gaia"] @@ -23,4 +23,4 @@ [submodule "deps/osmosis"] # Commit: 08669da8509059980dc964976ee1ca60c84f5c8a path = deps/osmosis - url = https://github.com/osmosis-labs/osmosis.git + url = https://github.com/osmosis-labs/osmosis.git \ No newline at end of file diff --git a/Dockerfile.gaia b/Dockerfile.gaia index 0621d8dfb..9742d9f43 100644 --- a/Dockerfile.gaia +++ b/Dockerfile.gaia @@ -1,15 +1,18 @@ -FROM golang:1.17-alpine3.15 AS gaiad-builder +FROM golang:1.17-alpine3.15 AS builder -WORKDIR /src/app/ +WORKDIR /opt RUN apk add --update curl make git libc-dev bash gcc linux-headers eudev-dev python3 -RUN git clone https://github.com/Stride-Labs/gaia --branch v7.0.2-pin-ibc-cosmos-sdk \ - && cd gaia \ +ENV COMMIT_HASH=5b47714dd5607993a1a91f2b06a6d92cbb504721 + +RUN git clone https://github.com/Stride-Labs/gaia gaia-install \ + && cd gaia-install \ + && git checkout $COMMIT_HASH \ && CGO_ENABLED=0 make install FROM alpine:3.15 -COPY --from=gaiad-builder /go/bin/gaiad /usr/local/bin/ +COPY --from=builder /go/bin/gaiad /usr/local/bin/ RUN adduser -S -h /home/gaia -D gaia -u 1000 USER gaia diff --git a/Dockerfile.hermes b/Dockerfile.hermes index 80811faf6..059d9524b 100644 --- a/Dockerfile.hermes +++ b/Dockerfile.hermes @@ -1,16 +1,18 @@ -FROM rust:1.58-slim as rust +FROM rust:1.58-slim as builder WORKDIR /opt RUN apt update && apt install git -y -RUN git clone https://github.com/informalsystems/ibc-rs --branch v1.0.0 \ +ENV COMMIT_HASH=ed4dd8c8b4ebd695730de2a1c69f3011cb179352 +RUN git clone https://github.com/informalsystems/ibc-rs \ && cd ibc-rs \ + && git checkout $COMMIT_HASH \ && cargo build --release FROM debian:bullseye-slim -COPY --from=rust /opt/ibc-rs/target/release/hermes /usr/local/bin/hermes +COPY --from=builder /opt/ibc-rs/target/release/hermes /usr/local/bin/hermes RUN apt-get update \ && adduser --system --home /home/hermes --disabled-password --disabled-login hermes -u 1000 diff --git a/Dockerfile.icq b/Dockerfile.icq index f8e1e47a8..a63cac9fb 100644 --- a/Dockerfile.icq +++ b/Dockerfile.icq @@ -20,4 +20,7 @@ USER icq WORKDIR /home/icq -CMD ["interchain-queries", "run"] \ No newline at end of file +RUN echo "while true; do interchain-queries run; done" > /home/icq/start.sh + +CMD ["sh", "/home/icq/start.sh"] + diff --git a/Dockerfile.juno b/Dockerfile.juno new file mode 100644 index 000000000..2528bdbd1 --- /dev/null +++ b/Dockerfile.juno @@ -0,0 +1,30 @@ +FROM golang:1.19-alpine3.15 AS builder + +WORKDIR /src/app/ + +RUN set -eux; apk add --no-cache ca-certificates build-base git; + +RUN git clone https://github.com/CosmosContracts/juno.git \ + && cd juno \ + && git checkout 9558920 + +WORKDIR /src/app/juno + +ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a +ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a +RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 7d2239e9f25e96d0d4daba982ce92367aacf0cbd95d2facb8442268f2b1cc1fc +RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep f6282df732a13dec836cda1f399dd874b1e3163504dbd9607c6af915b2740479 +RUN cp /lib/libwasmvm_muslc.$(uname -m).a /lib/libwasmvm_muslc.a + +RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build + +FROM alpine:3.15 +COPY --from=builder /src/app/juno/bin/junod /usr/local/bin/ +RUN adduser -S -h /home/juno -D juno -u 1000 + +USER juno +WORKDIR /home/juno + +EXPOSE 26657 26656 1317 9090 + +CMD ["junod", "start"] diff --git a/Dockerfile.osmo b/Dockerfile.osmo new file mode 100644 index 000000000..73080443b --- /dev/null +++ b/Dockerfile.osmo @@ -0,0 +1,31 @@ +FROM golang:1.18-alpine3.15 AS builder + +WORKDIR /src/app/ + +RUN set -eux; apk add --no-cache ca-certificates build-base; apk add git linux-headers + +RUN git clone https://github.com/osmosis-labs/osmosis.git \ + && cd osmosis \ + && git checkout 08669da8509059980dc964976ee1ca60c84f5c8a + +WORKDIR /src/app/osmosis + +# Cosmwasm - download correct libwasmvm version and verify checksum +RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) \ + && wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \ + -O /lib/libwasmvm_muslc.a \ + && wget https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/checksums.txt -O /tmp/checksums.txt \ + && sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep $(uname -m) | cut -d ' ' -f 1) + +RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build + +FROM alpine:3.15 +COPY --from=builder /src/app/osmosis/build/osmosisd /usr/local/bin/ +RUN adduser -S -h /home/osmosis -D osmosis -u 1000 + +USER osmosis +WORKDIR /home/osmosis + +EXPOSE 26657 26656 1317 9090 + +CMD ["osmosisd", "start"] diff --git a/Dockerfile.relayer b/Dockerfile.relayer index e64005c85..2dcca863f 100644 --- a/Dockerfile.relayer +++ b/Dockerfile.relayer @@ -1,18 +1,19 @@ -FROM golang:1.18-alpine3.15 AS relayer-builder +FROM golang:1.18-alpine3.15 AS builder WORKDIR /src/ +ENV COMMIT_HASH=65d6065e8016e420c0ddaf9141b5c834e01804c0 + RUN apk add --update git make gcc linux-headers libc-dev eudev-dev RUN git clone https://github.com/cosmos/relayer.git \ && cd relayer \ - && git checkout v2.0.0 \ + && git checkout $COMMIT_HASH \ && make install FROM alpine:3.15 -COPY --from=relayer-builder /go/bin/rly /usr/local/bin/ +COPY --from=builder /go/bin/rly /usr/local/bin/ RUN adduser -S -h /home/relayer -D relayer -u 1000 USER relayer WORKDIR /home/relayer -CMD ["rly", "start", "stride-gaia"] diff --git a/Dockerfile.stride b/Dockerfile.stride index 7dbd2b8f9..eac07da54 100644 --- a/Dockerfile.stride +++ b/Dockerfile.stride @@ -1,5 +1,5 @@ # syntax = docker/dockerfile:1 -FROM golang:1.18-alpine3.15 AS golang +FROM golang:1.18-alpine3.15 AS builder WORKDIR /src/ @@ -21,7 +21,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build make build # Add to a distroless container FROM alpine:3.15 -COPY --from=golang /src/build/strided /usr/local/bin/strided +COPY --from=builder /src/build/strided /usr/local/bin/strided RUN addgroup -g 1000 stride \ && adduser -S -h /home/stride -D stride -u 1000 -G stride diff --git a/Makefile b/Makefile index d563191b3..eb99b257d 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ test-unit: test-cover: @go test -mod=readonly -race -coverprofile=coverage.out -covermode=atomic ./x/$(module)/... -test-integration: +test-integration-local: sh scripts-local/tests/run_all_tests.sh test-integration-docker: @@ -143,6 +143,7 @@ start-local: build-local @sh scripts-local/start_network.sh ${cache} stop-local: - @killall gaiad strided junod osmosisd rly hermes interchain-queries || true + @killall gaiad strided junod osmosisd rly hermes interchain-queries icq-startup.sh || true @pkill -f "/bin/bash.*create_logs.sh" || true @pkill -f "sh.*start_network.sh" || true + diff --git a/deps/relayer b/deps/relayer index f56b9b6e5..65d6065e8 160000 --- a/deps/relayer +++ b/deps/relayer @@ -1 +1 @@ -Subproject commit f56b9b6e5c9b8eaf6d4f93ee6497a3b1e13a9faf +Subproject commit 65d6065e8016e420c0ddaf9141b5c834e01804c0 diff --git a/docker-compose.yml b/docker-compose.yml index 41fd85248..9467e1347 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,6 @@ version: "3.8" services: stride1: image: stridezone:stride - hostname: stride volumes: - ./scripts/state/stride1:/home/stride/.stride ports: @@ -12,49 +11,101 @@ services: stride2: image: stridezone:stride - hostname: stride volumes: - ./scripts/state/stride2:/home/stride/.stride stride3: image: stridezone:stride - hostname: stride volumes: - ./scripts/state/stride3:/home/stride/.stride gaia1: image: stridezone:gaia - hostname: stride volumes: - ./scripts/state/gaia1:/home/gaia/.gaia ports: - "26557:26657" - "1307:1317" - "9080:9090" + gaia2: image: stridezone:gaia - hostname: stride volumes: - ./scripts/state/gaia2:/home/gaia/.gaia gaia3: image: stridezone:gaia - hostname: stride volumes: - ./scripts/state/gaia3:/home/gaia/.gaia gaia4: image: stridezone:gaia - hostname: stride volumes: - ./scripts/state/gaia4:/home/gaia/.gaia gaia5: image: stridezone:gaia - hostname: stride volumes: - ./scripts/state/gaia5:/home/gaia/.gaia + juno1: + image: stridezone:juno + volumes: + - ./scripts/state/juno1:/home/juno/.juno + ports: + - "26457:26657" + - "1297:1317" + - "9070:9090" + + juno2: + image: stridezone:juno + volumes: + - ./scripts/state/juno2:/home/juno/.juno + + juno3: + image: stridezone:juno + volumes: + - ./scripts/state/juno3:/home/juno/.juno + + juno4: + image: stridezone:juno + volumes: + - ./scripts/state/juno4:/home/juno/.juno + + juno5: + image: stridezone:juno + volumes: + - ./scripts/state/juno5:/home/juno/.juno + + osmo1: + image: stridezone:osmo + volumes: + - ./scripts/state/osmo1:/home/osmosis/.osmosisd + ports: + - "26357:26657" + - "1287:1317" + - "9060:9090" + + osmo2: + image: stridezone:osmo + volumes: + - ./scripts/state/osmo2:/home/osmosis/.osmosisd + + osmo3: + image: stridezone:osmo + volumes: + - ./scripts/state/osmo3:/home/osmosis/.osmosisd + + osmo4: + image: stridezone:osmo + volumes: + - ./scripts/state/osmo4:/home/osmosis/.osmosisd + + osmo5: + image: stridezone:osmo + volumes: + - ./scripts/state/osmo5:/home/osmosis/.osmosisd + hermes: image: stridezone:hermes volumes: @@ -69,7 +120,7 @@ services: restart: always icq: - image: stridezone:interchain-queries + image: stridezone:icq volumes: - ./scripts/state/icq:/home/icq/.icq restart: always diff --git a/scripts/README.md b/scripts/README.md index b78815a5a..54e65576a 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1 +1,70 @@ `/scripts` contains (unmaintained) infrastructure that was used for early testing and development of the Stride protocol. The scripts here support docker-image based testing, some of which are heavily inspired by those used by Osmosis and Quicksilver (although there have been deviations from the original implementations since). The relevant licenses are included here. + +## Dockernet +### Adding a new host zone +* Create a new dockerfile at the root level (`Dockerfile.{new-host-zone}) +* Add the host zone to the docker compose file at the root level. Add the port forwarding to the first node. Add 5 nodes here. Drop the RPC port number by 100, and the API/gRPC port by 10 since the last host zone. +``` + {new-host-zone}1: + image: stridezone:{new-host-zone} + volumes: + - ./scripts/state/{new-host-zone}1:/home/{new-host-zone}/.{new-host-zone} + ports: + - "26257:26657" + - "1277:1317" + - "9050:9090" + + {new-host-zone}2: + image: stridezone:{new-host-zone} + volumes: + - ./scripts/state/{new-host-zone}2:/home/{new-host-zone}/.{new-host-zone} + + ... + + {new-host-zone}5: + image: stridezone:{new-host-zone} + volumes: + - ./scripts/state/{new-host-zone}5:/home/{new-host-zone}/.{new-host-zone} +``` +* Add the host zone as a submodule in `deps` +* Add the build command for that host zone in `scripts/build.sh` +``` +while getopts sgojhir{n} flag; do + case "${flag}" in + ... + n) build_local_and_docker {new-host-zone} deps/{new-host-zone} ;; +``` +* Add the following parameters to `scripts/vars.sh`, where `CHAIN_ID` is the ID of the new host zone +``` +{CHAIN_ID}_CHAIN_ID={NEW-HOST-ZONE} +{CHAIN_ID}_NODE_PREFIX={new-host-zone} +{CHAIN_ID}_NUM_NODES=3 +{CHAIN_ID}_CMD="$SCRIPT_DIR/../build/{new-host-zone}d" +{CHAIN_ID}_VAL_PREFIX={n}val +{CHAIN_ID}_REV_ACCT={n}rev1 +{CHAIN_ID}_DENOM= +{CHAIN_ID}_IBC_DENOM= +{CHAIN_ID}_RPC_PORT={the one included in the docker-compose above} +{CHAIN_ID}_MAIN_CMD="${CHAIN_ID}_CMD --home $SCRIPT_DIR/state/${${CHAIN_ID}_NODE_PREFIX}1" + +{CHAIN_ID}_REV_MNEMONIC="" +{CHAIN_ID}_VAL_MNEMONIC_1="" +{CHAIN_ID}_VAL_MNEMONIC_2="" +{CHAIN_ID}_VAL_MNEMONIC_3="" +{CHAIN_ID}_VAL_MNEMONIC_4="" +{CHAIN_ID}_VAL_MNEMONIC_5="" +{CHAIN_ID}_VAL_MNEMONICS=("${CHAIN_ID}_VAL_MNEMONIC_1","${CHAIN_ID}_VAL_MNEMONIC_2","${CHAIN_ID}_VAL_MNEMONIC_3","${CHAIN_ID}_VAL_MNEMONIC_4","${CHAIN_ID}_VAL_MNEMONIC_5") + + +HERMES_${CHAIN_ID}_ACCT=rly{add one since the account from the last host zone} +HERMES_${CHAIN_ID}_MNEMONIC="" + +ICQ_${CHAIN_ID}_ACCT=rly{add one since the account from the last host zone} +ICQ_${CHAIN_ID}_MNEMONIC="" +``` +* Finally add the execution of the `init_chain` script for this host zone in `scripts/start_network.sh`, and add it to the array of `HOST_CHAINS` +``` +sh ${SCRIPT_DIR}/init_chain.sh {NEW-HOST-ZONE} +HOST_CHAINS=(GAIA JUNO OSMO ... {NEW-HOST-ZONE}) +``` +* And that's it! Just start the network as normal, and make sure to rebuild the new host zone when running for the first time. \ No newline at end of file diff --git a/scripts/account_vars.sh b/scripts/account_vars.sh index 8f1a807e1..54d037127 100755 --- a/scripts/account_vars.sh +++ b/scripts/account_vars.sh @@ -6,16 +6,22 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source ${SCRIPT_DIR}/vars.sh echo "Getting relevant addresses..." -# Stride -STRIDE_VAL_ADDRESS=$($MAIN_STRIDE_CMD keys show ${STRIDE_VAL_PREFIX}1 --keyring-backend test -a) - -# Gaia -GAIA_VAL_ADDRESS=$($MAIN_GAIA_CMD keys show ${GAIA_VAL_PREFIX}1 --keyring-backend test -a) +STRIDE_ADDRESS=$($STRIDE_MAIN_CMD keys show ${STRIDE_VAL_PREFIX}1 --keyring-backend test -a) +GAIA_ADDRESS=$($GAIA_MAIN_CMD keys show ${GAIA_VAL_PREFIX}1 --keyring-backend test -a) +JUNO_ADDRESS=$($JUNO_MAIN_CMD keys show ${JUNO_VAL_PREFIX}1 --keyring-backend test -a) +OSMO_ADDRESS=$($OSMO_MAIN_CMD keys show ${OSMO_VAL_PREFIX}1 --keyring-backend test -a) # Relayers # NOTE: using $STRIDE_MAIN_CMD and $GAIA_MAIN_CMD here ONLY works because they rly1 and rly2 # keys are on stride1 and gaia1, respectively -RLY_ADDRESS_1=$($MAIN_STRIDE_CMD keys show rly1 --keyring-backend test -a) -RLY_ADDRESS_2=$($MAIN_GAIA_CMD keys show rly2 --keyring-backend test -a) +HERMES_STRIDE_ADDRESS=$($STRIDE_MAIN_CMD keys show $HERMES_STRIDE_ACCT --keyring-backend test -a) +HERMES_GAIA_ADDRESS=$($GAIA_MAIN_CMD keys show $HERMES_GAIA_ACCT --keyring-backend test -a) +HERMES_JUNO_ADDRESS=$($JUNO_MAIN_CMD keys show $HERMES_JUNO_ACCT --keyring-backend test -a) +HERMES_OSMO_ADDRESS=$($OSMO_MAIN_CMD keys show $HERMES_OSMO_ACCT --keyring-backend test -a) + +ICQ_STRIDE_ADDRESS=$($STRIDE_MAIN_CMD keys show $ICQ_STRIDE_ACCT --keyring-backend test -a) +ICQ_GAIA_ADDRESS=$($GAIA_MAIN_CMD keys show $ICQ_GAIA_ACCT --keyring-backend test -a) +ICQ_JUNO_ADDRESS=$($JUNO_MAIN_CMD keys show $ICQ_JUNO_ACCT --keyring-backend test -a) +ICQ_OSMO_ADDRESS=$($OSMO_MAIN_CMD keys show $ICQ_OSMO_ACCT --keyring-backend test -a) echo "Grabbed all data, running tests..." \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh index 8ed17041f..9bf2be6b7 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -6,50 +6,38 @@ source ${SCRIPT_DIR}/vars.sh BUILDDIR="$2" -# build docker images and local binaries -while getopts sghir flag; do - case "${flag}" in - s) echo "Building Stride Docker... "; - docker build --tag stridezone:stride -f Dockerfile.stride . ; - - printf '%s' "Building Stride Locally... "; - go build -mod=readonly -trimpath -o $BUILDDIR ./... ; - echo "Done" ;; - - g) echo "Building Gaia Docker... "; - docker build --tag stridezone:gaia -f Dockerfile.gaia . ; - - printf '%s' "Building Gaia Locally... "; - cd deps/gaia ; - go build -mod=readonly -trimpath -o $BUILDDIR ./... 2>&1 | grep -v -E "deprecated|keychain" || true ; - cd ../.. ; - echo "Done" ;; - - h) echo "Building Hermes Docker... "; - docker build --tag stridezone:hermes -f Dockerfile.hermes . ; +build_local_and_docker() { + module="$1" + folder="$2" + title=$(printf "$module" | awk '{ print toupper($0) }') + + echo "Building $title Docker... " + docker build --tag stridezone:$module -f Dockerfile.$module . + + printf '%s' "Building $title Locally... " + cwd=$PWD + cd $folder + go build -mod=readonly -trimpath -o $BUILDDIR ./... 2>&1 | grep -v -E "deprecated|keychain" || true ; + cd $cwd + echo "Done" +} - printf '%s' "Building Hermes Locally... "; - cd deps/hermes; - cargo build --release --target-dir $BUILDDIR/hermes; - cd ../.. - echo "Done" ;; - - i) echo "Building ICQ Docker... "; - docker build --tag stridezone:interchain-queries -f Dockerfile.icq . ; - - printf '%s' "Building ICQ Locally... "; - cd deps/interchain-queries; - go build -mod=readonly -trimpath -o $BUILDDIR ./... 2>&1 | grep -v -E "deprecated|keychain" || true; - cd ../.. - echo "Done" ;; - - r) echo "Building Relayer Docker... "; - docker build --tag stridezone:relayer -f Dockerfile.relayer . ; - - printf '%s' "Building Relayer Locally... "; - cd deps/relayer; - go build -mod=readonly -trimpath -o $BUILDDIR ./... 2>&1 | grep -v -E "deprecated|keychain" || true; - cd ../.. - echo "Done" ;; - esac -done +# build docker images and local binaries +while getopts sgojhir flag; do + case "${flag}" in + s) build_local_and_docker stride . ;; + g) build_local_and_docker gaia deps/gaia ;; + j) build_local_and_docker juno deps/juno ;; + o) build_local_and_docker osmo deps/osmosis ;; + i) build_local_and_docker icq deps/interchain-queries ;; + r) build_local_and_docker relayer deps/relayer ;; + h) echo "Building Hermes Docker... "; + docker build --tag stridezone:hermes -f Dockerfile.hermes . ; + + printf '%s' "Building Hermes Locally... "; + cd deps/hermes; + cargo build --release --target-dir $BUILDDIR/hermes; + cd ../.. + echo "Done" ;; + esac +done \ No newline at end of file diff --git a/scripts/config/hermes_config.toml b/scripts/config/hermes_config.toml index dd8ce5a71..46db2999e 100644 --- a/scripts/config/hermes_config.toml +++ b/scripts/config/hermes_config.toml @@ -42,7 +42,7 @@ max_msg_num = 30 max_tx_size = 2097152 clock_drift = '5s' max_block_time = '10s' -trusting_period = '180s' +trusting_period = '119s' trust_threshold = { numerator = '1', denominator = '3' } address_type = { derivation = 'cosmos' } @@ -63,6 +63,48 @@ max_msg_num = 30 max_tx_size = 2097152 clock_drift = '5s' max_block_time = '10s' -trusting_period = '180s' +trusting_period = '119s' trust_threshold = { numerator = '1', denominator = '3' } address_type = { derivation = 'cosmos' } + +[[chains]] +id = 'JUNO' +rpc_addr = 'http://juno1:26657' +grpc_addr = 'http://juno1:9090' +websocket_addr = 'ws://juno1:26657/websocket' +rpc_timeout = '10s' +account_prefix = 'juno' +key_name = 'rly3' +store_prefix = 'ibc' +default_gas = 100000 +max_gas = 3000000 +gas_price = { price = 0.000, denom = 'ujuno' } +gas_multiplier = 1.1 +max_msg_num = 30 +max_tx_size = 2097152 +clock_drift = '5s' +max_block_time = '10s' +trusting_period = '119s' +trust_threshold = { numerator = '1', denominator = '3' } +address_type = { derivation = 'cosmos' } + +[[chains]] +id = 'OSMO' +rpc_addr = 'http://osmo1:26657' +grpc_addr = 'http://osmo1:9090' +websocket_addr = 'ws://osmo1:26657/websocket' +rpc_timeout = '10s' +account_prefix = 'osmo' +key_name = 'rly4' +store_prefix = 'ibc' +default_gas = 100000 +max_gas = 3000000 +gas_price = { price = 0.000, denom = 'uosmo' } +gas_multiplier = 1.1 +max_msg_num = 30 +max_tx_size = 2097152 +clock_drift = '5s' +max_block_time = '10s' +trusting_period = '119s' +trust_threshold = { numerator = '1', denominator = '3' } +address_type = { derivation = 'cosmos' } \ No newline at end of file diff --git a/scripts/config/ica.json b/scripts/config/ica.json new file mode 100644 index 000000000..97f1ef688 --- /dev/null +++ b/scripts/config/ica.json @@ -0,0 +1,31 @@ +{ + "interchainaccounts": { + "controller_genesis_state": { + "active_channels": [], + "interchain_accounts": [], + "ports": [], + "params": { + "controller_enabled": true + } + }, + "host_genesis_state": { + "active_channels": [], + "interchain_accounts": [], + "port": "icahost", + "params": { + "host_enabled": true, + "allow_messages": [ + "/cosmos.bank.v1beta1.MsgSend", + "/cosmos.bank.v1beta1.MsgMultiSend", + "/cosmos.staking.v1beta1.MsgDelegate", + "/cosmos.staking.v1beta1.MsgUndelegate", + "/cosmos.staking.v1beta1.MsgRedeemTokensforShares", + "/cosmos.staking.v1beta1.MsgTokenizeShares", + "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", + "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", + "/ibc.applications.transfer.v1.MsgTransfer" + ] + } + } + } +} \ No newline at end of file diff --git a/scripts/config/icq_config.yaml b/scripts/config/icq_config.yaml index 0533b9bdf..120fac414 100644 --- a/scripts/config/icq_config.yaml +++ b/scripts/config/icq_config.yaml @@ -28,3 +28,31 @@ chains: block-timeout: "" output-format: json sign-mode: direct + juno: + key: icq3 + chain-id: JUNO + rpc-addr: http://juno1:26657 + grpc-addr: http://juno1:9090 + account-prefix: juno + keyring-backend: test + gas-adjustment: 1.2 + gas-prices: 1ujuno + debug: false + timeout: 20s + block-timeout: "" + output-format: json + sign-mode: direct + osmo: + key: icq4 + chain-id: OSMO + rpc-addr: http://osmo1:26657 + grpc-addr: http://osmo1:9090 + account-prefix: osmo + keyring-backend: test + gas-adjustment: 1.2 + gas-prices: 1uosmo + debug: false + timeout: 20s + block-timeout: "" + output-format: json + sign-mode: direct diff --git a/scripts/config/relayer_config.yaml b/scripts/config/relayer_config.yaml index 48e410458..cfe7ff1cf 100644 --- a/scripts/config/relayer_config.yaml +++ b/scripts/config/relayer_config.yaml @@ -32,4 +32,56 @@ chains: timeout: 20s output-format: json sign-mode: direct -paths: {} + juno: + type: cosmos + value: + key: rly3 + chain-id: JUNO + rpc-addr: http://juno1:26657 + account-prefix: juno + keyring-backend: test + gas-adjustment: 1.2 + gas-prices: 0.01ujuno + debug: false + timeout: 20s + output-format: json + sign-mode: direct + osmo: + type: cosmos + value: + key: rly4 + chain-id: OSMO + rpc-addr: http://osmo1:26657 + account-prefix: osmo + keyring-backend: test + gas-adjustment: 1.2 + gas-prices: 0.01uosmo + debug: false + timeout: 20s + output-format: json + sign-mode: direct +paths: + stride-gaia: + src: + chain-id: STRIDE + dst: + chain-id: GAIA + src-channel-filter: + rule: "" + channel-list: [] + stride-osmo: + src: + chain-id: STRIDE + dst: + chain-id: OSMO + src-channel-filter: + rule: "" + channel-list: [] + stride-juno: + src: + chain-id: STRIDE + dst: + chain-id: JUNO + src-channel-filter: + rule: "" + channel-list: [] diff --git a/scripts/create_channels.sh b/scripts/create_channels.sh new file mode 100644 index 000000000..95f8417aa --- /dev/null +++ b/scripts/create_channels.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -eu +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +source ${SCRIPT_DIR}/vars.sh + +HOST_CHAINS="$@" +HERMES_LOGS=$SCRIPT_DIR/logs/hermes.log + +for host_chain in ${HOST_CHAINS[@]}; do + echo "Creating connection STRIDE <> $host_chain..." | tee -a $HERMES_LOGS + $HERMES_EXEC create connection --a-chain $STRIDE_CHAIN_ID --b-chain $host_chain | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" >> $HERMES_LOGS 2>&1 + echo "Done" + + echo "Creating transfer channel STRIDE <> $host_chain..." | tee -a $HERMES_LOGS + $HERMES_EXEC create channel --a-chain $host_chain --a-connection connection-0 --a-port transfer --b-port transfer | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" >> $HERMES_LOGS 2>&1 + echo "Done" +done diff --git a/scripts/create_logs.sh b/scripts/create_logs.sh index 3bd5c74da..7bc4d866d 100755 --- a/scripts/create_logs.sh +++ b/scripts/create_logs.sh @@ -12,8 +12,8 @@ mkdir -p $TEMP_LOGS_DIR while true; do # transactions logs - $MAIN_STRIDE_CMD q txs --events message.module=interchainquery --limit=100000 >$TEMP_LOGS_DIR/icq-events.log - $MAIN_STRIDE_CMD q txs --events message.module=stakeibc --limit=100000 >$TEMP_LOGS_DIR/stakeibc-events.log + $STRIDE_MAIN_CMD q txs --events message.module=interchainquery --limit=100000 >$TEMP_LOGS_DIR/icq-events.log + $STRIDE_MAIN_CMD q txs --events message.module=stakeibc --limit=100000 >$TEMP_LOGS_DIR/stakeibc-events.log # accounts GAIA_DELEGATE="cosmos1sy63lffevueudvvlvh2lf6s387xh9xq72n3fsy6n2gr5hm6u2szs2v0ujm" @@ -22,37 +22,37 @@ while true; do GAIA_REV="cosmos1wdplq6qjh2xruc7qqagma9ya665q6qhcwju3ng" STRIDE_ADDRESS="stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7" - N_VALIDATORS_STRIDE=$($MAIN_STRIDE_CMD q tendermint-validator-set | grep -o address | wc -l | tr -dc '0-9') - N_VALIDATORS_GAIA=$($MAIN_GAIA_CMD q tendermint-validator-set | grep -o address | wc -l | tr -dc '0-9') - echo "STRIDE @ $($MAIN_STRIDE_CMD q tendermint-validator-set | head -n 1 | tr -dc '0-9') | $N_VALIDATORS_STRIDE VALS" >$TEMP_LOGS_DIR/accounts.log - echo "GAIA @ $($MAIN_GAIA_CMD q tendermint-validator-set | head -n 1 | tr -dc '0-9') | $N_VALIDATORS_GAIA VALS" >>$TEMP_LOGS_DIR/accounts.log + N_VALIDATORS_STRIDE=$($STRIDE_MAIN_CMD q tendermint-validator-set | grep -o address | wc -l | tr -dc '0-9') + N_VALIDATORS_GAIA=$($GAIA_MAIN_CMD q tendermint-validator-set | grep -o address | wc -l | tr -dc '0-9') + echo "STRIDE @ $($STRIDE_MAIN_CMD q tendermint-validator-set | head -n 1 | tr -dc '0-9') | $N_VALIDATORS_STRIDE VALS" >$TEMP_LOGS_DIR/accounts.log + echo "GAIA @ $($GAIA_MAIN_CMD q tendermint-validator-set | head -n 1 | tr -dc '0-9') | $N_VALIDATORS_GAIA VALS" >>$TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "BALANCES STRIDE" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_STRIDE_CMD q bank balances $STRIDE_ADDRESS >>$TEMP_LOGS_DIR/accounts.log + $STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS >>$TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "BALANCES GAIA (DELEGATION ACCT)" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_GAIA_CMD q bank balances $GAIA_DELEGATE >>$TEMP_LOGS_DIR/accounts.log + $GAIA_MAIN_CMD q bank balances $GAIA_DELEGATE >>$TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "DELEGATIONS GAIA (DELEGATION ACCT)" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_GAIA_CMD q staking delegations $GAIA_DELEGATE >>$TEMP_LOGS_DIR/accounts.log + $GAIA_MAIN_CMD q staking delegations $GAIA_DELEGATE >>$TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "UNBONDING-DELEGATIONS GAIA (DELEGATION ACCT)" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_GAIA_CMD q staking unbonding-delegations $GAIA_DELEGATE >>$TEMP_LOGS_DIR/accounts.log + $GAIA_MAIN_CMD q staking unbonding-delegations $GAIA_DELEGATE >>$TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "BALANCES GAIA (REDEMPTION ACCT)" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_GAIA_CMD q bank balances $GAIA_REDEMPTION >>$TEMP_LOGS_DIR/accounts.log + $GAIA_MAIN_CMD q bank balances $GAIA_REDEMPTION >>$TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "BALANCES GAIA (REVENUE ACCT)" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_GAIA_CMD q bank balances $GAIA_REV >>$TEMP_LOGS_DIR/accounts.log + $GAIA_MAIN_CMD q bank balances $GAIA_REV >>$TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "BALANCES GAIA (WITHDRAWAL ACCT)" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_GAIA_CMD q bank balances $GAIA_WITHDRAWAL >>$TEMP_LOGS_DIR/accounts.log + $GAIA_MAIN_CMD q bank balances $GAIA_WITHDRAWAL >>$TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "LIST-HOST-ZONES STRIDE" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_STRIDE_CMD q stakeibc list-host-zone | head -n 40 >>$TEMP_LOGS_DIR/accounts.log + $STRIDE_MAIN_CMD q stakeibc list-host-zone >>$TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "LIST-DEPOSIT-RECORDS" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_STRIDE_CMD q records list-deposit-record >> $TEMP_LOGS_DIR/accounts.log + $STRIDE_MAIN_CMD q records list-deposit-record >> $TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "LIST-EPOCH-UNBONDING-RECORDS" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_STRIDE_CMD q records list-epoch-unbonding-record >> $TEMP_LOGS_DIR/accounts.log + $STRIDE_MAIN_CMD q records list-epoch-unbonding-record >> $TEMP_LOGS_DIR/accounts.log printf '\n%s\n' "LIST-USER-REDEMPTION-RECORDS" >>$TEMP_LOGS_DIR/accounts.log - $MAIN_STRIDE_CMD q records list-user-redemption-record >> $TEMP_LOGS_DIR/accounts.log + $STRIDE_MAIN_CMD q records list-user-redemption-record >> $TEMP_LOGS_DIR/accounts.log mv $TEMP_LOGS_DIR/*.log $LOGS_DIR sleep 3 -done +done \ No newline at end of file diff --git a/scripts/init_gaia.sh b/scripts/init_chain.sh similarity index 52% rename from scripts/init_gaia.sh rename to scripts/init_chain.sh index 0300e74aa..9e1567b0a 100644 --- a/scripts/init_gaia.sh +++ b/scripts/init_chain.sh @@ -5,18 +5,52 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source $SCRIPT_DIR/vars.sh -CHAIN_ID=$GAIA_CHAIN_ID -CMD=$GAIA_CMD -DENOM=$GAIA_DENOM -RPC_PORT=$GAIA_RPC_PORT -NUM_NODES=$GAIA_NUM_NODES -NODE_PREFIX=$GAIA_NODE_PREFIX -VAL_PREFIX=$GAIA_VAL_PREFIX - -HERMES_ACCT=$HERMES_GAIA_ACCT -HERMES_MNEMONIC=$HERMES_GAIA_MNEMONIC -ICQ_ACCT=$ICQ_GAIA_ACCT -ICQ_MNEMONIC=$ICQ_GAIA_MNEMONIC +CHAIN_ID="$1" +KEYS_LOGS=$SCRIPT_DIR/logs/keys.log + +CMD=$(GET_VAR_VALUE ${CHAIN_ID}_CMD) +DENOM=$(GET_VAR_VALUE ${CHAIN_ID}_DENOM) +RPC_PORT=$(GET_VAR_VALUE ${CHAIN_ID}_RPC_PORT) +NUM_NODES=$(GET_VAR_VALUE ${CHAIN_ID}_NUM_NODES) +NODE_PREFIX=$(GET_VAR_VALUE ${CHAIN_ID}_NODE_PREFIX) +VAL_PREFIX=$(GET_VAR_VALUE ${CHAIN_ID}_VAL_PREFIX) + +VAL_MNEMONICS_VAR=${CHAIN_ID}_VAL_MNEMONICS +IFS=',' read -r -a VAL_MNEMONICS <<< "${!VAL_MNEMONICS_VAR}" + +HERMES_ACCT=$(GET_VAR_VALUE HERMES_${CHAIN_ID}_ACCT) +HERMES_MNEMONIC=$(GET_VAR_VALUE HERMES_${CHAIN_ID}_MNEMONIC) +ICQ_ACCT=$(GET_VAR_VALUE ICQ_${CHAIN_ID}_ACCT) +ICQ_MNEMONIC=$(GET_VAR_VALUE ICQ_${CHAIN_ID}_MNEMONIC) + +REV_ACCT_VAR=${CHAIN_ID}_REV_ACCT +REV_MNEMONIC_VAR=${CHAIN_ID}_REV_MNEMONIC + +set_stride_genesis() { + genesis_config=$1 + + # update params + jq '(.app_state.epochs.epochs[] | select(.identifier=="day") ).duration = $epochLen' --arg epochLen $STRIDE_DAY_EPOCH_DURATION $genesis_config > json.tmp && mv json.tmp $genesis_config + jq '(.app_state.epochs.epochs[] | select(.identifier=="stride_epoch") ).duration = $epochLen' --arg epochLen $STRIDE_EPOCH_EPOCH_DURATION $genesis_config > json.tmp && mv json.tmp $genesis_config + jq '.app_state.staking.params.unbonding_time = $newVal' --arg newVal "$UNBONDING_TIME" $genesis_config > json.tmp && mv json.tmp $genesis_config + jq '.app_state.gov.deposit_params.max_deposit_period = $newVal' --arg newVal "$MAX_DEPOSIT_PERIOD" $genesis_config > json.tmp && mv json.tmp $genesis_config + jq '.app_state.gov.voting_params.voting_period = $newVal' --arg newVal "$VOTING_PERIOD" $genesis_config > json.tmp && mv json.tmp $genesis_config +} + +set_host_genesis() { + genesis_config=$1 + + # Shorten epochs and unbonding time + jq '(.app_state.epochs.epochs[]? | select(.identifier=="day") ).duration = $epochLen' --arg epochLen $HOST_DAY_EPOCH_DURATION $genesis_config > json.tmp && mv json.tmp $genesis_config + jq '(.app_state.epochs.epochs[]? | select(.identifier=="hour") ).duration = $epochLen' --arg epochLen $HOST_HOUR_EPOCH_DURATION $genesis_config > json.tmp && mv json.tmp $genesis_config + jq '(.app_state.epochs.epochs[]? | select(.identifier=="week") ).duration = $epochLen' --arg epochLen $HOST_WEEK_EPOCH_DURATION $genesis_config > json.tmp && mv json.tmp $genesis_config + jq '.app_state.staking.params.unbonding_time = $newVal' --arg newVal "$UNBONDING_TIME" $genesis_config > json.tmp && mv json.tmp $genesis_config + + # Add interchain accounts to the genesis set + jq "del(.app_state.interchain_accounts)" $genesis_config > json.tmp && mv json.tmp $genesis_config + interchain_accts=$(cat $SCRIPT_DIR/config/ica.json) + jq ".app_state += $interchain_accts" $genesis_config > json.tmp && mv json.tmp $genesis_config +} MAIN_ID=1 # Node responsible for genesis and persistent_peers MAIN_NODE_NAME="" @@ -24,7 +58,7 @@ MAIN_NODE_CMD="" MAIN_NODE_ID="" MAIN_CONFIG="" MAIN_GENESIS="" -echo 'Initializing gaia chain...' +echo "Initializing $CHAIN_ID chain..." for (( i=1; i <= $NUM_NODES; i++ )); do # Node names will be of the form: "stride-node1" node_name="${NODE_PREFIX}${i}" @@ -34,7 +68,7 @@ for (( i=1; i <= $NUM_NODES; i++ )); do # Create a state directory for the current node and initialize the chain mkdir -p $STATE/$node_name cmd="$CMD --home ${STATE}/$node_name" - $cmd init $moniker --chain-id $CHAIN_ID --overwrite 2> /dev/null + $cmd init $moniker --chain-id $CHAIN_ID --overwrite &> /dev/null # Update node networking configuration config_toml="${STATE}/${node_name}/config/config.toml" @@ -63,13 +97,13 @@ for (( i=1; i <= $NUM_NODES; i++ )); do # add a validator account val_acct="${VAL_PREFIX}${i}" - val_mnemonic="${GAIA_VAL_MNEMONICS[((i-1))]}" - echo "$val_mnemonic" | $cmd keys add $val_acct --recover --keyring-backend=test + val_mnemonic="${VAL_MNEMONICS[((i-1))]}" + echo "$val_mnemonic" | $cmd keys add $val_acct --recover --keyring-backend=test >> $KEYS_LOGS 2>&1 val_addr=$($cmd keys show $val_acct --keyring-backend test -a) # Add this account to the current node $cmd add-genesis-account ${val_addr} ${VAL_TOKENS}${DENOM} # actually set this account as a validator on the current node - $cmd gentx $val_acct ${STAKE_TOKENS}${DENOM} --chain-id $CHAIN_ID --keyring-backend test 2> /dev/null + $cmd gentx $val_acct ${STAKE_TOKENS}${DENOM} --chain-id $CHAIN_ID --keyring-backend test &> /dev/null # Cleanup from seds rm -rf ${client_toml}-E @@ -88,13 +122,13 @@ for (( i=1; i <= $NUM_NODES; i++ )); do cp ${STATE}/${node_name}/config/gentx/*.json ${STATE}/${MAIN_NODE_NAME}/config/gentx/ # and add each validator's keys to the first state directory - echo "$val_mnemonic" | $MAIN_NODE_CMD keys add $val_acct --recover --keyring-backend=test + echo "$val_mnemonic" | $MAIN_NODE_CMD keys add $val_acct --recover --keyring-backend=test &> /dev/null fi done # add Hermes and ICQ relayer accounts on Stride -echo "$HERMES_MNEMONIC" | $MAIN_NODE_CMD keys add $HERMES_ACCT --recover --keyring-backend=test -echo "$ICQ_MNEMONIC" | $MAIN_NODE_CMD keys add $ICQ_ACCT --recover --keyring-backend=test +echo "$HERMES_MNEMONIC" | $MAIN_NODE_CMD keys add $HERMES_ACCT --recover --keyring-backend=test >> $KEYS_LOGS 2>&1 +echo "$ICQ_MNEMONIC" | $MAIN_NODE_CMD keys add $ICQ_ACCT --recover --keyring-backend=test >> $KEYS_LOGS 2>&1 HERMES_ADDRESS=$($MAIN_NODE_CMD keys show $HERMES_ACCT --keyring-backend test -a) ICQ_ADDRESS=$($MAIN_NODE_CMD keys show $ICQ_ACCT --keyring-backend test -a) @@ -102,16 +136,30 @@ ICQ_ADDRESS=$($MAIN_NODE_CMD keys show $ICQ_ACCT --keyring-backend test -a) $MAIN_NODE_CMD add-genesis-account ${HERMES_ADDRESS} ${VAL_TOKENS}${DENOM} $MAIN_NODE_CMD add-genesis-account ${ICQ_ADDRESS} ${VAL_TOKENS}${DENOM} +if [ "$CHAIN_ID" == "$STRIDE_CHAIN_ID" ]; then + # add the stride admin account + echo "$STRIDE_ADMIN_MNEMONIC" | $MAIN_NODE_CMD keys add $STRIDE_ADMIN_ACCT --recover --keyring-backend=test >> $KEYS_LOGS 2>&1 + STRIDE_ADMIN_ADDRESS=$($MAIN_NODE_CMD keys show $STRIDE_ADMIN_ACCT --keyring-backend test -a) + $MAIN_NODE_CMD add-genesis-account ${STRIDE_ADMIN_ADDRESS} ${ADMIN_TOKENS}${DENOM} +else + # add a revenue account + REV_ACCT=${!REV_ACCT_VAR} + REV_MNEMONIC=${!REV_MNEMONIC_VAR} + echo $REV_MNEMONIC | $MAIN_NODE_CMD keys add $REV_ACCT --recover --keyring-backend=test >> $KEYS_LOGS 2>&1 +fi + # now we process gentx txs on the main node -$MAIN_NODE_CMD collect-gentxs 2> /dev/null +$MAIN_NODE_CMD collect-gentxs &> /dev/null # wipe out the persistent peers for the main node (these are incorrectly autogenerated for each validator during collect-gentxs) sed -i -E "s|persistent_peers = .*|persistent_peers = \"\"|g" $MAIN_CONFIG -## add the message types ICA should allow to the host chain -ALLOW_MESSAGES='\"/cosmos.bank.v1beta1.MsgSend\", \"/cosmos.bank.v1beta1.MsgMultiSend\", \"/cosmos.staking.v1beta1.MsgDelegate\", \"/cosmos.staking.v1beta1.MsgUndelegate\", \"/cosmos.staking.v1beta1.MsgRedeemTokensforShares\", \"/cosmos.staking.v1beta1.MsgTokenizeShares\", \"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward\", \"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress\", \"/ibc.applications.transfer.v1.MsgTransfer\"' -sed -i -E "s|\"allow_messages\": \[\]|\"allow_messages\": \[${ALLOW_MESSAGES}\]|g" $MAIN_GENESIS -jq '.app_state.staking.params.unbonding_time = $newVal' --arg newVal "$UNBONDING_TIME" $MAIN_GENESIS > json.tmp && mv json.tmp $MAIN_GENESIS +# update chian-specific genesis settings +if [ "$CHAIN_ID" == "$STRIDE_CHAIN_ID" ]; then + set_stride_genesis $MAIN_GENESIS +else + set_host_genesis $MAIN_GENESIS +fi # for all peer nodes.... for (( i=2; i <= $NUM_NODES; i++ )); do @@ -129,4 +177,4 @@ done # Cleanup from seds rm -rf ${MAIN_CONFIG}-E -rm -rf ${MAIN_GENESIS}-E +rm -rf ${MAIN_GENESIS}-E \ No newline at end of file diff --git a/scripts/init_relayers.sh b/scripts/init_relayers.sh index 3165e7092..58c8481e8 100644 --- a/scripts/init_relayers.sh +++ b/scripts/init_relayers.sh @@ -5,6 +5,13 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source ${SCRIPT_DIR}/vars.sh +# Pass chain IDs as arguments +CHAINS="$@" +if [[ "$CHAINS" == "" ]]; then + echo "ERROR: Please specify at least chain IDs that require a relayer connection" + exit 1 +fi + mkdir -p $STATE/hermes mkdir -p $STATE/icq mkdir -p $STATE/relayer/config @@ -15,20 +22,29 @@ cp ${SCRIPT_DIR}/config/relayer_config.yaml $STATE/relayer/config/config.yaml echo "Adding Hermes keys" TMP_MNEMONICS=${SCRIPT_DIR}/state/mnemonic.txt +for chain_id in ${CHAINS[@]}; do + account_name=$(GET_VAR_VALUE HERMES_${chain_id}_ACCT) + mnemonic=$(GET_VAR_VALUE HERMES_${chain_id}_MNEMONIC) -echo "$HERMES_STRIDE_MNEMONIC" > $TMP_MNEMONICS -$HERMES_CMD keys add --key-name rly1 --chain $STRIDE_CHAIN_ID --mnemonic-file $TMP_MNEMONICS --overwrite - -echo "$HERMES_GAIA_MNEMONIC" > $TMP_MNEMONICS -$HERMES_CMD keys add --key-name rly2 --chain $GAIA_CHAIN_ID --mnemonic-file $TMP_MNEMONICS --overwrite - + echo "$mnemonic" > $TMP_MNEMONICS + $HERMES_CMD keys add --key-name $account_name --chain $STRIDE_CHAIN_ID --mnemonic-file $TMP_MNEMONICS --overwrite +done rm -f $TMP_MNEMONICS -# echo "Adding Relayer keys" -# $RELAYER_CMD keys restore stride rly1 "$RELAYER_STRIDE_MNEMONIC" -# $RELAYER_CMD keys restore gaia rly2 "$RELAYER_GAIA_MNEMONIC" -# $RELAYER_CMD paths new $STRIDE_CHAIN_ID $GAIA_CHAIN_ID stride-gaia +echo "Adding Relayer keys" +for chain_id in ${CHAINS[@]}; do + account_name=$(GET_VAR_VALUE RELAYER_${chain_id}_ACCT) + mnemonic=$(GET_VAR_VALUE RELAYER_${chain_id}_MNEMONIC) + chain_name=$(printf "$chain_id" | awk '{ print tolower($0) }') + + $RELAYER_CMD keys restore $chain_name $account_name "$mnemonic" +done echo "Adding ICQ keys" -echo $ICQ_STRIDE_MNEMONIC | $ICQ_CMD keys restore icq1 --chain stride -echo $ICQ_GAIA_MNEMONIC | $ICQ_CMD keys restore icq2 --chain gaia +for chain_id in ${CHAINS[@]}; do + account_name=$(GET_VAR_VALUE ICQ_${chain_id}_ACCT) + mnemonic=$(GET_VAR_VALUE ICQ_${chain_id}_MNEMONIC) + chain_name=$(printf "$chain_id" | awk '{ print tolower($0) }') + + echo $mnemonic | $ICQ_CMD keys restore $account_name --chain $chain_name +done \ No newline at end of file diff --git a/scripts/init_stride.sh b/scripts/init_stride.sh deleted file mode 100755 index 97933195e..000000000 --- a/scripts/init_stride.sh +++ /dev/null @@ -1,140 +0,0 @@ -#!/bin/bash - -set -eu -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - -source $SCRIPT_DIR/vars.sh - -CHAIN_ID=$STRIDE_CHAIN_ID -CMD=$STRIDE_CMD -DENOM=$STRIDE_DENOM -RPC_PORT=$STRIDE_RPC_PORT -NUM_NODES=$STRIDE_NUM_NODES -NODE_PREFIX=$STRIDE_NODE_PREFIX -VAL_PREFIX=$STRIDE_VAL_PREFIX - -ADMIN_ACCT=$STRIDE_ADMIN_ACCT -HERMES_ACCT=$HERMES_STRIDE_ACCT -HERMES_MNEMONIC=$HERMES_STRIDE_MNEMONIC -ICQ_ACCT=$ICQ_STRIDE_ACCT -ICQ_MNEMONIC=$ICQ_STRIDE_MNEMONIC - -MAIN_ID=1 # Node responsible for genesis and persistent_peers -MAIN_NODE_NAME="" -MAIN_NODE_CMD="" -MAIN_NODE_ID="" -MAIN_CONFIG="" -MAIN_GENESIS="" -echo 'Initializing stride chain...' -for (( i=1; i <= $NUM_NODES; i++ )); do - # Node names will be of the form: "stride-node1" - node_name="${NODE_PREFIX}${i}" - # Moniker is of the form: STRIDE_1 - moniker=$(printf "${NODE_PREFIX}_${i}" | awk '{ print toupper($0) }') - - # Create a state directory for the current node and initialize the chain - mkdir -p $STATE/$node_name - cmd="$CMD --home ${STATE}/$node_name" - $cmd init $moniker --chain-id $CHAIN_ID --overwrite 2> /dev/null - - # Update node networking configuration - config_toml="${STATE}/${node_name}/config/config.toml" - client_toml="${STATE}/${node_name}/config/client.toml" - app_toml="${STATE}/${node_name}/config/app.toml" - genesis_json="${STATE}/${node_name}/config/genesis.json" - - sed -i -E "s|cors_allowed_origins = \[\]|cors_allowed_origins = [\"\*\"]|g" $config_toml - sed -i -E "s|127.0.0.1|0.0.0.0|g" $config_toml - sed -i -E "s|timeout_commit = \"5s\"|timeout_commit = \"${BLOCK_TIME}\"|g" $config_toml - sed -i -E "s|prometheus = false|prometheus = true|g" $config_toml - - sed -i -E "s|minimum-gas-prices = \".*\"|minimum-gas-prices = \"0${DENOM}\"|g" $app_toml - sed -i -E '/\[api\]/,/^enable = .*$/ s/^enable = .*$/enable = true/' $app_toml - sed -i -E 's|unsafe-cors = .*|unsafe-cors = true|g' $app_toml - - sed -i -E "s|chain-id = \"\"|chain-id = \"${CHAIN_ID}\"|g" $client_toml - sed -i -E "s|keyring-backend = \"os\"|keyring-backend = \"test\"|g" $client_toml - sed -i -E "s|node = \".*\"|node = \"tcp://localhost:$RPC_PORT\"|g" $client_toml - - sed -i -E "s|\"stake\"|\"${DENOM}\"|g" $genesis_json - - # Get the endpoint and node ID - node_id=$($cmd tendermint show-node-id)@$node_name:$PEER_PORT - echo "Node #$i ID: $node_id" - - # add a validator account - val_acct="${VAL_PREFIX}${i}" - val_mnemonic="${STRIDE_VAL_MNEMONICS[((i-1))]}" - echo "$val_mnemonic" | $cmd keys add $val_acct --recover --keyring-backend=test - val_addr=$($cmd keys show $val_acct --keyring-backend test -a) - # Add this account to the current node - $cmd add-genesis-account ${val_addr} ${VAL_TOKENS}${DENOM} - # actually set this account as a validator on the current node - $cmd gentx $val_acct ${STAKE_TOKENS}${DENOM} --chain-id $CHAIN_ID --keyring-backend test 2> /dev/null - - # Cleanup from seds - rm -rf ${client_toml}-E - rm -rf ${genesis_json}-E - rm -rf ${app_toml}-E - - if [ $i -eq $MAIN_ID ]; then - MAIN_NODE_NAME=$node_name - MAIN_NODE_CMD=$cmd - MAIN_NODE_ID=$node_id - MAIN_CONFIG=$config_toml - MAIN_GENESIS=$genesis_json - else - # also add this account and it's genesis tx to the main node - $MAIN_NODE_CMD add-genesis-account ${val_addr} ${VAL_TOKENS}${DENOM} - cp ${STATE}/${node_name}/config/gentx/*.json ${STATE}/${MAIN_NODE_NAME}/config/gentx/ - - # and add each validator's keys to the first state directory - echo "$val_mnemonic" | $MAIN_NODE_CMD keys add $val_acct --recover --keyring-backend=test - fi -done - -# add Hermes and ICQ relayer accounts on Stride -echo "$HERMES_MNEMONIC" | $MAIN_NODE_CMD keys add $HERMES_ACCT --recover --keyring-backend=test -echo "$ICQ_MNEMONIC" | $MAIN_NODE_CMD keys add $ICQ_ACCT --recover --keyring-backend=test -HERMES_ADDRESS=$($MAIN_NODE_CMD keys show $HERMES_ACCT --keyring-backend test -a) -ICQ_ADDRESS=$($MAIN_NODE_CMD keys show $ICQ_ACCT --keyring-backend test -a) - -# give relayer accounts token balances -$MAIN_NODE_CMD add-genesis-account ${HERMES_ADDRESS} ${VAL_TOKENS}${DENOM} -$MAIN_NODE_CMD add-genesis-account ${ICQ_ADDRESS} ${VAL_TOKENS}${DENOM} - -# Add the stride admin account -echo "$STRIDE_ADMIN_MNEMONIC" | $MAIN_NODE_CMD keys add $ADMIN_ACCT --recover --keyring-backend=test -ADMIN_ADDRESS=$($MAIN_NODE_CMD keys show $ADMIN_ACCT --keyring-backend test -a) -$MAIN_NODE_CMD add-genesis-account ${ADMIN_ADDRESS} ${ADMIN_TOKENS}${DENOM} - -# now we process gentx txs on the main node -$MAIN_NODE_CMD collect-gentxs 2> /dev/null - -# wipe out the persistent peers for the main node (these are incorrectly autogenerated for each validator during collect-gentxs) -sed -i -E "s|persistent_peers = .*|persistent_peers = \"\"|g" $MAIN_CONFIG - -# modify our params -jq '.app_state.epochs.epochs[$epochIndex].duration = $epochLen' --arg epochLen $DAY_EPOCH_DURATION --argjson epochIndex $DAY_EPOCH_INDEX $MAIN_GENESIS > json.tmp && mv json.tmp $MAIN_GENESIS -jq '.app_state.epochs.epochs[$epochIndex].duration = $epochLen' --arg epochLen $STRIDE_EPOCH_DURATION --argjson epochIndex $STRIDE_EPOCH_INDEX $MAIN_GENESIS > json.tmp && mv json.tmp $MAIN_GENESIS -jq '.app_state.staking.params.unbonding_time = $newVal' --arg newVal "$UNBONDING_TIME" $MAIN_GENESIS > json.tmp && mv json.tmp $MAIN_GENESIS -jq '.app_state.gov.deposit_params.max_deposit_period = $newVal' --arg newVal "$MAX_DEPOSIT_PERIOD" $MAIN_GENESIS > json.tmp && mv json.tmp $MAIN_GENESIS -jq '.app_state.gov.voting_params.voting_period = $newVal' --arg newVal "$VOTING_PERIOD" $MAIN_GENESIS > json.tmp && mv json.tmp $MAIN_GENESIS - -# for all peer nodes.... -for (( i=2; i <= $NUM_NODES; i++ )); do - node_name="${NODE_PREFIX}${i}" - config_toml="${STATE}/${node_name}/config/config.toml" - genesis_json="${STATE}/${node_name}/config/genesis.json" - - # add the main node as a persistent peer - sed -i -E "s|persistent_peers = .*|persistent_peers = \"${MAIN_NODE_ID}\"|g" $config_toml - # copy the main node's genesis to the peer nodes to ensure they all have the same genesis - cp $MAIN_GENESIS $genesis_json - - rm -rf ${config_toml}-E -done - -# Cleanup from seds -rm -rf ${MAIN_CONFIG}-E -rm -rf ${MAIN_GENESIS}-E diff --git a/scripts/register_host.sh b/scripts/register_host.sh index 9df45d119..d6f5af265 100644 --- a/scripts/register_host.sh +++ b/scripts/register_host.sh @@ -4,31 +4,38 @@ set -eu SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source $SCRIPT_DIR/vars.sh +CHAIN_ID="$1" +CONNECTION="$2" +CHANNEL="$3" + +MAIN_CMD=$(GET_VAR_VALUE ${CHAIN_ID}_MAIN_CMD) +VAL_PREFIX=$(GET_VAR_VALUE ${CHAIN_ID}_VAL_PREFIX) +IBC_DENOM=$(GET_VAR_VALUE ${CHAIN_ID}_IBC_DENOM) +HOST_DENOM=$(GET_VAR_VALUE ${CHAIN_ID}_DENOM) +ADDRESS_PREFIX=$(GET_VAR_VALUE ${CHAIN_ID}_ADDRESS_PREFIX) + # Get validator addresses -GAIA_VAL_2_ADDR="$($MAIN_GAIA_CMD keys show gval2 -a)" -GAIA_VAL_3_ADDR="$($MAIN_GAIA_CMD keys show gval3 -a)" -GAIA_DELEGATE_VAL_1="$($MAIN_GAIA_CMD q staking validators | grep GAIA_1 -A 5 | grep operator | awk '{print $2}')" -GAIA_DELEGATE_VAL_2="$($MAIN_GAIA_CMD q staking validators | grep GAIA_2 -A 5 | grep operator | awk '{print $2}')" - -# Submit a transaction on stride to register the gaia host zone -printf "\nCreating host zone...\n" -$MAIN_STRIDE_CMD tx stakeibc register-host-zone \ - connection-0 $ATOM_DENOM cosmos $IBC_ATOM_DENOM channel-0 1 \ - --from $STRIDE_ADMIN_ACCT --gas 1000000 --home $SCRIPT_DIR/state/stride1 -y -CSLEEP 10 - -printf "\nRegistering validators...\n" -$MAIN_STRIDE_CMD tx stakeibc add-validator $GAIA_CHAIN_ID gval1 $GAIA_DELEGATE_VAL_1 10 5 --from $STRIDE_ADMIN_ACCT -y -CSLEEP 10 -$MAIN_STRIDE_CMD tx stakeibc add-validator $GAIA_CHAIN_ID gval2 $GAIA_DELEGATE_VAL_2 10 10 --from $STRIDE_ADMIN_ACCT -y -CSLEEP 10 - -# sleep a while longer to wait for ICA accounts to set up -printf "\nWaiting for ICA accounts on host..." +DELEGATE_VAL_1="$($MAIN_CMD q staking validators | grep ${CHAIN_ID}_1 -A 5 | grep operator | awk '{print $2}')" +DELEGATE_VAL_2="$($MAIN_CMD q staking validators | grep ${CHAIN_ID}_2 -A 5 | grep operator | awk '{print $2}')" + +echo "$CHAIN_ID - Registering host zone..." +$STRIDE_MAIN_CMD tx stakeibc register-host-zone \ + $CONNECTION $HOST_DENOM $ADDRESS_PREFIX $IBC_DENOM $CHANNEL 1 \ + --gas 1000000 --from $STRIDE_ADMIN_ACCT --home $SCRIPT_DIR/state/stride1 -y | grep -E "code:|txhash:" | sed 's/^/ /' +sleep 4 + +echo "$CHAIN_ID - Registering validators..." +$STRIDE_MAIN_CMD tx stakeibc add-validator $CHAIN_ID ${VAL_PREFIX}1 $DELEGATE_VAL_1 10 5 \ + --from $STRIDE_ADMIN_ACCT -y | grep -E "code:|txhash:" | sed 's/^/ /' +sleep 4 + +$STRIDE_MAIN_CMD tx stakeibc add-validator $CHAIN_ID ${VAL_PREFIX}2 $DELEGATE_VAL_2 10 10 \ + --from $STRIDE_ADMIN_ACCT -y | grep -E "code:|txhash:" | sed 's/^/ /' +sleep 4 + while true; do - if ! $MAIN_STRIDE_CMD q stakeibc list-host-zone | grep Account | grep -q null; then - sleep 5 + if ! $STRIDE_MAIN_CMD q stakeibc list-host-zone | grep Account | grep -q null; then + sleep 1 break fi -done -echo "Done" \ No newline at end of file +done \ No newline at end of file diff --git a/scripts/start_chain.sh b/scripts/start_chain.sh new file mode 100644 index 000000000..64d566815 --- /dev/null +++ b/scripts/start_chain.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +set -eu +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +source ${SCRIPT_DIR}/vars.sh + +# Pass the CHAIN_ID's of the chains to start +CHAINS="$@" +if [[ "$CHAINS" == "" ]]; then + echo "ERROR: Please specify chain IDs to start" + exit 1 +fi + +for chain_id in ${CHAINS[@]}; do + num_nodes=$(GET_VAR_VALUE ${chain_id}_NUM_NODES) + node_prefix=$(GET_VAR_VALUE ${chain_id}_NODE_PREFIX) + + log_file=$SCRIPT_DIR/logs/${node_prefix}.log + + echo "Starting $chain_id chain" + nodes_names=$(i=1; while [ $i -le $num_nodes ]; do printf "%s " ${node_prefix}${i}; i=$(($i + 1)); done;) + docker-compose up -d $nodes_names + + docker-compose logs -f ${node_prefix}1 | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $log_file 2>&1 & +done + +for chain_id in ${CHAINS[@]}; do + printf "Waiting for $chain_id to start..." + + node_prefix=$(GET_VAR_VALUE ${chain_id}_NODE_PREFIX) + log_file=$SCRIPT_DIR/logs/${node_prefix}.log + + ( tail -f -n0 $log_file & ) | grep -q "finalizing commit of block" + echo "Done" +done + +sleep 5 \ No newline at end of file diff --git a/scripts/start_network.sh b/scripts/start_network.sh index 7ed8f3d56..c36065ed5 100755 --- a/scripts/start_network.sh +++ b/scripts/start_network.sh @@ -5,47 +5,23 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) source ${SCRIPT_DIR}/vars.sh # cleanup any stale state -make stop-docker +docker-compose down rm -rf $SCRIPT_DIR/state $SCRIPT_DIR/logs/*.log $SCRIPT_DIR/logs/temp +mkdir -p $SCRIPT_DIR/logs -STRIDE_LOGS=$SCRIPT_DIR/logs/stride.log -GAIA_LOGS=$SCRIPT_DIR/logs/gaia.log HERMES_LOGS=$SCRIPT_DIR/logs/hermes.log ICQ_LOGS=$SCRIPT_DIR/logs/icq.log # Initialize the state for stride/gaia and relayers -sh ${SCRIPT_DIR}/init_stride.sh -sh ${SCRIPT_DIR}/init_gaia.sh -sh ${SCRIPT_DIR}/init_relayers.sh +sh ${SCRIPT_DIR}/init_chain.sh STRIDE +sh ${SCRIPT_DIR}/init_chain.sh GAIA +sh ${SCRIPT_DIR}/init_chain.sh JUNO +sh ${SCRIPT_DIR}/init_chain.sh OSMO -echo "Starting STRIDE chain" -stride_nodes=$(i=1; while [ $i -le $STRIDE_NUM_NODES ]; do printf "%s " stride$i; i=$(($i + 1)); done;) -docker-compose up -d $stride_nodes - -echo "Starting GAIA chain" -gaia_nodes=$(i=1; while [ $i -le $GAIA_NUM_NODES ]; do printf "%s " gaia$i; i=$(($i + 1)); done;) -docker-compose up -d $gaia_nodes - -docker-compose logs -f stride1 | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $STRIDE_LOGS 2>&1 & -docker-compose logs -f gaia1 | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $GAIA_LOGS 2>&1 & - -printf "Waiting for STRIDE and GAIA to start..." -( tail -f -n0 $STRIDE_LOGS & ) | grep -q "finalizing commit of block" -( tail -f -n0 $GAIA_LOGS & ) | grep -q "finalizing commit of block" -sleep 5 -echo "Done" - -printf "Creating connection..." -$HERMES_EXEC create connection --a-chain $STRIDE_CHAIN_ID --b-chain $GAIA_CHAIN_ID | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" >> $HERMES_LOGS 2>&1 -echo "Done" - -printf "Creating transfer channel..." -$HERMES_EXEC create channel --a-chain $GAIA_CHAIN_ID --a-connection connection-0 --a-port transfer --b-port transfer | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" >> $HERMES_LOGS 2>&1 -echo "Done" - -# printf "Creating clients, connections, and transfer channel" -# $RELAYER_EXEC transact link stride-gaia -# echo "DONE" +HOST_CHAINS=(GAIA JUNO OSMO) +sh ${SCRIPT_DIR}/start_chain.sh STRIDE ${HOST_CHAINS[@]} +sh ${SCRIPT_DIR}/init_relayers.sh STRIDE ${HOST_CHAINS[@]} +sh ${SCRIPT_DIR}/create_channels.sh ${HOST_CHAINS[@]} echo "Starting relayers" docker-compose up -d hermes icq @@ -53,6 +29,19 @@ docker-compose up -d hermes icq docker-compose logs -f hermes | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" >> $HERMES_LOGS 2>&1 & docker-compose logs -f icq | sed -r -u "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" > $ICQ_LOGS 2>&1 & -bash $SCRIPT_DIR/register_host.sh +# Wait for hermes to start +( tail -f -n0 $HERMES_LOGS & ) | grep -q -E "Hermes has started" + +# Register all host zones in parallel +pids=() +for i in ${!HOST_CHAINS[@]}; do + if [[ "$i" != "0" ]]; then sleep 20; fi + bash $SCRIPT_DIR/register_host.sh ${HOST_CHAINS[$i]} connection-${i} channel-${i} & + pids[${i}]=$! +done +for i in ${!pids[@]}; do + wait ${pids[$i]} + echo "${HOST_CHAINS[$i]} - Done" +done $SCRIPT_DIR/create_logs.sh & \ No newline at end of file diff --git a/scripts/test-util/1.sh b/scripts/test-util/1.sh new file mode 100644 index 000000000..78620298d --- /dev/null +++ b/scripts/test-util/1.sh @@ -0,0 +1,8 @@ +### IBC TRANSFER +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source ${SCRIPT_DIR}/../account_vars.sh + +## IBC ATOM from GAIA to STRIDE +$GAIA_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $STRIDE_ADDRESS 1000000uatom --from ${GAIA_VAL_PREFIX}1 -y +sleep 10 +$STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS \ No newline at end of file diff --git a/scripts/test-util/2.sh b/scripts/test-util/2.sh new file mode 100644 index 000000000..477ace43f --- /dev/null +++ b/scripts/test-util/2.sh @@ -0,0 +1,6 @@ +### LIQ STAKE +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +source ${SCRIPT_DIR}/../account_vars.sh + +$STRIDE_MAIN_CMD tx stakeibc liquid-stake 10000 $ATOM_DENOM --from ${STRIDE_VAL_PREFIX}1 -y \ No newline at end of file diff --git a/scripts/tests/1.sh b/scripts/tests/1.sh deleted file mode 100755 index 0d8517941..000000000 --- a/scripts/tests/1.sh +++ /dev/null @@ -1,11 +0,0 @@ -### IBC OVER TOKENS -GAIA1_EXEC="build/gaiad --home scripts-local/state/gaia" -STR1_EXEC="build/strided --home scripts-local/state/stride" -SCRIPT_DIR="./scripts-local/logs/" -STRIDE_ADDRESS="stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7" - -# ibc over atoms to stride -$GAIA1_EXEC tx ibc-transfer transfer transfer channel-0 $STRIDE_ADDRESS 100000uatom --from gval1 --chain-id GAIA -y --keyring-backend test -SLEEP 5 -$STR1_EXEC q bank balances $STRIDE_ADDRESS - diff --git a/scripts/tests/2.sh b/scripts/tests/2.sh deleted file mode 100755 index f5b00124a..000000000 --- a/scripts/tests/2.sh +++ /dev/null @@ -1,8 +0,0 @@ -### LIQ STAKE + EXCH RATE TEST -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -GAIA1_EXEC="build/gaiad --home scripts-local/state/gaia" -STR1_EXEC="build/strided --home scripts-local/state/stride" -SCRIPT_DIR="./scripts-local/logs/" -STRIDE_ADDRESS="stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7" - -$STR1_EXEC tx stakeibc liquid-stake 1000 uatom --keyring-backend test --from val1 -y --chain-id STRIDE \ No newline at end of file diff --git a/scripts/tests/3.sh b/scripts/tests/3.sh deleted file mode 100755 index b50a0a7bc..000000000 --- a/scripts/tests/3.sh +++ /dev/null @@ -1,33 +0,0 @@ -### LIQ STAKE + EXCH RATE TEST -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -# import dependencies -# source ${SCRIPT_DIR}/../account_vars.sh - -GAIA_DELEGATE="cosmos19l6d3d7k2pel8epgcpxc9np6fsvjpaaa06nm65vagwxap0e4jezq05mmvu" -GAIA_DELEGATE_VAL="cosmosvaloper19e7sugzt8zaamk2wyydzgmg9n3ysylg6na6k6e" -GAIA_WITHDRAWAL="cosmos1lcnmjwjy2lnqged5pnrc0cstz0r88rttunla4zxv84mee30g2q3q48fm53" -GAIA1_EXEC="docker-compose --ansi never exec -T gaia1 gaiad --home /gaia/.gaiad" - -GETSTAKE() { - tail -n 2 | head -n 1 | grep -o -E '[0-9]+' | head -n 1 - } - -# $STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 - -# $GAIA1_EXEC q bank balances $GAIA_WITHDRAWAL -# $GAIA1_EXEC q staking delegations $GAIA_WITHDRAWAL -# $GAIA1_EXEC q distribution rewards $GAIA_WITHDRAWAL - -# echo "-----------------------------" -$STR1_EXEC strided q stakeibc list-host-zone -# $GAIA1_EXEC q bank balances $GAIA_DELEGATE -# echo "-----------------------------" -# # $GAIA1_EXEC q staking delegation $GAIA_DELEGATE $GAIA_DELEGATE_VAL | GETSTAKE -# $GAIA1_EXEC q distribution rewards $GAIA_DELEGATE -# echo "-----------------------------" -# $GAIA1_EXEC q staking delegations $GAIA_DELEGATE # $GAIA_DELEGATE_VAL #| GETSTAKE -# $GAIA1_EXEC q staking delegation $GAIA_DELEGATE $GAIA_DELEGATE_VAL | GETSTAKE - -# $GAIA1_EXEC q bank balances $GAIA_DELEGATE -# $GAIA1_EXEC q staking delegations $GAIA_DELEGATE - # cosmos19l6d3d7k2pel8epgcpxc9np6fsvjpaaa06nm65vagwxap0e4jezq05mmvu cosmosvaloper19e7sugzt8zaamk2wyydzgmg9n3ysylg6na6k6e diff --git a/scripts/tests/basic_tests.bats b/scripts/tests/basic_tests.bats deleted file mode 100755 index f3479ccf2..000000000 --- a/scripts/tests/basic_tests.bats +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/env bats - -setup_file() { - # get the containing directory of this file - SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - PATH="$SCRIPT_DIR/../../:$PATH" - - # set allows us to export all variables in account_vars - set -a - source scripts/account_vars.sh - STRIDE_ADDR="stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7" - IBCSTRD='ibc/FF6C2E86490C1C4FBBD24F55032831D2415B9D7882F85C3CC9C2401D79362BEA' - IBCATOM='ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2' - DELEGATE_ADDR='cosmos19l6d3d7k2pel8epgcpxc9np6fsvjpaaa06nm65vagwxap0e4jezq05mmvu' - GAIA_DELEGATE_VAL='cosmosvaloper19e7sugzt8zaamk2wyydzgmg9n3ysylg6na6k6e' - STATOM="stuatom" - GETBAL() { - head -n 1 | grep -o -E '[0-9]+' - } - GETSTAKE() { - tail -n 2 | head -n 1 | grep -o -E '[0-9]+' | head -n 1 - } - INIT_STAKE=$($GAIA1_EXEC q staking delegation $DELEGATE_ADDR $GAIA_DELEGATE_VAL | GETSTAKE) - set +a -} - -setup() { - # get the containing directory of this file - SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - PATH="$SCRIPT_DIR/../../:$PATH" - - load 'test_helper/bats-support/load' - load 'test_helper/bats-assert/load' -} - -@test "proper initial address names" { - [[ $STRIDE_ADDRESS_1 == "stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7" ]] - assert_equal $STRIDE_ADDRESS_1 'stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7' - assert_equal $STRIDE_ADDRESS_2 'stride1ld5ewfgc3crml46n806km7djtr788vqdd5lnu5' - assert_equal $STRIDE_ADDRESS_3 'stride16vlrvd7lsfqg8q7kyxcyar9v7nt0h99p5arglq' - - assert_equal $GAIA_ADDRESS_1 'cosmos1pcag0cj4ttxg8l7pcg0q4ksuglswuuedcextl2' - assert_equal $GAIA_ADDRESS_2 'cosmos1t2aqq3c6mt8fa6l5ady44manvhqf77sywjcldv' - assert_equal $GAIA_ADDRESS_3 'cosmos19e7sugzt8zaamk2wyydzgmg9n3ysylg6kfwrk2' - - assert_equal $RLY_ADDRESS_1 'stride1ft20pydau82pgesyl9huhhux307s9h3078692y' - assert_equal $RLY_ADDRESS_2 'cosmos1uyrmx8zw0mxu7sdn58z29wnnqnxtqvvxqec074' -} - -@test "ibc transfer updates all balances" { - # get initial balances - str1_balance=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom ustrd | GETBAL) - gaia1_balance=$($GAIA1_EXEC q bank balances $GAIA_ADDRESS_1 --denom $IBCSTRD | GETBAL) - str1_balance_atom=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $IBCATOM | GETBAL) - gaia1_balance_atom=$($GAIA1_EXEC q bank balances $GAIA_ADDRESS_1 --denom uatom | GETBAL) - # do IBC transfer - $STRIDE1_EXEC tx ibc-transfer transfer transfer channel-0 $GAIA_ADDRESS_1 10000ustrd --from val1 --chain-id STRIDE -y --keyring-backend test - $GAIA1_EXEC tx ibc-transfer transfer transfer channel-0 $STRIDE_ADDRESS_1 10000uatom --from gval1 --chain-id GAIA -y --keyring-backend test - sleep 20 - # get new balances - str1_balance_new=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom ustrd | GETBAL) - gaia1_balance_new=$($GAIA1_EXEC q bank balances $GAIA_ADDRESS_1 --denom $IBCSTRD | GETBAL) - str1_balance_atom_new=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $IBCATOM | GETBAL) - gaia1_balance_atom_new=$($GAIA1_EXEC q bank balances $GAIA_ADDRESS_1 --denom uatom | GETBAL) - # get all STRD balance diffs - str1_diff=$(($str1_balance - $str1_balance_new)) - gaia1_diff=$(($gaia1_balance - $gaia1_balance_new)) - assert_equal "$str1_diff" '10000' - assert_equal "$gaia1_diff" '-10000' - # get all ATOM balance diffs - str1_diff=$(($str1_balance_atom - $str1_balance_atom_new)) - gaia1_diff=$(($gaia1_balance_atom - $gaia1_balance_atom_new)) - assert_equal "$str1_diff" '-10000' - assert_equal "$gaia1_diff" '10000' -} - -@test "liquid stake mints stATOM" { - # get module address - MODADDR=$($STRIDE1_EXEC q stakeibc module-address stakeibc | awk '{print $NF}') - # get initial balances - mod_balance_atom=$($STRIDE1_EXEC q bank balances $MODADDR --denom $IBCATOM | GETBAL) - str1_balance_atom=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $IBCATOM | GETBAL) - str1_balance_statom=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $STATOM | GETBAL) - # liquid stake - $STRIDE1_EXEC tx stakeibc liquid-stake 1000 uatom --keyring-backend test --from val1 -y - sleep 15 - # make sure Module Acct received ATOM - remove if IBC transfer is automated - # mod_balance_atom_new=$($STRIDE1_EXEC q bank balances $MODADDR --denom $IBCATOM | GETBAL) - # mod_atom_diff=$(($mod_balance_atom_new - $mod_balance_atom)) - # assert_equal "$mod_atom_diff" '1000' - # make sure IBCATOM went down - str1_balance_atom_new=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $IBCATOM | GETBAL) - str1_atom_diff=$(($str1_balance_atom - $str1_balance_atom_new)) - assert_equal "$str1_atom_diff" '1000' - # make sure STATOM went up - str1_balance_statom_new=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $STATOM | GETBAL) - str1_statom_diff=$(($str1_balance_statom_new-$str1_balance_statom)) - assert_equal "$str1_statom_diff" "1000" -} - -# add test to register host zone -@test "host zone successfully registered" { - run $STRIDE1_EXEC q stakeibc show-host-zone GAIA - assert_line ' HostDenom: uatom' - assert_line ' chainId: GAIA' - assert_line ' delegationAccount:' - assert_line ' address: cosmos19l6d3d7k2pel8epgcpxc9np6fsvjpaaa06nm65vagwxap0e4jezq05mmvu' -} - -# add test to see if assets are properly being staked on host zone -@test "tokens staking on host zone" { - # run below test once ICQ is deployed - sleep 60 - NEW_STAKE=$($GAIA1_EXEC q staking delegation $DELEGATE_ADDR $GAIA_DELEGATE_VAL | GETSTAKE) - stake_diff=$((($NEW_STAKE - $INIT_STAKE) > 0)) - assert_equal "$stake_diff" "1" -} - -# TEST-74 -# add test to see if assets are properly being staked on host zone -# add asset redemption test - -# @test "icq: exchange rate and delegated balance queries" { -# # Test: query exchange rate -# $STRIDE1_EXEC tx interchainquery query-exchangerate GAIA --keyring-backend test -y --from val1 -# sleep 15 -# run $STRIDE1_EXEC q txs --events message.action=/stride.interchainquery.MsgSubmitQueryResponse --limit=1 -# assert_line --partial 'key: redemptionRate' - -# # Test query delegated balance -# $STRIDE1_EXEC tx interchainquery query-delegatedbalance GAIA --keyring-backend test -y --from val1 -# sleep 15 -# run $STRIDE1_EXEC q txs --events message.action=/stride.interchainquery.MsgSubmitQueryResponse --limit=1 -# assert_line --partial 'key: totalDelegations' -# } - -@test "exchange rate" { - # Test: liquid stake - # TODO(VISHAL) write a proper test here -RR=$($STR1_EXEC q stakeibc list-host-zone | grep -Fiw 'RedemptionRate' | grep -Eo '[+-]?[0-9]+([.][0-9]+)?') -UDBAL=$($GAIA1_EXEC q bank balances $DELEGATE_ADDR | grep -Fiw 'amount:' | tr -dc '0-9') -DBAL=$($GAIA1_EXEC q staking delegations $DELEGATE_ADDR | grep -Fiw 'amount:' | grep -Eo '[+-]?[0-9]+([.][0-9]+)?') -STSUPPLY=$($STR1_EXEC q bank balances $STRIDE_ADDR | grep -Fiw 'stuatom' -B 1 | tr -dc '0-9') -BAL=$(( $UDBAL + $DBAL )) -echo $BAL"="$STSUPPLY"*"$RR -} - diff --git a/scripts/tests/gaia_tests.bats b/scripts/tests/gaia_tests.bats new file mode 100644 index 000000000..506d4186d --- /dev/null +++ b/scripts/tests/gaia_tests.bats @@ -0,0 +1,242 @@ +#!/usr/bin/env bats + +setup_file() { + # get the containing directory of this file + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + PATH="$SCRIPT_DIR/../../:$PATH" + + set allows us to export all variables in account_vars + set -a + source scripts/account_vars.sh + + GETBAL() { + head -n 1 | grep -o -E '[0-9]+' + } + GETSTAKE() { + tail -n 2 | head -n 1 | grep -o -E '[0-9]+' | head -n 1 + } + # HELPER FUNCTIONS + DECADD () { + echo "scale=2; $1+$2" | bc + } + DECMUL () { + echo "scale=2; $1*$2" | bc + } + FLOOR () { + printf "%.0f\n" $1 + } + CEIL () { + printf "%.0f\n" $(ADD $1 1) + } + set +a +} + +setup() { + # get the containing directory of this file + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + PATH="$SCRIPT_DIR/../../:$PATH" + + + # if these extensions don't load properly, adjust the paths accoring to these instructions + TEST_BREW_PREFIX="$(brew --prefix)" + load "${TEST_BREW_PREFIX}/lib/bats-support/load.bash" + load "${TEST_BREW_PREFIX}/lib/bats-assert/load.bash" +} + +############################################################################################## +###### HOW TO ###### +############################################################################################## +# Tests are written sequentially +# Each test depends on the previous tests, and examines the chain state at a point in time + +# To add a new test, take an action then sleep for seconds / blocks / IBC_TX_WAIT_SECONDS +# / epochs +# Reordering existing tests could break them + +############################################################################################## +###### SETUP TESTS ###### +############################################################################################## + +@test "[INTEGRATION-BASIC] address names are correct" { + assert_equal $STRIDE_ADDRESS "stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7" + assert_equal $GAIA_ADDRESS "cosmos1pcag0cj4ttxg8l7pcg0q4ksuglswuuedcextl2" + + assert_equal $DELEGATION_ICA_ADDR "cosmos1sy63lffevueudvvlvh2lf6s387xh9xq72n3fsy6n2gr5hm6u2szs2v0ujm" + assert_equal $REDEMPTION_ICA_ADDR "cosmos1xmcwu75s8v7s54k79390wc5gwtgkeqhvzegpj0nm2tdwacv47tmqg9ut30" + assert_equal $WITHDRAWAL_ICA_ADDR "cosmos1x5p8er7e2ne8l54tx33l560l8djuyapny55pksctuguzdc00dj7saqcw2l" + assert_equal $REVENUE_EOA_ADDR "cosmos1wdplq6qjh2xruc7qqagma9ya665q6qhcwju3ng" + assert_equal $FEE_ICA_ADDR "cosmos1lkgt5sfshn9shm7hd7chtytkq4mvwvswgmyl0hkacd4rmusu9wwq60cezx" + assert_equal $GAIA_DELEGATE_VAL_1 "cosmosvaloper1pcag0cj4ttxg8l7pcg0q4ksuglswuuedadj7ne" + assert_equal $GAIA_DELEGATE_VAL_2 "cosmosvaloper133lfs9gcpxqj6er3kx605e3v9lqp2pg5syhvsz" + assert_equal $GAIA_RECEIVER_ACCT "cosmos1g6qdx6kdhpf000afvvpte7hp0vnpzapuyxp8uf" + + assert_equal $JUNO_DELEGATE_VAL "junovaloper1pcag0cj4ttxg8l7pcg0q4ksuglswuued3knlr0" + assert_equal $JUNO_DELEGATION_ICA_ADDR 'juno1xan7vt4nurz6c7x0lnqnvpmuc0lljz7rycqmuz2kk6wxv4k69d0sfats35' + assert_equal $JUNO_REDEMPTION_ICA_ADDR 'juno1y6haxdt03cgkc7aedxrlaleeteel7fgc0nvtu2kggee3hnrlvnvs4kw2v9' + assert_equal $JUNO_WITHDRAWAL_ICA_ADDR 'juno104n6h822n6n7psqjgjl7emd2uz67lptggp5cargh6mw0gxpch2gsk53qk5' + assert_equal $JUNO_FEE_ICA_ADDR 'juno1rp8qgfq64wmjg7exyhjqrehnvww0t9ev3f3p2ls82umz2fxgylqsz3vl9h' + + assert_equal $OSMO_DELEGATE_VAL 'osmovaloper12ffkl30v0ghtyaezvedazquhtsf4q5ng8khuv4' + assert_equal $OSMO_DELEGATION_ICA_ADDR "osmo1cx04p5974f8hzh2lqev48kjrjugdxsxy7mzrd0eyweycpr90vk8q8d6f3h" + assert_equal $OSMO_REDEMPTION_ICA_ADDR "osmo1uy9p9g609676rflkjnnelaxatv8e4sd245snze7qsxzlk7dk7s8qrcjaez" + assert_equal $OSMO_WITHDRAWAL_ICA_ADDR "osmo10arcf5r89cdmppntzkvulc7gfmw5lr66y2m25c937t6ccfzk0cqqz2l6xv" + assert_equal $OSMO_FEE_ICA_ADDR "osmo1n4r77qsmu9chvchtmuqy9cv3s539q87r398l6ugf7dd2q5wgyg9su3wd4g" +} + +# # add test to register host zone +@test "[INTEGRATION-BASIC] host zones successfully registered" { + run $STRIDE_MAIN_CMD q stakeibc show-host-zone GAIA + assert_line ' HostDenom: uatom' + assert_line ' chainId: GAIA' + assert_line ' delegationAccount:' + assert_line ' address: cosmos1sy63lffevueudvvlvh2lf6s387xh9xq72n3fsy6n2gr5hm6u2szs2v0ujm' + assert_line ' feeAccount:' + assert_line ' address: cosmos1lkgt5sfshn9shm7hd7chtytkq4mvwvswgmyl0hkacd4rmusu9wwq60cezx' + assert_line ' redemptionAccount:' + assert_line ' address: cosmos1xmcwu75s8v7s54k79390wc5gwtgkeqhvzegpj0nm2tdwacv47tmqg9ut30' + assert_line ' withdrawalAccount:' + assert_line ' address: cosmos1x5p8er7e2ne8l54tx33l560l8djuyapny55pksctuguzdc00dj7saqcw2l' + assert_line ' unbondingFrequency: "1"' +} + + +############################################################################################## +###### TEST BASIC STRIDE FUNCTIONALITY ###### +############################################################################################## + + +@test "[INTEGRATION-BASIC-GAIA] ibc transfer updates all balances" { + # get initial balances + str1_balance=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom ustrd | GETBAL) + gaia1_balance=$($GAIA_MAIN_CMD q bank balances $GAIA_ADDRESS --denom $IBC_STRD_DENOM | GETBAL) + str1_balance_atom=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_ATOM_DENOM | GETBAL) + gaia1_balance_atom=$($GAIA_MAIN_CMD q bank balances $GAIA_ADDRESS --denom uatom | GETBAL) + # do IBC transfer + $STRIDE_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $GAIA_ADDRESS 3000ustrd --from val1 --chain-id STRIDE -y --keyring-backend test & + $GAIA_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $STRIDE_ADDRESS 3000uatom --from gval1 --chain-id GAIA -y --keyring-backend test & + WAIT_FOR_BLOCK $STRIDE_LOGS 8 + # get new balances + str1_balance_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom ustrd | GETBAL) + gaia1_balance_new=$($GAIA_MAIN_CMD q bank balances $GAIA_ADDRESS --denom $IBC_STRD_DENOM | GETBAL) + str1_balance_atom_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_ATOM_DENOM | GETBAL) + gaia1_balance_atom_new=$($GAIA_MAIN_CMD q bank balances $GAIA_ADDRESS --denom uatom | GETBAL) + # get all STRD balance diffs + str1_diff=$(($str1_balance - $str1_balance_new)) + gaia1_diff=$(($gaia1_balance - $gaia1_balance_new)) + assert_equal "$str1_diff" '3000' + assert_equal "$gaia1_diff" '-3000' + # get all ATOM_DENOM balance diffs + str1_diff=$(($str1_balance_atom - $str1_balance_atom_new)) + gaia1_diff=$(($gaia1_balance_atom - $gaia1_balance_atom_new)) + assert_equal "$str1_diff" '-3000' + assert_equal "$gaia1_diff" '3000' +} + +@test "[INTEGRATION-BASIC-GAIA] liquid stake mints stATOM" { + # get module address + MODADDR=$($STRIDE_MAIN_CMD q stakeibc module-address stakeibc | awk '{print $NF}') + # get initial balances + mod_balance_atom=$($STRIDE_MAIN_CMD q bank balances $MODADDR --denom $IBC_ATOM_DENOM | GETBAL) + str1_balance_atom=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_ATOM_DENOM | GETBAL) + str1_balance_statom=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $STATOM_DENOM | GETBAL) + # liquid stake + $STRIDE_MAIN_CMD tx stakeibc liquid-stake 1000 uatom --keyring-backend test --from val1 -y --chain-id $STRIDE_CHAIN_ID + # sleep two block for the tx to settle on stride + WAIT_FOR_STRING $STRIDE_LOGS '\[MINT ST ASSET\] success on GAIA' + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # make sure IBC_ATOM_DENOM went down + str1_balance_atom_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_ATOM_DENOM | GETBAL) + str1_atom_diff=$(($str1_balance_atom - $str1_balance_atom_new)) + assert_equal "$str1_atom_diff" '1000' + # make sure STATOM went up + str1_balance_statom_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $STATOM_DENOM | GETBAL) + str1_statom_diff=$(($str1_balance_statom_new-$str1_balance_statom)) + assert_equal "$str1_statom_diff" "1000" +} + +# check that tokens were transferred to GAIA +@test "[INTEGRATION-BASIC-GAIA] tokens were transferred to GAIA after liquid staking" { + # initial balance of delegation ICA + initial_delegation_ica_bal=$($GAIA_MAIN_CMD q bank balances $DELEGATION_ICA_ADDR --denom uatom | GETBAL) + WAIT_FOR_STRING $STRIDE_LOGS '\[IBC-TRANSFER\] success to GAIA' + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # get the new delegation ICA balance + post_delegation_ica_bal=$($GAIA_MAIN_CMD q bank balances $DELEGATION_ICA_ADDR --denom uatom | GETBAL) + diff=$(($post_delegation_ica_bal - $initial_delegation_ica_bal)) + assert_equal "$diff" '1000' +} + +# check that tokens on GAIA are staked +@test "[INTEGRATION-BASIC-GAIA] tokens on GAIA were staked" { + # wait for another epoch to pass so that tokens are staked + WAIT_FOR_STRING $STRIDE_LOGS '\[DELEGATION\] success on GAIA' + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # check staked tokens + NEW_STAKE=$($GAIA_MAIN_CMD q staking delegation $DELEGATION_ICA_ADDR $GAIA_DELEGATE_VAL_1 | GETSTAKE) + stake_diff=$(($NEW_STAKE > 0)) + assert_equal "$stake_diff" "1" +} + +# check that redemptions and claims work +@test "[INTEGRATION-BASIC-GAIA] redemption works" { + old_redemption_ica_bal=$($GAIA_MAIN_CMD q bank balances $REDEMPTION_ICA_ADDR --denom uatom | GETBAL) + # call redeem-stake + amt_to_redeem=100 + $STRIDE_MAIN_CMD tx stakeibc redeem-stake $amt_to_redeem GAIA $GAIA_RECEIVER_ACCT \ + --from val1 --keyring-backend test --chain-id $STRIDE_CHAIN_ID -y + WAIT_FOR_STRING $STRIDE_LOGS '\[REDEMPTION] completed on GAIA' + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # check that the tokens were transferred to the redemption account + new_redemption_ica_bal=$($GAIA_MAIN_CMD q bank balances $REDEMPTION_ICA_ADDR --denom uatom | GETBAL) + diff_positive=$(($new_redemption_ica_bal > $old_redemption_ica_bal)) + assert_equal "$diff_positive" "1" +} + +@test "[INTEGRATION-BASIC-GAIA] claimed tokens are properly distributed" { + # TODO(optimize tests) extra sleep just in case + SENDER_ACCT=$STRIDE_ADDRESS + old_sender_bal=$($GAIA_MAIN_CMD q bank balances $GAIA_RECEIVER_ACCT --denom uatom | GETBAL) + # TODO check that the UserRedemptionRecord has isClaimable = true + + # grab the epoch number for the first deposit record in the list od DRs + EPOCH=$(strided q records list-user-redemption-record | grep -Fiw 'epochNumber' | head -n 1 | grep -o -E '[0-9]+') + # claim the record + $STRIDE_MAIN_CMD tx stakeibc claim-undelegated-tokens GAIA $EPOCH $SENDER_ACCT --from val1 --keyring-backend test --chain-id STRIDE -y + WAIT_FOR_STRING $STRIDE_LOGS '\[CLAIM\] success on GAIA' + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + + # check that the tokens were transferred to the sender account + new_sender_bal=$($GAIA_MAIN_CMD q bank balances $GAIA_RECEIVER_ACCT --denom uatom | GETBAL) + + # check that the undelegated tokens were transfered to the sender account + diff_positive=$(($new_sender_bal > $old_sender_bal)) + assert_equal "$diff_positive" "1" +} + + +# check that a second liquid staking call kicks off reinvestment +@test "[INTEGRATION-BASIC-GAIA] rewards are being reinvested, exchange rate updating" { + # read the exchange rate and current delegations + RR1=$($STRIDE_MAIN_CMD q stakeibc show-host-zone GAIA | grep -Fiw 'RedemptionRate' | grep -Eo '[+-]?[0-9]+([.][0-9]+)?') + OLD_STAKED_BAL=$($GAIA_MAIN_CMD q staking delegation $DELEGATION_ICA_ADDR $GAIA_DELEGATE_VAL_1 | GETSTAKE) + # liquid stake again to kickstart the reinvestment process + $STRIDE_MAIN_CMD tx stakeibc liquid-stake 1000 uatom --keyring-backend test --from val1 -y --chain-id $STRIDE_CHAIN_ID + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # wait four days (transfers, stake, move rewards, reinvest rewards) + epoch_duration=$($STRIDE_MAIN_CMD q epochs epoch-infos | grep -Fiw -B 2 'stride_epoch' | head -n 1 | grep -o -E '[0-9]+') + sleep $(($epoch_duration * 4)) + # simple check that number of tokens staked increases + NEW_STAKED_BAL=$($GAIA_MAIN_CMD q staking delegation $DELEGATION_ICA_ADDR $GAIA_DELEGATE_VAL_1 | GETSTAKE) + STAKED_BAL_INCREASED=$(($NEW_STAKED_BAL > $OLD_STAKED_BAL)) + assert_equal "$STAKED_BAL_INCREASED" "1" + + RR2=$($STRIDE_MAIN_CMD q stakeibc show-host-zone GAIA | grep -Fiw 'RedemptionRate' | grep -Eo '[+-]?[0-9]+([.][0-9]+)?') + # check that the exchange rate has increased + MULT=1000000 + RR_INCREASED=$(( $(FLOOR $(DECMUL $RR2 $MULT)) > $(FLOOR $(DECMUL $RR1 $MULT)))) + assert_equal "$RR_INCREASED" "1" +} + +# TODO check that the correct amount is being reinvested and the correct amount is flowing to the rev EOA +@test "[NOT-IMPLEMENTED] reinvestment and revenue amounts are correct" { +} diff --git a/scripts/tests/ica_redeem.sh b/scripts/tests/ica_redeem.sh deleted file mode 100755 index ff928cf79..000000000 --- a/scripts/tests/ica_redeem.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -echo "Register zone" -# setup logic on controller zone -$STRIDE1_EXEC tx stakeibc register-host-zone \ - connection-0 uatom cosmos ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9 channel-0 --chain-id \ - STRIDE --home /stride/.strided --keyring-backend test \ - --from val1 --gas 500000 -y - -echo "Sleeping for 30s" -sleep 30 - -echo "Host zones" -# store the delegate account -$STRIDE1_EXEC q stakeibc list-host-zone - -# host zone accounts -# gaiad keys list --home /gaia/.gaiad --keyring-backend test -# TODO(TEST-58): make this dynamic -VAL_KEY=cosmos1pcag0cj4ttxg8l7pcg0q4ksuglswuuedcextl2 -DELEGATION_ADDR=cosmos10ltqave0ml70h9ynfsp6py2pv925xuzys7ypmffr8ud92sj09dzs6xtq8e - -echo "Transferring tokens from $VAL_KEY to $DELEGATION_ADDR" -# transfer tokens to delegate account on the host zone -$GAIA1_EXEC tx bank send $VAL_KEY $DELEGATION_ADDR 100uatom --chain-id GAIA_1 --home /gaia/.gaiad --keyring-backend test -y - -echo "Sleeping for 14s" -# wait 2 blocks -sleep 14 - -echo "Balance before staking" -# check balances -$GAIA1_EXEC q bank balances cosmos10ltqave0ml70h9ynfsp6py2pv925xuzys7ypmffr8ud92sj09dzs6xtq8e --home /gaia/.gaiad - -echo "Sleeping for 14s" -# wait 4 blocks -sleep 30 - -echo "Balance after staking" -# check balances -$GAIA1_EXEC q bank balances cosmos10ltqave0ml70h9ynfsp6py2pv925xuzys7ypmffr8ud92sj09dzs6xtq8e --home /gaia/.gaiad - -# check that tokens were staked after 10 blocks -$GAIA1_EXEC q staking delegations cosmos10ltqave0ml70h9ynfsp6py2pv925xuzys7ypmffr8ud92sj09dzs6xtq8e - - -# redeem stAssets for native tokens -$STRIDE1_EXEC tx stakeibc redeem-stake 1 statom \ - --chain-id STRIDE_1 --home /stride/.strided --keyring-backend test \ - --from val1 --gas 500000 -y - -# query unbonding delegations, should reflect 1uatom -gaiad q staking unbonding-delegations $DELEGATION_ADDR diff --git a/scripts/tests/juno_tests.bats b/scripts/tests/juno_tests.bats new file mode 100644 index 000000000..32e60a846 --- /dev/null +++ b/scripts/tests/juno_tests.bats @@ -0,0 +1,238 @@ +#!/usr/bin/env bats + +setup_file() { + # get the containing directory of this file + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + PATH="$SCRIPT_DIR/../../:$PATH" + + # set allows us to export all variables in account_vars + set -a + source scripts/account_vars.sh + + GETBAL() { + head -n 1 | grep -o -E '[0-9]+' + } + GETSTAKE() { + tail -n 2 | head -n 1 | grep -o -E '[0-9]+' | head -n 1 + } + # HELPER FUNCTIONS + DECADD () { + echo "scale=2; $1+$2" | bc + } + DECMUL () { + echo "scale=2; $1*$2" | bc + } + FLOOR () { + printf "%.0f\n" $1 + } + CEIL () { + printf "%.0f\n" $(ADD $1 1) + } + set +a +} + +setup() { + # get the containing directory of this file + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + PATH="$SCRIPT_DIR/../../:$PATH" + + + # if these extensions don't load properly, adjust the paths accoring to these instructions + TEST_BREW_PREFIX="$(brew --prefix)" + load "${TEST_BREW_PREFIX}/lib/bats-support/load.bash" + load "${TEST_BREW_PREFIX}/lib/bats-assert/load.bash" +} + +############################################################################################## +###### HOW TO ###### +############################################################################################## +# Tests are written sequentially +# Each test depends on the previous tests, and examines the chain state at a point in time + +# To add a new test, take an action then sleep for seconds / blocks / IBC_TX_WAIT_SECONDS +# / epochs +# Reordering existing tests could break them + +############################################################################################## +###### SETUP TESTS ###### +############################################################################################## + +@test "[INTEGRATION-BASIC] address names are correct" { + assert_equal $STRIDE_ADDRESS "stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7" + assert_equal $GAIA_ADDRESS "cosmos1pcag0cj4ttxg8l7pcg0q4ksuglswuuedcextl2" + + assert_equal $DELEGATION_ICA_ADDR "cosmos1sy63lffevueudvvlvh2lf6s387xh9xq72n3fsy6n2gr5hm6u2szs2v0ujm" + assert_equal $REDEMPTION_ICA_ADDR "cosmos1xmcwu75s8v7s54k79390wc5gwtgkeqhvzegpj0nm2tdwacv47tmqg9ut30" + assert_equal $WITHDRAWAL_ICA_ADDR "cosmos1x5p8er7e2ne8l54tx33l560l8djuyapny55pksctuguzdc00dj7saqcw2l" + assert_equal $REVENUE_EOA_ADDR "cosmos1wdplq6qjh2xruc7qqagma9ya665q6qhcwju3ng" + assert_equal $FEE_ICA_ADDR "cosmos1lkgt5sfshn9shm7hd7chtytkq4mvwvswgmyl0hkacd4rmusu9wwq60cezx" + assert_equal $GAIA_DELEGATE_VAL_1 "cosmosvaloper1pcag0cj4ttxg8l7pcg0q4ksuglswuuedadj7ne" + assert_equal $GAIA_DELEGATE_VAL_2 "cosmosvaloper133lfs9gcpxqj6er3kx605e3v9lqp2pg5syhvsz" + assert_equal $GAIA_RECEIVER_ACCT "cosmos1g6qdx6kdhpf000afvvpte7hp0vnpzapuyxp8uf" + + assert_equal $JUNO_DELEGATE_VAL "junovaloper1pcag0cj4ttxg8l7pcg0q4ksuglswuued3knlr0" + assert_equal $JUNO_DELEGATION_ICA_ADDR 'juno1xan7vt4nurz6c7x0lnqnvpmuc0lljz7rycqmuz2kk6wxv4k69d0sfats35' + assert_equal $JUNO_REDEMPTION_ICA_ADDR 'juno1y6haxdt03cgkc7aedxrlaleeteel7fgc0nvtu2kggee3hnrlvnvs4kw2v9' + assert_equal $JUNO_WITHDRAWAL_ICA_ADDR 'juno104n6h822n6n7psqjgjl7emd2uz67lptggp5cargh6mw0gxpch2gsk53qk5' + assert_equal $JUNO_FEE_ICA_ADDR 'juno1rp8qgfq64wmjg7exyhjqrehnvww0t9ev3f3p2ls82umz2fxgylqsz3vl9h' + + assert_equal $OSMO_DELEGATE_VAL 'osmovaloper12ffkl30v0ghtyaezvedazquhtsf4q5ng8khuv4' + assert_equal $OSMO_DELEGATION_ICA_ADDR "osmo1cx04p5974f8hzh2lqev48kjrjugdxsxy7mzrd0eyweycpr90vk8q8d6f3h" + assert_equal $OSMO_REDEMPTION_ICA_ADDR "osmo1uy9p9g609676rflkjnnelaxatv8e4sd245snze7qsxzlk7dk7s8qrcjaez" + assert_equal $OSMO_WITHDRAWAL_ICA_ADDR "osmo10arcf5r89cdmppntzkvulc7gfmw5lr66y2m25c937t6ccfzk0cqqz2l6xv" + assert_equal $OSMO_FEE_ICA_ADDR "osmo1n4r77qsmu9chvchtmuqy9cv3s539q87r398l6ugf7dd2q5wgyg9su3wd4g" +} + +# # add test to register host zone +@test "[INTEGRATION-BASIC] host zones successfully registered" { + run $STRIDE_MAIN_CMD q stakeibc show-host-zone JUNO + assert_line ' HostDenom: ujuno' + assert_line ' chainId: JUNO' + assert_line ' delegationAccount:' + assert_line ' address: juno1xan7vt4nurz6c7x0lnqnvpmuc0lljz7rycqmuz2kk6wxv4k69d0sfats35' + assert_line ' feeAccount:' + assert_line ' address: juno1rp8qgfq64wmjg7exyhjqrehnvww0t9ev3f3p2ls82umz2fxgylqsz3vl9h' + assert_line ' redemptionAccount:' + assert_line ' address: juno1y6haxdt03cgkc7aedxrlaleeteel7fgc0nvtu2kggee3hnrlvnvs4kw2v9' + assert_line ' withdrawalAccount:' + assert_line ' address: juno104n6h822n6n7psqjgjl7emd2uz67lptggp5cargh6mw0gxpch2gsk53qk5' + assert_line ' unbondingFrequency: "1"' + assert_line ' RedemptionRate: "1.000000000000000000"' +} + + +############################################################################################## +###### TEST BASIC STRIDE FUNCTIONALITY ###### +############################################################################################## + +@test "[INTEGRATION-BASIC-JUNO] ibc transfer updates all balances" { + # get initial balances + str1_balance=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom ustrd | GETBAL) + juno1_balance=$($JUNO_MAIN_CMD q bank balances $JUNO_ADDRESS --denom $IBC_STRD_DENOM | GETBAL) + str1_balance_juno=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_JUNO_DENOM | GETBAL) + juno1_balance_juno=$($JUNO_MAIN_CMD q bank balances $JUNO_ADDRESS --denom ujuno | GETBAL) + # do IBC transfer + $STRIDE_MAIN_CMD tx ibc-transfer transfer transfer channel-1 $JUNO_ADDRESS 100000000ustrd --from val1 --chain-id STRIDE -y --keyring-backend test + $JUNO_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $STRIDE_ADDRESS 100000000ujuno --from jval1 --chain-id JUNO -y --keyring-backend test + WAIT_FOR_BLOCK $STRIDE_LOGS 8 + # get new balances + str1_balance_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom ustrd | GETBAL) + juno1_balance_new=$($JUNO_MAIN_CMD q bank balances $JUNO_ADDRESS --denom $IBC_STRD_DENOM | GETBAL) + str1_balance_juno_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_JUNO_DENOM | GETBAL) + juno1_balance_juno_new=$($JUNO_MAIN_CMD q bank balances $JUNO_ADDRESS --denom ujuno | GETBAL) + # get all STRD balance diffs + str1_diff=$(($str1_balance - $str1_balance_new)) + juno1_diff=$(($juno1_balance - $juno1_balance_new)) + assert_equal "$str1_diff" '100000000' + assert_equal "$juno1_diff" '-100000000' + # get all JUNO_DENOM balance diffs + str1_diff=$(($str1_balance_juno - $str1_balance_juno_new)) + juno1_diff=$(($juno1_balance_juno - $juno1_balance_juno_new)) + assert_equal "$str1_diff" '-100000000' + assert_equal "$juno1_diff" '100000000' +} + +@test "[INTEGRATION-BASIC-JUNO] liquid stake mints stJUNO" { + # get module address + MODADDR=$($STRIDE_MAIN_CMD q stakeibc module-address stakeibc | awk '{print $NF}') + # get initial balances + mod_balance_juno=$($STRIDE_MAIN_CMD q bank balances $MODADDR --denom $IBC_JUNO_DENOM | GETBAL) + str1_balance_juno=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_JUNO_DENOM | GETBAL) + str1_balance_stjuno=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $STJUNO_DENOM | GETBAL) + # liquid stake + $STRIDE_MAIN_CMD tx stakeibc liquid-stake 10000000 ujuno --keyring-backend test --from val1 -y --chain-id $STRIDE_CHAIN_ID + # sleep two block for the tx to settle on stride + WAIT_FOR_STRING $STRIDE_LOGS '\[MINT ST ASSET\] success on JUNO' + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # make sure IBC_JUNO_DENOM went down + str1_balance_juno_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_JUNO_DENOM | GETBAL) + str1_juno_diff=$(($str1_balance_juno - $str1_balance_juno_new)) + assert_equal "$str1_juno_diff" '10000000' + # make sure STJUNO went up + str1_balance_stjuno_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $STJUNO_DENOM | GETBAL) + str1_stjuno_diff=$(($str1_balance_stjuno_new-$str1_balance_stjuno)) + assert_equal "$str1_stjuno_diff" "10000000" +} + +@test "[INTEGRATION-BASIC-JUNO] tokens were transferred to JUNO after liquid staking" { + # initial balance of delegation ICA + initial_delegation_ica_bal=$($JUNO_MAIN_CMD q bank balances $JUNO_DELEGATION_ICA_ADDR --denom ujuno | GETBAL) + WAIT_FOR_STRING $STRIDE_LOGS '\[IBC-TRANSFER\] success to JUNO' + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # get the new delegation ICA balance + post_delegation_ica_bal=$($JUNO_MAIN_CMD q bank balances $JUNO_DELEGATION_ICA_ADDR --denom ujuno | GETBAL) + diff=$(($post_delegation_ica_bal - $initial_delegation_ica_bal)) + assert_equal "$diff" '10000000' +} + +@test "[INTEGRATION-BASIC-JUNO] tokens on JUNO were staked" { + # wait for another epoch to pass so that tokens are staked + WAIT_FOR_STRING $STRIDE_LOGS '\[DELEGATION\] success on JUNO' + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # check staked tokens + NEW_STAKE=$($JUNO_MAIN_CMD q staking delegation $JUNO_DELEGATION_ICA_ADDR $JUNO_DELEGATE_VAL | GETSTAKE) + stake_diff=$(($NEW_STAKE > 0)) + assert_equal "$stake_diff" "1" +} + +# check that redemptions and claims work +@test "[INTEGRATION-BASIC-JUNO] redemption works" { + sleep 5 + old_redemption_ica_bal=$($JUNO_MAIN_CMD q bank balances $JUNO_REDEMPTION_ICA_ADDR --denom ujuno | GETBAL) + # call redeem-stake + amt_to_redeem=100 + $STRIDE_MAIN_CMD tx stakeibc redeem-stake $amt_to_redeem JUNO $JUNO_RECEIVER_ACCT \ + --from val1 --keyring-backend test --chain-id $STRIDE_CHAIN_ID -y + WAIT_FOR_STRING $STRIDE_LOGS '\[REDEMPTION] completed on JUNO' + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # check that the tokens were transferred to the redemption account + new_redemption_ica_bal=$($JUNO_MAIN_CMD q bank balances $JUNO_REDEMPTION_ICA_ADDR --denom ujuno | GETBAL) + diff_positive=$(($new_redemption_ica_bal > $old_redemption_ica_bal)) + assert_equal "$diff_positive" "1" +} + +@test "[INTEGRATION-BASIC-JUNO] claimed tokens are properly distributed" { + # TODO(optimize tests) extra sleep just in case + SENDER_ACCT=$STRIDE_ADDRESS + old_sender_bal=$($JUNO_MAIN_CMD q bank balances $JUNO_RECEIVER_ACCT --denom ujuno | GETBAL) + # TODO check that the UserRedemptionRecord has isClaimable = true + # grab the epoch number for the first deposit record in the list od DRs + EPOCH=$(strided q records list-user-redemption-record | grep -Fiw 'epochNumber' | head -n 1 | grep -o -E '[0-9]+') + # claim the record + $STRIDE_MAIN_CMD tx stakeibc claim-undelegated-tokens JUNO $EPOCH $SENDER_ACCT --from val1 --keyring-backend test --chain-id STRIDE -y + WAIT_FOR_STRING $STRIDE_LOGS '\[CLAIM\] success on JUNO' + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # TODO check that UserRedemptionRecord has isClaimable = false + # check that the tokens were transferred to the sender account + new_sender_bal=$($JUNO_MAIN_CMD q bank balances $JUNO_RECEIVER_ACCT --denom ujuno | GETBAL) + # check that the undelegated tokens were transfered to the sender account + diff_positive=$(($new_sender_bal > $old_sender_bal)) + assert_equal "$diff_positive" "1" +} + +# check that a second liquid staking call kicks off reinvestment +@test "[INTEGRATION-BASIC-JUNO] rewards are being reinvested, exchange rate updating" { + # read the exchange rate and current delegations + RR1=$($STRIDE_MAIN_CMD q stakeibc show-host-zone JUNO | grep -Fiw 'RedemptionRate' | grep -Eo '[+-]?[0-9]+([.][0-9]+)?') + OLD_STAKED_BAL=$($JUNO_MAIN_CMD q staking delegation $JUNO_DELEGATION_ICA_ADDR $JUNO_DELEGATE_VAL | GETSTAKE) + # liquid stake again to kickstart the reinvestment process + $STRIDE_MAIN_CMD tx stakeibc liquid-stake 1000 ujuno --keyring-backend test --from val1 -y --chain-id $STRIDE_CHAIN_ID + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # wait four days (transfers, stake, move rewards, reinvest rewards) + epoch_duration=$($STRIDE_MAIN_CMD q epochs epoch-infos | grep -Fiw -B 2 'stride_epoch' | head -n 1 | grep -o -E '[0-9]+') + sleep $(($epoch_duration * 4)) + # simple check that number of tokens staked increases + NEW_STAKED_BAL=$($JUNO_MAIN_CMD q staking delegation $JUNO_DELEGATION_ICA_ADDR $JUNO_DELEGATE_VAL | GETSTAKE) + STAKED_BAL_INCREASED=$(($NEW_STAKED_BAL > $OLD_STAKED_BAL)) + assert_equal "$STAKED_BAL_INCREASED" "1" + + RR2=$($STRIDE_MAIN_CMD q stakeibc show-host-zone JUNO | grep -Fiw 'RedemptionRate' | grep -Eo '[+-]?[0-9]+([.][0-9]+)?') + # check that the exchange rate has increased + MULT=1000000 + RR_INCREASED=$(( $(FLOOR $(DECMUL $RR2 $MULT)) > $(FLOOR $(DECMUL $RR1 $MULT)))) + assert_equal "$RR_INCREASED" "1" +} + +# TODO check that the correct amount is being reinvested and the correct amount is flowing to the rev EOA +@test "[NOT-IMPLEMENTED] reinvestment and revenue amounts are correct" { +} diff --git a/scripts/tests/local_tests.bats b/scripts/tests/local_tests.bats deleted file mode 100644 index da5dc401a..000000000 --- a/scripts/tests/local_tests.bats +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env bats - -setup_file() { - # get the containing directory of this file - SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - PATH="$SCRIPT_DIR/../../:$PATH" - - # set allows us to export all variables in account_vars - set -a - source scripts/account_vars.sh - IBCSTRD='ibc/FF6C2E86490C1C4FBBD24F55032831D2415B9D7882F85C3CC9C2401D79362BEA' - IBCATOM='ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2' - DELEGATE_ADDR='cosmos19l6d3d7k2pel8epgcpxc9np6fsvjpaaa06nm65vagwxap0e4jezq05mmvu' - # GAIA_DELEGATE_VAL='cosmosvaloper19e7sugzt8zaamk2wyydzgmg9n3ysylg6na6k6e' - GAIA_DELEGATE_VAL='cosmosvaloper1pcag0cj4ttxg8l7pcg0q4ksuglswuuedadj7ne' - STATOM="stuatom" - GETBAL() { - head -n 1 | grep -o -E '[0-9]+' - } - GETSTAKE() { - tail -n 2 | head -n 1 | grep -o -E '[0-9]+' | head -n 1 - } - INIT_STAKE=$($GAIA1_EXEC q staking delegation $DELEGATE_ADDR $GAIA_DELEGATE_VAL | GETSTAKE) - set +a -} - -setup() { - # get the containing directory of this file - SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - PATH="$SCRIPT_DIR/../../:$PATH" - - load 'test_helper/bats-support/load' - load 'test_helper/bats-assert/load' -} - -@test "proper initial address names" { - [[ $STRIDE_ADDRESS_1 == "stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7" ]] - assert_equal $STRIDE_ADDRESS_1 'stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7' - assert_equal $STRIDE_ADDRESS_2 'stride1ld5ewfgc3crml46n806km7djtr788vqdd5lnu5' - assert_equal $STRIDE_ADDRESS_3 'stride16vlrvd7lsfqg8q7kyxcyar9v7nt0h99p5arglq' - - assert_equal $GAIA_ADDRESS_1 'cosmos1pcag0cj4ttxg8l7pcg0q4ksuglswuuedcextl2' - assert_equal $GAIA_ADDRESS_2 'cosmos1t2aqq3c6mt8fa6l5ady44manvhqf77sywjcldv' - assert_equal $GAIA_ADDRESS_3 'cosmos19e7sugzt8zaamk2wyydzgmg9n3ysylg6kfwrk2' - - assert_equal $RLY_ADDRESS_1 'stride1ft20pydau82pgesyl9huhhux307s9h3078692y' - assert_equal $RLY_ADDRESS_2 'cosmos1uyrmx8zw0mxu7sdn58z29wnnqnxtqvvxqec074' -} - -@test "ibc transfer updates all balances" { - # get initial balances - str1_balance=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom ustrd | GETBAL) - gaia1_balance=$($GAIA1_EXEC q bank balances $GAIA_ADDRESS_1 --denom $IBCSTRD | GETBAL) - str1_balance_atom=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $IBCATOM | GETBAL) - gaia1_balance_atom=$($GAIA1_EXEC q bank balances $GAIA_ADDRESS_1 --denom uatom | GETBAL) - # do IBC transfer - $STRIDE1_EXEC tx ibc-transfer transfer transfer channel-0 $GAIA_ADDRESS_1 10000ustrd --from val1 --chain-id STRIDE -y --keyring-backend test - $GAIA1_EXEC tx ibc-transfer transfer transfer channel-0 $STRIDE_ADDRESS_1 10000uatom --from gval1 --chain-id GAIA -y --keyring-backend test - sleep 20 - # get new balances - str1_balance_new=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom ustrd | GETBAL) - gaia1_balance_new=$($GAIA1_EXEC q bank balances $GAIA_ADDRESS_1 --denom $IBCSTRD | GETBAL) - str1_balance_atom_new=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $IBCATOM | GETBAL) - gaia1_balance_atom_new=$($GAIA1_EXEC q bank balances $GAIA_ADDRESS_1 --denom uatom | GETBAL) - # get all STRD balance diffs - str1_diff=$(($str1_balance - $str1_balance_new)) - gaia1_diff=$(($gaia1_balance - $gaia1_balance_new)) - assert_equal "$str1_diff" '10000' - assert_equal "$gaia1_diff" '-10000' - # get all ATOM balance diffs - str1_diff=$(($str1_balance_atom - $str1_balance_atom_new)) - gaia1_diff=$(($gaia1_balance_atom - $gaia1_balance_atom_new)) - assert_equal "$str1_diff" '-10000' - assert_equal "$gaia1_diff" '10000' -} - -# add test to register host zone -@test "host zone successfully registered" { - run $STRIDE1_EXEC q stakeibc show-host-zone GAIA - assert_line ' HostDenom: uatom' - assert_line ' chainId: GAIA' - assert_line ' delegationAccount:' - assert_line ' address: cosmos19l6d3d7k2pel8epgcpxc9np6fsvjpaaa06nm65vagwxap0e4jezq05mmvu' -} - -# add test to register a validator -@test "validator successfully registered" { - run $GAIA_CMD q stakeibc show-host-zone GAIA - assert_line ' HostDenom: uatom' - assert_line ' chainId: GAIA' - assert_line ' delegationAccount:' - assert_line ' address: cosmos19l6d3d7k2pel8epgcpxc9np6fsvjpaaa06nm65vagwxap0e4jezq05mmvu' -} - -@test "liquid stake mints stATOM" { - # get module address - MODADDR=$($STRIDE1_EXEC q stakeibc module-address stakeibc | awk '{print $NF}') - # get initial balances - mod_balance_atom=$($STRIDE1_EXEC q bank balances $MODADDR --denom $IBCATOM | GETBAL) - str1_balance_atom=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $IBCATOM | GETBAL) - str1_balance_statom=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $STATOM | GETBAL) - # liquid stake - $STRIDE1_EXEC tx stakeibc liquid-stake 1000 uatom --keyring-backend test --from val1 -y - sleep 15 - # make sure Module Acct received ATOM - remove if IBC transfer is automated - # mod_balance_atom_new=$($STRIDE1_EXEC q bank balances $MODADDR --denom $IBCATOM | GETBAL) - # mod_atom_diff=$(($mod_balance_atom_new - $mod_balance_atom)) - # assert_equal "$mod_atom_diff" '1000' - # make sure IBCATOM went down - str1_balance_atom_new=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $IBCATOM | GETBAL) - str1_atom_diff=$(($str1_balance_atom - $str1_balance_atom_new)) - assert_equal "$str1_atom_diff" '1000' - # make sure STATOM went up - str1_balance_statom_new=$($STRIDE1_EXEC q bank balances $STRIDE_ADDRESS_1 --denom $STATOM | GETBAL) - str1_statom_diff=$(($str1_balance_statom_new-$str1_balance_statom)) - assert_equal "$str1_statom_diff" "1000" -} - -# # add test to see if assets are properly being staked on host zone -# @test "tokens staking on host zone" { -# # run below test once ICQ is deployed -# sleep 60 -# NEW_STAKE=$($GAIA1_EXEC q staking delegation $DELEGATE_ADDR $GAIA_DELEGATE_VAL | GETSTAKE) -# stake_diff=$((($NEW_STAKE - $INIT_STAKE) > 0)) -# assert_equal "$stake_diff" "1" -# } - -# TEST-74 -# add test to see if assets are properly being staked on host zone -# add asset redemption test - -# @test "icq: exchange rate and delegated balance queries" { -# # Test: query exchange rate -# $STRIDE1_EXEC tx interchainquery query-exchangerate GAIA --keyring-backend test -y --from val1 -# sleep 15 -# run $STRIDE1_EXEC q txs --events message.action=/stride.interchainquery.MsgSubmitQueryResponse --limit=1 -# assert_line --partial 'key: redemptionRate' - -# # Test query delegated balance -# $STRIDE1_EXEC tx interchainquery query-delegatedbalance GAIA --keyring-backend test -y --from val1 -# sleep 15 -# run $STRIDE1_EXEC q txs --events message.action=/stride.interchainquery.MsgSubmitQueryResponse --limit=1 -# assert_line --partial 'key: totalDelegations' -# } - - diff --git a/scripts/tests/osmo_tests.bats b/scripts/tests/osmo_tests.bats new file mode 100755 index 000000000..b513d1b7d --- /dev/null +++ b/scripts/tests/osmo_tests.bats @@ -0,0 +1,235 @@ +#!/usr/bin/env bats + +setup_file() { + # get the containing directory of this file + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + PATH="$SCRIPT_DIR/../../:$PATH" + + # set allows us to export all variables in account_vars + set -a + source scripts/account_vars.sh + + GETBAL() { + head -n 1 | grep -o -E '[0-9]+' + } + GETSTAKE() { + tail -n 2 | head -n 1 | grep -o -E '[0-9]+' | head -n 1 + } + # HELPER FUNCTIONS + DECADD () { + echo "scale=2; $1+$2" | bc + } + DECMUL () { + echo "scale=2; $1*$2" | bc + } + FLOOR () { + printf "%.0f\n" $1 + } + CEIL () { + printf "%.0f\n" $(ADD $1 1) + } + set +a +} + +setup() { + # get the containing directory of this file + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + PATH="$SCRIPT_DIR/../../:$PATH" + + + # if these extensions don't load properly, adjust the paths accoring to these instructions + TEST_BREW_PREFIX="$(brew --prefix)" + load "${TEST_BREW_PREFIX}/lib/bats-support/load.bash" + load "${TEST_BREW_PREFIX}/lib/bats-assert/load.bash" +} + +############################################################################################## +###### HOW TO ###### +############################################################################################## +# Tests are written sequentially +# Each test depends on the previous tests, and examines the chain state at a point in time + +# To add a new test, take an action then sleep for seconds / blocks / IBC_TX_WAIT_SECONDS +# / epochs +# Reordering existing tests could break them + +############################################################################################## +###### SETUP TESTS ###### +############################################################################################## + +@test "[INTEGRATION-BASIC] address names are correct" { + assert_equal $STRIDE_ADDRESS "stride1uk4ze0x4nvh4fk0xm4jdud58eqn4yxhrt52vv7" + assert_equal $GAIA_ADDRESS "cosmos1pcag0cj4ttxg8l7pcg0q4ksuglswuuedcextl2" + + assert_equal $DELEGATION_ICA_ADDR "cosmos1sy63lffevueudvvlvh2lf6s387xh9xq72n3fsy6n2gr5hm6u2szs2v0ujm" + assert_equal $REDEMPTION_ICA_ADDR "cosmos1xmcwu75s8v7s54k79390wc5gwtgkeqhvzegpj0nm2tdwacv47tmqg9ut30" + assert_equal $WITHDRAWAL_ICA_ADDR "cosmos1x5p8er7e2ne8l54tx33l560l8djuyapny55pksctuguzdc00dj7saqcw2l" + assert_equal $REVENUE_EOA_ADDR "cosmos1wdplq6qjh2xruc7qqagma9ya665q6qhcwju3ng" + assert_equal $FEE_ICA_ADDR "cosmos1lkgt5sfshn9shm7hd7chtytkq4mvwvswgmyl0hkacd4rmusu9wwq60cezx" + assert_equal $GAIA_DELEGATE_VAL_1 "cosmosvaloper1pcag0cj4ttxg8l7pcg0q4ksuglswuuedadj7ne" + assert_equal $GAIA_DELEGATE_VAL_2 "cosmosvaloper133lfs9gcpxqj6er3kx605e3v9lqp2pg5syhvsz" + assert_equal $GAIA_RECEIVER_ACCT "cosmos1g6qdx6kdhpf000afvvpte7hp0vnpzapuyxp8uf" + + assert_equal $JUNO_DELEGATE_VAL "junovaloper1pcag0cj4ttxg8l7pcg0q4ksuglswuued3knlr0" + assert_equal $JUNO_DELEGATION_ICA_ADDR 'juno1xan7vt4nurz6c7x0lnqnvpmuc0lljz7rycqmuz2kk6wxv4k69d0sfats35' + assert_equal $JUNO_REDEMPTION_ICA_ADDR 'juno1y6haxdt03cgkc7aedxrlaleeteel7fgc0nvtu2kggee3hnrlvnvs4kw2v9' + assert_equal $JUNO_WITHDRAWAL_ICA_ADDR 'juno104n6h822n6n7psqjgjl7emd2uz67lptggp5cargh6mw0gxpch2gsk53qk5' + assert_equal $JUNO_FEE_ICA_ADDR 'juno1rp8qgfq64wmjg7exyhjqrehnvww0t9ev3f3p2ls82umz2fxgylqsz3vl9h' + + assert_equal $OSMO_DELEGATE_VAL 'osmovaloper12ffkl30v0ghtyaezvedazquhtsf4q5ng8khuv4' + assert_equal $OSMO_DELEGATION_ICA_ADDR "osmo1cx04p5974f8hzh2lqev48kjrjugdxsxy7mzrd0eyweycpr90vk8q8d6f3h" + assert_equal $OSMO_REDEMPTION_ICA_ADDR "osmo1uy9p9g609676rflkjnnelaxatv8e4sd245snze7qsxzlk7dk7s8qrcjaez" + assert_equal $OSMO_WITHDRAWAL_ICA_ADDR "osmo10arcf5r89cdmppntzkvulc7gfmw5lr66y2m25c937t6ccfzk0cqqz2l6xv" + assert_equal $OSMO_FEE_ICA_ADDR "osmo1n4r77qsmu9chvchtmuqy9cv3s539q87r398l6ugf7dd2q5wgyg9su3wd4g" +} + +# # add test to register host zone +@test "[INTEGRATION-BASIC] host zones successfully registered" { + + run $STRIDE_MAIN_CMD q stakeibc show-host-zone OSMO + assert_line ' HostDenom: uosmo' + assert_line ' chainId: OSMO' + assert_line ' delegationAccount:' + assert_line ' address: osmo1cx04p5974f8hzh2lqev48kjrjugdxsxy7mzrd0eyweycpr90vk8q8d6f3h' + assert_line ' feeAccount:' + assert_line ' address: osmo1n4r77qsmu9chvchtmuqy9cv3s539q87r398l6ugf7dd2q5wgyg9su3wd4g' + assert_line ' redemptionAccount:' + assert_line ' address: osmo1uy9p9g609676rflkjnnelaxatv8e4sd245snze7qsxzlk7dk7s8qrcjaez' + assert_line ' withdrawalAccount:' + assert_line ' address: osmo10arcf5r89cdmppntzkvulc7gfmw5lr66y2m25c937t6ccfzk0cqqz2l6xv' + assert_line ' unbondingFrequency: "1"' + assert_line ' RedemptionRate: "1.000000000000000000"' +} + + +############################################################################################## +###### TEST BASIC STRIDE FUNCTIONALITY ###### +############################################################################################## + +@test "[INTEGRATION-BASIC-OSMO] ibc transfer updates all balances" { + # get initial balances + str1_balance=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom ustrd | GETBAL) + osmo1_balance=$($OSMO_MAIN_CMD q bank balances $OSMO_ADDRESS --denom $IBC_STRD_DENOM | GETBAL) + str1_balance_osmo=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_OSMO_DENOM | GETBAL) + osmo1_balance_osmo=$($OSMO_MAIN_CMD q bank balances $OSMO_ADDRESS --denom uosmo | GETBAL) + # do IBC transfer + $STRIDE_MAIN_CMD tx ibc-transfer transfer transfer channel-2 $OSMO_ADDRESS 3000000000ustrd --from val1 --chain-id STRIDE -y --keyring-backend test & + $OSMO_MAIN_CMD tx ibc-transfer transfer transfer channel-0 $STRIDE_ADDRESS 3000000000uosmo --from oval1 --chain-id OSMO -y --keyring-backend test & + WAIT_FOR_BLOCK $STRIDE_LOGS 8 + # get new balances + str1_balance_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom ustrd | GETBAL) + osmo1_balance_new=$($OSMO_MAIN_CMD q bank balances $OSMO_ADDRESS --denom $IBC_STRD_DENOM | GETBAL) + str1_balance_osmo_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_OSMO_DENOM | GETBAL) + osmo1_balance_osmo_new=$($OSMO_MAIN_CMD q bank balances $OSMO_ADDRESS --denom uosmo | GETBAL) + # get all STRD balance diffs + str1_diff=$(($str1_balance - $str1_balance_new)) + osmo1_diff=$(($osmo1_balance - $osmo1_balance_new)) + assert_equal "$str1_diff" '3000000000' + assert_equal "$osmo1_diff" '-3000000000' + # get all OSMO_DENOM balance diffs + str1_diff=$(($str1_balance_osmo - $str1_balance_osmo_new)) + osmo1_diff=$(($osmo1_balance_osmo - $osmo1_balance_osmo_new)) + assert_equal "$str1_diff" '-3000000000' + assert_equal "$osmo1_diff" '3000000000' +} + +@test "[INTEGRATION-BASIC-OSMO] liquid stake mints stOSMO" { + # get module address + MODADDR=$($STRIDE_MAIN_CMD q stakeibc module-address stakeibc | awk '{print $NF}') + # get initial balances + mod_balance_osmo=$($STRIDE_MAIN_CMD q bank balances $MODADDR --denom $IBC_OSMO_DENOM | GETBAL) + str1_balance_osmo=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_OSMO_DENOM | GETBAL) + str1_balance_stosmo=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $STOSMO_DENOM | GETBAL) + # liquid stake + $STRIDE_MAIN_CMD tx stakeibc liquid-stake 1000000000 uosmo --keyring-backend test --from val1 -y --chain-id $STRIDE_CHAIN_ID + # sleep two block for the tx to settle on stride + WAIT_FOR_STRING $STRIDE_LOGS '\[MINT ST ASSET\] success on OSMO' + # make sure IBC_OSMO_DENOM went down + str1_balance_osmo_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $IBC_OSMO_DENOM | GETBAL) + str1_osmo_diff=$(($str1_balance_osmo - $str1_balance_osmo_new)) + assert_equal "$str1_osmo_diff" '1000000000' + # make sure STOSMO went up + str1_balance_stosmo_new=$($STRIDE_MAIN_CMD q bank balances $STRIDE_ADDRESS --denom $STOSMO_DENOM | GETBAL) + str1_stosmo_diff=$(($str1_balance_stosmo_new-$str1_balance_stosmo)) + assert_equal "$str1_stosmo_diff" "1000000000" +} + +@test "[INTEGRATION-BASIC-OSMO] tokens were transferred to OSMO after liquid staking" { + # initial balance of delegation ICA + initial_delegation_ica_bal=$($OSMO_MAIN_CMD q bank balances $OSMO_DELEGATION_ICA_ADDR --denom uosmo | GETBAL) + WAIT_FOR_STRING $STRIDE_LOGS '\[IBC-TRANSFER\] success to OSMO' + # get the new delegation ICA balance + post_delegation_ica_bal=$($OSMO_MAIN_CMD q bank balances $OSMO_DELEGATION_ICA_ADDR --denom uosmo | GETBAL) + diff=$(($post_delegation_ica_bal - $initial_delegation_ica_bal)) + assert_equal "$diff" '1000000000' +} + +@test "[INTEGRATION-BASIC-OSMO] tokens on OSMO were staked" { + # wait for another epoch to pass so that tokens are staked + WAIT_FOR_STRING $STRIDE_LOGS '\[DELEGATION\] success on OSMO' + # check staked tokens + NEW_STAKE=$($OSMO_MAIN_CMD q staking delegation $OSMO_DELEGATION_ICA_ADDR $OSMO_DELEGATE_VAL | GETSTAKE) + stake_diff=$(($NEW_STAKE > 0)) + assert_equal "$stake_diff" "1" +} + +# check that redemptions and claims work +@test "[INTEGRATION-BASIC-OSMO] redemption works" { + sleep 5 + old_redemption_ica_bal=$($OSMO_MAIN_CMD q bank balances $OSMO_REDEMPTION_ICA_ADDR --denom uosmo | GETBAL) + # call redeem-stake + amt_to_redeem=100 + $STRIDE_MAIN_CMD tx stakeibc redeem-stake $amt_to_redeem OSMO $OSMO_RECEIVER_ACCT \ + --from val1 --keyring-backend test --chain-id $STRIDE_CHAIN_ID -y + WAIT_FOR_STRING $STRIDE_LOGS '\[REDEMPTION] completed on OSMO' + # check that the tokens were transferred to the redemption account + new_redemption_ica_bal=$($OSMO_MAIN_CMD q bank balances $OSMO_REDEMPTION_ICA_ADDR --denom uosmo | GETBAL) + diff_positive=$(($new_redemption_ica_bal > $old_redemption_ica_bal)) + assert_equal "$diff_positive" "1" +} + +@test "[INTEGRATION-BASIC-OSMO] claimed tokens are properly distributed" { + # TODO(optimize tests) extra sleep just in case + SENDER_ACCT=$STRIDE_ADDRESS + old_sender_bal=$($OSMO_MAIN_CMD q bank balances $OSMO_RECEIVER_ACCT --denom uosmo | GETBAL) + # TODO check that the UserRedemptionRecord has isClaimable = true + # grab the epoch number for the first deposit record in the list od DRs + EPOCH=$(strided q records list-user-redemption-record | grep -Fiw 'epochNumber' | head -n 1 | grep -o -E '[0-9]+') + # claim the record + $STRIDE_MAIN_CMD tx stakeibc claim-undelegated-tokens OSMO $EPOCH $SENDER_ACCT --from val1 --keyring-backend test --chain-id STRIDE -y + WAIT_FOR_STRING $STRIDE_LOGS '\[CLAIM\] success on OSMO' + + # check that the tokens were transferred to the sender account + new_sender_bal=$($OSMO_MAIN_CMD q bank balances $OSMO_RECEIVER_ACCT --denom uosmo | GETBAL) + + # check that the undelegated tokens were transfered to the sender account + diff_positive=$(($new_sender_bal > $old_sender_bal)) + assert_equal "$diff_positive" "1" +} + +# check that a second liquid staking call kicks off reinvestment +@test "[INTEGRATION-BASIC-OSMO] rewards are being reinvested, exchange rate updating" { + # read the exchange rate and current delegations + RR1=$($STRIDE_MAIN_CMD q stakeibc show-host-zone OSMO | grep -Fiw 'RedemptionRate' | grep -Eo '[+-]?[0-9]+([.][0-9]+)?') + OLD_STAKED_BAL=$($OSMO_MAIN_CMD q staking delegation $OSMO_DELEGATION_ICA_ADDR $OSMO_DELEGATE_VAL | GETSTAKE) + # liquid stake again to kickstart the reinvestment process + $STRIDE_MAIN_CMD tx stakeibc liquid-stake 1000 uosmo --keyring-backend test --from val1 -y --chain-id $STRIDE_CHAIN_ID + WAIT_FOR_BLOCK $STRIDE_LOGS 2 + # wait four days (transfers, stake, move rewards, reinvest rewards) + epoch_duration=$($STRIDE_MAIN_CMD q epochs epoch-infos | grep -Fiw -B 2 'stride_epoch' | head -n 1 | grep -o -E '[0-9]+') + sleep $(($epoch_duration * 4)) + # simple check that number of tokens staked increases + NEW_STAKED_BAL=$($OSMO_MAIN_CMD q staking delegation $OSMO_DELEGATION_ICA_ADDR $OSMO_DELEGATE_VAL | GETSTAKE) + STAKED_BAL_INCREASED=$(($NEW_STAKED_BAL > $OLD_STAKED_BAL)) + assert_equal "$STAKED_BAL_INCREASED" "1" + + RR2=$($STRIDE_MAIN_CMD q stakeibc show-host-zone OSMO | grep -Fiw 'RedemptionRate' | grep -Eo '[+-]?[0-9]+([.][0-9]+)?') + # check that the exchange rate has increased + MULT=1000000 + RR_INCREASED=$(( $(FLOOR $(DECMUL $RR2 $MULT)) > $(FLOOR $(DECMUL $RR1 $MULT)))) + assert_equal "$RR_INCREASED" "1" +} + +# TODO check that the correct amount is being reinvested and the correct amount is flowing to the rev EOA +@test "[NOT-IMPLEMENTED] reinvestment and revenue amounts are correct" { +} diff --git a/scripts/tests/run_all_tests.sh b/scripts/tests/run_all_tests.sh index e77c33628..94e0d104f 100755 --- a/scripts/tests/run_all_tests.sh +++ b/scripts/tests/run_all_tests.sh @@ -1,4 +1,8 @@ #!/bin/bash BASE_SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -bats $BASE_SCRIPT_DIR/basic_tests.bats +# run test files +bats $BASE_SCRIPT_DIR/gaia_tests.bats +bats $BASE_SCRIPT_DIR/juno_tests.bats +bats $BASE_SCRIPT_DIR/osmo_tests.bats + diff --git a/scripts/vars.sh b/scripts/vars.sh index ee4eb9d31..5e53a0a07 100644 --- a/scripts/vars.sh +++ b/scripts/vars.sh @@ -4,29 +4,43 @@ set -eu SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) STATE=$SCRIPT_DIR/state +LOGS=$SCRIPT_DIR/logs PEER_PORT=26656 +# Logs +STRIDE_LOGS=$LOGS/stride.log +TX_LOGS=$SCRIPT_DIR/logs/tx.log +KEYS_LOGS=$SCRIPT_DIR/logs/keys.log + # DENOMS IBC_STRD_DENOM='ibc/FF6C2E86490C1C4FBBD24F55032831D2415B9D7882F85C3CC9C2401D79362BEA' IBC_ATOM_DENOM='ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2' +IBC_JUNO_DENOM='ibc/EFF323CC632EC4F747C61BCE238A758EFDB7699C3226565F7C20DA06509D59A5' +IBC_OSMO_DENOM='ibc/13B2C536BB057AC79D5616B8EA1B9540EC1F2170718CAFF6F0083C966FFFED0B' ATOM_DENOM='uatom' +JUNO_DENOM='ujuno' +OSMO_DENOM='uosmo' STRD_DENOM='ustrd' STATOM_DENOM="stuatom" - -BLOCK_TIME='5s' -DAY_EPOCH_INDEX=1 -DAY_EPOCH_DURATION="100s" -STRIDE_EPOCH_INDEX=2 -STRIDE_EPOCH_DURATION="40s" -UNBONDING_TIME="200s" +STJUNO_DENOM="stujuno" +STOSMO_DENOM="stuosmo" + +# CHAIN PARAMS +BLOCK_TIME='1s' +STRIDE_DAY_EPOCH_DURATION="100s" +STRIDE_EPOCH_EPOCH_DURATION="40s" +HOST_DAY_EPOCH_DURATION="60s" +HOST_HOUR_EPOCH_DURATION="60s" +HOST_WEEK_EPOCH_DURATION="60s" +UNBONDING_TIME="120s" MAX_DEPOSIT_PERIOD="30s" VOTING_PERIOD="30s" VAL_TOKENS=5000000000000 -STAKE_TOKENS=4500000000000 +STAKE_TOKENS=5000000000 ADMIN_TOKENS=1000000000 -# STRIDE vars +# STRIDE STRIDE_CHAIN_ID=STRIDE STRIDE_NODE_PREFIX=stride STRIDE_NUM_NODES=3 @@ -35,66 +49,142 @@ STRIDE_VAL_PREFIX=val STRIDE_DENOM=$STRD_DENOM STRIDE_RPC_PORT=26657 STRIDE_ADMIN_ACCT=admin -MAIN_STRIDE_CMD="$STRIDE_CMD --home $SCRIPT_DIR/state/stride1" +STRIDE_MAIN_CMD="$STRIDE_CMD --home $SCRIPT_DIR/state/${STRIDE_NODE_PREFIX}1" STRIDE_MNEMONIC_1="close soup mirror crew erode defy knock trigger gather eyebrow tent farm gym gloom base lemon sleep weekend rich forget diagram hurt prize fly" -STRIDE_MNEMONIC_2="timber vacant teach wedding disease fashion place merge poet produce promote renew sunny industry enforce heavy inch three call sustain deal flee athlete intact" -STRIDE_MNEMONIC_3="enjoy dignity rule multiply kitchen arrange flight rocket kingdom domain motion fire wage viable enough comic cry motor memory fancy dish sing border among" -STRIDE_MNEMONIC_4="vacant margin wave rice brush drastic false rifle tape critic volcano worry tumble assist pulp swamp sheriff stairs decorate chaos empower already obvious caught" -STRIDE_MNEMONIC_5="river spin follow make trash wreck clever increase dial divert meadow abuse victory able foot kid sell bench embody river income utility dismiss timber" -STRIDE_VAL_MNEMONICS=("$STRIDE_MNEMONIC_1" "$STRIDE_MNEMONIC_2" "$STRIDE_MNEMONIC_3" "$STRIDE_MNEMONIC_4" "$STRIDE_MNEMONIC_5") +STRIDE_MNEMONIC_2="turkey miss hurry unable embark hospital kangaroo nuclear outside term toy fall buffalo book opinion such moral meadow wing olive camp sad metal banner" +STRIDE_MNEMONIC_3="tenant neck ask season exist hill churn rice convince shock modify evidence armor track army street stay light program harvest now settle feed wheat" +STRIDE_MNEMONIC_4="tail forward era width glory magnet knock shiver cup broken turkey upgrade cigar story agent lake transfer misery sustain fragile parrot also air document" +STRIDE_MNEMONIC_5="crime lumber parrot enforce chimney turtle wing iron scissors jealous indicate peace empty game host protect juice submit motor cause second picture nuclear area" +STRIDE_VAL_MNEMONICS=("$STRIDE_MNEMONIC_1","$STRIDE_MNEMONIC_2","$STRIDE_MNEMONIC_3","$STRIDE_MNEMONIC_4","$STRIDE_MNEMONIC_5") -# GAIA vars +# GAIA GAIA_CHAIN_ID=GAIA GAIA_NODE_PREFIX=gaia -GAIA_NUM_NODES=3 +GAIA_NUM_NODES=2 GAIA_CMD="$SCRIPT_DIR/../build/gaiad" GAIA_VAL_PREFIX=gval +GAIA_REV_ACCT=grev1 +GAIA_ADDRESS_PREFIX=cosmos GAIA_DENOM=$ATOM_DENOM +GAIA_IBC_DENOM=$IBC_ATOM_DENOM GAIA_RPC_PORT=26557 -MAIN_GAIA_CMD="$GAIA_CMD --home $SCRIPT_DIR/state/gaia1" - -GAIA_MNEMONIC_1="move next relief spatial resemble onion exhibit fitness major toss where square wrong exact infant skate dragon shift region over you gospel absorb double" -GAIA_MNEMONIC_2="guilt leader matrix lecture infant axis method grain diesel sting reflect brave estate surge october candy busy crash parade club practice sure gentle celery" -GAIA_MNEMONIC_3="fire tape spread wing click winter awful ozone visa spray swear color table settle review rival meadow gauge speed tide timber disease float live" -GAIA_MNEMONIC_4="curtain mom patrol rifle list lamp interest hard lock stairs display world disagree ten fantasy engine van explain chunk social smile detail initial typical" -GAIA_MNEMONIC_5="invite close edit quick effort mosquito ocean north term spread dial throw human review west bike mandate learn cabin bubble remove unlock lab unique" -GAIA_VAL_MNEMONICS=("$GAIA_MNEMONIC_1" "$GAIA_MNEMONIC_2" "$GAIA_MNEMONIC_3" "$GAIA_MNEMONIC_4" "$GAIA_MNEMONIC_5") - -# define relayer vars +GAIA_MAIN_CMD="$GAIA_CMD --home $SCRIPT_DIR/state/${GAIA_NODE_PREFIX}1" + +GAIA_REV_MNEMONIC="tonight bonus finish chaos orchard plastic view nurse salad regret pause awake link bacon process core talent whale million hope luggage sauce card weasel" +GAIA_VAL_MNEMONIC_1="move next relief spatial resemble onion exhibit fitness major toss where square wrong exact infant skate dragon shift region over you gospel absorb double" +GAIA_VAL_MNEMONIC_2="guilt leader matrix lecture infant axis method grain diesel sting reflect brave estate surge october candy busy crash parade club practice sure gentle celery" +GAIA_VAL_MNEMONIC_3="fire tape spread wing click winter awful ozone visa spray swear color table settle review rival meadow gauge speed tide timber disease float live" +GAIA_VAL_MNEMONIC_4="curtain mom patrol rifle list lamp interest hard lock stairs display world disagree ten fantasy engine van explain chunk social smile detail initial typical" +GAIA_VAL_MNEMONIC_5="invite close edit quick effort mosquito ocean north term spread dial throw human review west bike mandate learn cabin bubble remove unlock lab unique" +GAIA_VAL_MNEMONICS=("$GAIA_VAL_MNEMONIC_1","$GAIA_VAL_MNEMONIC_2","$GAIA_VAL_MNEMONIC_3","$GAIA_VAL_MNEMONIC_4","$GAIA_VAL_MNEMONIC_5") + +# JUNO +JUNO_CHAIN_ID=JUNO +JUNO_NODE_PREFIX=juno +JUNO_NUM_NODES=2 +JUNO_CMD="$SCRIPT_DIR/../build/junod" +JUNO_VAL_PREFIX=jval +JUNO_REV_ACCT=jrev1 +JUNO_ADDRESS_PREFIX=juno +JUNO_DENOM=$JUNO_DENOM +JUNO_IBC_DENOM=$IBC_JUNO_DENOM +JUNO_RPC_PORT=26457 +JUNO_MAIN_CMD="$JUNO_CMD --home $SCRIPT_DIR/state/${JUNO_NODE_PREFIX}1" + +JUNO_REV_MNEMONIC="tonight bonus finish chaos orchard plastic view nurse salad regret pause awake link bacon process core talent whale million hope luggage sauce card weasel" +JUNO_VAL_MNEMONIC_1="move next relief spatial resemble onion exhibit fitness major toss where square wrong exact infant skate dragon shift region over you gospel absorb double" +JUNO_VAL_MNEMONIC_2="acoustic prize donkey space pitch visa labor enable sting sort safe conduct key name electric toddler disagree abandon impose chest marine three try sense" +JUNO_VAL_MNEMONIC_3="almost east skate high judge that marriage below slush olympic exercise medal utility recall meadow control siren deliver umbrella bid biology input common item" +JUNO_VAL_MNEMONIC_4="language planet neck gold garment day foam bomb roof crystal marble office they hospital party bargain horror disease enforce icon fruit describe sorry universe" +JUNO_VAL_MNEMONIC_5="embrace possible empower remove arrest escape stadium behave bulb bright time drum casual seminar remind science feel absurd isolate beef hidden peace usage sort" +JUNO_VAL_MNEMONICS=("$JUNO_VAL_MNEMONIC_1","$JUNO_VAL_MNEMONIC_2","$JUNO_VAL_MNEMONIC_3","$JUNO_VAL_MNEMONIC_4","$JUNO_VAL_MNEMONIC_5") + +# OSMO +OSMO_CHAIN_ID=OSMO +OSMO_NODE_PREFIX=osmo +OSMO_NUM_NODES=2 +OSMO_CMD="$SCRIPT_DIR/../build/osmosisd" +OSMO_VAL_PREFIX=oval +OSMO_REV_ACCT=orev1 +OSMO_ADDRESS_PREFIX=osmo +OSMO_DENOM=$OSMO_DENOM +OSMO_IBC_DENOM=$IBC_OSMO_DENOM +OSMO_RPC_PORT=26357 +OSMO_MAIN_CMD="$OSMO_CMD --home $SCRIPT_DIR/state/${OSMO_NODE_PREFIX}1" + +OSMO_REV_MNEMONIC="furnace spell ring dinosaur paper thank sketch social mystery tissue upgrade voice advice peasant quote surge meat december level broom clock hurdle portion predict" +OSMO_VAL_MNEMONIC_1="badge thumb upper scrap gift prosper milk whale journey term indicate risk acquire afford awake margin venture penalty simple fancy fluid review enrich ozone" +OSMO_VAL_MNEMONIC_2="tattoo fade gloom boring review actual pluck wrestle desk update mandate grow spawn people blush gym inner voice reform glue shiver screen train august" +OSMO_VAL_MNEMONIC_3="immune acid hurry impose mechanic forward bitter square curtain busy couple hollow calm pole flush deer bird one normal fish loyal upgrade town rail" +OSMO_VAL_MNEMONIC_4="ridge round key spawn address anchor file local athlete pioneer eyebrow flush chase visa awake claim test device chimney roast tent excess profit gaze" +OSMO_VAL_MNEMONIC_5="federal garden bundle rebel museum donor hello oak daring argue talk sing chief burst rigid corn zone gather tell opera nominee desk select shine" +OSMO_VAL_MNEMONICS=("$OSMO_VAL_MNEMONIC_1","$OSMO_VAL_MNEMONIC_2","$OSMO_VAL_MNEMONIC_3","$OSMO_VAL_MNEMONIC_4","$OSMO_VAL_MNEMONIC_5") + +# HERMES HERMES_CMD="$SCRIPT_DIR/../build/hermes/release/hermes --config $STATE/hermes/config.toml" HERMES_EXEC="docker-compose run --rm hermes hermes" HERMES_STRIDE_ACCT=rly1 HERMES_GAIA_ACCT=rly2 -HERMES_OSMOSIS_ACCT=rly3 +HERMES_JUNO_ACCT=rly3 +HERMES_OSMO_ACCT=rly4 HERMES_STRIDE_MNEMONIC="alter old invest friend relief slot swear pioneer syrup economy vendor tray focus hedgehog artist legend antenna hair almost donkey spice protect sustain increase" HERMES_GAIA_MNEMONIC="resemble accident lake amateur physical jewel taxi nut demand magnet person blanket trip entire awkward fiber usual current index limb lady lady depart train" -HERMES_OSMOSIS_MNEMONIC="artwork ranch dinosaur maple unhappy office bone vote rebel slot outside benefit innocent wrist certain cradle almost fat trial build chicken enroll strike milk" +HERMES_JUNO_MNEMONIC="uphold decorate moon memory taste century work pride force genius width ripple myself year steel ivory type sweet tree ignore danger pudding owner discover" +HERMES_OSMO_MNEMONIC="lawn inside color february double myth depart invite miracle nest silver spider spray recall theme loan exotic puzzle uncover dial young earn disagree fee" +# RELAYER RELAYER_CMD="$SCRIPT_DIR/../build/relayer --home $STATE/relayer" RELAYER_EXEC="docker-compose run --rm relayer rly" RELAYER_STRIDE_ACCT=rly1 RELAYER_GAIA_ACCT=rly2 -RELAYER_OSMOSIS_ACCT=rly3 +RELAYER_JUNO_ACCT=rly3 +RELAYER_OSMO_ACCT=rly4 -RELAYER_STRIDE_MNEMONIC="alter old invest friend relief slot swear pioneer syrup economy vendor tray focus hedgehog artist legend antenna hair almost donkey spice protect sustain increase" -RELAYER_GAIA_MNEMONIC="resemble accident lake amateur physical jewel taxi nut demand magnet person blanket trip entire awkward fiber usual current index limb lady lady depart train" -RELAYER_OSMOSIS_MNEMONIC="artwork ranch dinosaur maple unhappy office bone vote rebel slot outside benefit innocent wrist certain cradle almost fat trial build chicken enroll strike milk" +RELAYER_STRIDE_MNEMONIC="pride narrow breeze fitness sign bounce dose smart squirrel spell length federal replace coral lunar thunder vital push nuclear crouch fun accident hood need" +RELAYER_GAIA_MNEMONIC="fiction perfect rapid steel bundle giant blade grain eagle wing cannon fever must humble dance kitchen lazy episode museum faith off notable rate flavor" +RELAYER_JUNO_MNEMONIC="kiwi betray topple van vapor flag decorate cement crystal fee family clown cry story gain frost strong year blanket remain grass pig hen empower" +RELAYER_OSMO_MNEMONIC="unaware wine ramp february bring trust leaf beyond fever inside option dilemma save know captain endless salute radio humble chicken property culture foil taxi" +# ICQ ICQ_CMD="$SCRIPT_DIR/../build/interchain-queries --home $STATE/icq" ICQ_EXEC="docker-compose run --rm icq interchain-queries" ICQ_STRIDE_ACCT=icq1 ICQ_GAIA_ACCT=icq2 -ICQ_OSMOSIS_ACCT=icq3 +ICQ_JUNO_ACCT=icq3 +ICQ_OSMO_ACCT=icq4 ICQ_STRIDE_MNEMONIC="helmet say goat special plug umbrella finger night flip axis resource tuna trigger angry shove essay point laundry horror eager forget depend siren alarm" ICQ_GAIA_MNEMONIC="capable later bamboo snow drive afraid cheese practice latin brush hand true visa drama mystery bird client nature jealous guess tank marriage volume fantasy" -ICQ_OSMOSIS_MNEMONIC="rival inch buzz slow high dynamic antique idle switch evolve math virus direct health simple capital place mutual air orphan champion prefer garage over" - +ICQ_JUNO_MNEMONIC="divorce loop depth announce strategy goddess short cash private raise spatial parent deal acid casual love inner bind ozone picnic fee earn scene galaxy" +ICQ_OSMO_MNEMONIC="mix deal extend cargo office intact illegal cage fabric must upset yellow put any shaft area use piece patrol tobacco village guilt iron program" + +DELEGATION_ICA_ADDR='cosmos1sy63lffevueudvvlvh2lf6s387xh9xq72n3fsy6n2gr5hm6u2szs2v0ujm' +REDEMPTION_ICA_ADDR='cosmos1xmcwu75s8v7s54k79390wc5gwtgkeqhvzegpj0nm2tdwacv47tmqg9ut30' +WITHDRAWAL_ICA_ADDR='cosmos1x5p8er7e2ne8l54tx33l560l8djuyapny55pksctuguzdc00dj7saqcw2l' +REVENUE_EOA_ADDR='cosmos1wdplq6qjh2xruc7qqagma9ya665q6qhcwju3ng' +FEE_ICA_ADDR='cosmos1lkgt5sfshn9shm7hd7chtytkq4mvwvswgmyl0hkacd4rmusu9wwq60cezx' +GAIA_DELEGATE_VAL_1='cosmosvaloper1pcag0cj4ttxg8l7pcg0q4ksuglswuuedadj7ne' +GAIA_DELEGATE_VAL_2='cosmosvaloper133lfs9gcpxqj6er3kx605e3v9lqp2pg5syhvsz' +GAIA_RECEIVER_ACCT='cosmos1g6qdx6kdhpf000afvvpte7hp0vnpzapuyxp8uf' + +JUNO_DELEGATE_VAL='junovaloper1pcag0cj4ttxg8l7pcg0q4ksuglswuued3knlr0' +JUNO_DELEGATION_ICA_ADDR='juno1xan7vt4nurz6c7x0lnqnvpmuc0lljz7rycqmuz2kk6wxv4k69d0sfats35' +JUNO_REDEMPTION_ICA_ADDR='juno1y6haxdt03cgkc7aedxrlaleeteel7fgc0nvtu2kggee3hnrlvnvs4kw2v9' +JUNO_WITHDRAWAL_ICA_ADDR='juno104n6h822n6n7psqjgjl7emd2uz67lptggp5cargh6mw0gxpch2gsk53qk5' +JUNO_FEE_ICA_ADDR='juno1rp8qgfq64wmjg7exyhjqrehnvww0t9ev3f3p2ls82umz2fxgylqsz3vl9h' +JUNO_RECEIVER_ACCT='juno1sy0q0jpaw4t3hnf6k5wdd4384g0syzlp7rrtsg' + +OSMO_DELEGATE_VAL='osmovaloper12ffkl30v0ghtyaezvedazquhtsf4q5ng8khuv4' +OSMO_DELEGATION_ICA_ADDR='osmo1cx04p5974f8hzh2lqev48kjrjugdxsxy7mzrd0eyweycpr90vk8q8d6f3h' +OSMO_REDEMPTION_ICA_ADDR='osmo1uy9p9g609676rflkjnnelaxatv8e4sd245snze7qsxzlk7dk7s8qrcjaez' +OSMO_WITHDRAWAL_ICA_ADDR='osmo10arcf5r89cdmppntzkvulc7gfmw5lr66y2m25c937t6ccfzk0cqqz2l6xv' +OSMO_FEE_ICA_ADDR='osmo1n4r77qsmu9chvchtmuqy9cv3s539q87r398l6ugf7dd2q5wgyg9su3wd4g' +OSMO_RECEIVER_ACCT='osmo1w6wdc2684g9h3xl8nhgwr282tcxx4kl06n4sjl' CSLEEP() { for i in $(seq $1); do @@ -102,3 +192,19 @@ CSLEEP() { printf "\r\t$(($1 - $i))s left..." done } + +GET_VAR_VALUE() { + var_name="$1" + echo "${!var_name}" +} + +WAIT_FOR_BLOCK() { + num_blocks="${2:-1}" + for i in $(seq $num_blocks); do + ( tail -f -n0 $1 & ) | grep -q "INF executed block height=" + done +} + +WAIT_FOR_STRING() { + ( tail -f -n0 $1 & ) | grep -q "$2" +}