diff --git a/envs/latest b/envs/latest new file mode 100644 index 0000000..ce304fd --- /dev/null +++ b/envs/latest @@ -0,0 +1,15 @@ +COMPOSE_PROJECT_NAME=polymesh + +POLYMESH_CHAIN_IMAGE=polymeshassociation/polymesh:7.3.0-ci-runtime-docker-image-debian +POLYMESH_CHAIN_WS_PORT=9944 +POLYMESH_CHAIN_RPC_PORT=9933 +POLYMESH_CHAIN_P2P_PORT=30333 + +POLYMESH_REST_API_IMAGE=polymeshassociation/polymesh-rest-api:v7.1.0-alpha.3 +POLYMESH_REST_API_LOCAL_SM_PORT=3004 +POLYMESH_REST_API_VAULT_SM_PORT=3005 + +POLYMESH_SUBQUERY_IMAGE=polymeshassociation/polymesh-subquery:v19.2.0 + +POLYMESH_SUBQUERY_GRAPHQL_IMAGE=onfinality/subql-query:v2.9.0 +POLYMESH_SUBQUERY_GRAPHQL_PORT=3000 \ No newline at end of file diff --git a/scripts/get-vault-token.sh b/scripts/get-vault-token.sh index 14aee09..66c47ec 100755 --- a/scripts/get-vault-token.sh +++ b/scripts/get-vault-token.sh @@ -1,18 +1,8 @@ #!/bin/sh -# This script extracts the Vault root token from the polymesh-vault-init container logs -# and exports it as VAULT_TOKEN environment variable. It also prints the token to stdout. -# -# Usage: -# ./print-vault-token.sh # Print token to stdout -# source ./print-vault-token.sh # Export token to current shell -# -# Note: The script assumes the polymesh-vault-init container has -# generated a root token in its logs before exiting. - -set -eu -o pipefail +# This script extracts the Vault root token from the polymesh-vault-init container logs and writes it to std out VAULT_TOKEN=$(docker logs polymesh-vault-init-1 --tail=10 | - grep "Vault Root Token:" | cut -d' ' -f4) + grep "Vault Root Token:" | tail -n 1 | cut -d' ' -f4) echo $VAULT_TOKEN diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 791a342..f8f10c4 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -1,21 +1,14 @@ #!/bin/bash -# This script starts up a dev environment via compose and executes a suite of integration tests +# This script runs Polymesh integration tests # Get the directory where this script is located, regardless of where it's called from SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -docker compose up -d - -echo "Waiting for a fully initialized environment..." -docker compose wait environment-ready >/dev/null 2>&1 - # Vault token needs to be set so the tests can manage keys export VAULT_TOKEN=$("${SCRIPT_DIR}/get-vault-token.sh") # Run jest with default maxWorkers and any additional arguments passed to this script echo "Beginning tests..." -jest --maxWorkers=8 "$@" +yarn jest --maxWorkers=8 "$@" -echo "Cleaning up the docker environment..." -docker compose down -v \ No newline at end of file diff --git a/scripts/start-env.sh b/scripts/start-env.sh new file mode 100755 index 0000000..c73e86e --- /dev/null +++ b/scripts/start-env.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +#!/bin/bash + +# This script starts up a dev environment via compose and executes a suite of integration tests + +# Get the directory where this script is located, regardless of where it's called from +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +COMPOSE_ENV="${SCRIPT_DIR}/../envs/latest" + +echo "Starting env using $COMPOSE_ENV" +docker compose --env-file "$COMPOSE_ENV" up --detach + +echo "Waiting for a fully initialized environment..." +docker compose wait environment-ready >/dev/null 2>&1 + +echo "Polymesh dev environment started" \ No newline at end of file diff --git a/scripts/stop-env.sh b/scripts/stop-env.sh new file mode 100755 index 0000000..f00e699 --- /dev/null +++ b/scripts/stop-env.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# This script cleans up the test environment + +# Get the directory where this script is located, regardless of where it's called from +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +COMPOSE_ENV="${SCRIPT_DIR}/../envs/latest" + +echo "Cleaning up the docker environment..." +docker compose --env-file "$COMPOSE_ENV" down -v \ No newline at end of file diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..64ed53a --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# This script sets up a Polymesh env, runs the tests and cleans up the environment + +# Get the directory where this script is located, regardless of where it's called from +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +"${SCRIPT_DIR}/start-env.sh" + +"${SCRIPT_DIR}/run-tests.sh" + +"${SCRIPT_DIR}/stop-env.sh" + + diff --git a/tests/package.json b/tests/package.json index e3fc6fd..3608514 100644 --- a/tests/package.json +++ b/tests/package.json @@ -4,9 +4,11 @@ "description": "Polymesh developer environment helper", "main": "index.js", "scripts": { - "test": "../scripts/run-tests.sh", - "up": "docker compose up -d", - "down": "docker compose down -v" + "test": "../scripts/test.sh", + "test:start": "../scripts/start-env.sh", + "test:run": "../scripts/run-tests.sh", + "test:stop": "../scripts/stop-env.sh", + "test:vault-token": "../scripts/get-vault-token.sh" }, "author": "Polymesh Association", "license": "ISC",