Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions envs/latest
Original file line number Diff line number Diff line change
@@ -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
14 changes: 2 additions & 12 deletions scripts/get-vault-token.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 2 additions & 9 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions scripts/start-env.sh
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 11 additions & 0 deletions scripts/stop-env.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -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"


8 changes: 5 additions & 3 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading