Repository navigation
Expand file tree
/
Copy pathup.sh
More file actions
executable file
·112 lines (105 loc) · 5.06 KB
/
Copy pathup.sh
File metadata and controls
executable file
·112 lines (105 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
# Starts the isolated devnet test environment:
# 1. the chain: adaup's node, Kuber, db-sync skip with SKIP_CHAIN=1
# 2. the faucet settings, funding its base address skip with SKIP_FAUCET=1
# 3. GovTool's app stack (docker-compose.yml), healthy
# 4. the seed (seed.sh) skip with SKIP_SEED=1
# 5. .state/playwright.env and .state/pytest.env
#
# Settings: .env.devnet (+ .env.devnet.local). Extra arguments go to
# `docker compose up`. DEVNET_COMPOSE_BUILD=0 skips rebuilding images that
# exist. Step timings are written to .state/timings.txt.
set -euo pipefail
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
load_env
mkdir -p "$DEVNET_STATE_DIR"
chmod 700 "$DEVNET_STATE_DIR"
: > "$DEVNET_STATE_DIR/timings.txt"
# --- 1. Chain -----------------------------------------------------------------
if [ "${SKIP_CHAIN:-0}" != "1" ]; then
command -v "$ADAUP_CARDANO" >/dev/null 2>&1 ||
die "adaup CLI '$ADAUP_CARDANO' not found (pip install adaup, or set ADAUP_CARDANO)"
step_start
log "starting the devnet (${ADAUP_DEVNET_SLOT_LENGTH}s slots, ${ADAUP_DEVNET_EPOCH_LENGTH}-slot epochs, proposals live ${ADAUP_DEVNET_LIVE_SECONDS}s)"
# A fresh genesis every time: remove a previous devnet first.
"$ADAUP_CARDANO" devnet down --docker >/dev/null 2>&1 || true
"$ADAUP_CARDANO" devnet up --docker --detach --wait
step_end "chain up"
fi
docker network inspect "$DEVNET_DOCKER_NETWORK" >/dev/null 2>&1 ||
die "Docker network '$DEVNET_DOCKER_NETWORK' not found; is the devnet running? (DEVNET_DOCKER_NETWORK)"
wait_for "Kuber at $KUBER_URL" 180 http_ok "$KUBER_URL/api/v3/protocol-params"
# --- 2. Faucet ----------------------------------------------------------------
if [ "${SKIP_FAUCET:-0}" != "1" ]; then
step_start
[ -d "$REPO_ROOT/tests/govtool-frontend/playwright/node_modules" ] ||
(cd "$REPO_ROOT/tests/govtool-frontend/playwright" && npm ci --no-audit --no-fund)
node "$DEVNET_DIR/scripts/faucet-env.js" --fund
step_end "faucet"
fi
# --- 3. App stack -------------------------------------------------------------
step_start
log "starting the app stack"
# DEVNET_COMPOSE_BUILD=0 uses the images as they are (CI builds them first
# with a layer cache); missing images are still built.
build_flag=(--build)
[ "${DEVNET_COMPOSE_BUILD:-1}" = "1" ] || build_flag=()
compose up -d ${build_flag[@]+"${build_flag[@]}"} --wait --wait-timeout "${COMPOSE_WAIT_TIMEOUT:-600}" "$@"
BACKEND="http://127.0.0.1:${BACKEND_PORT}"
SHIM="http://127.0.0.1:${BLOCKFROST_SHIM_PORT}"
wait_for "backend" 120 http_ok "$BACKEND/health"
# /network/info reads db-sync and the genesis file; it fails when either
# belongs to another run.
wait_for "backend reading db-sync" 180 http_ok "$BACKEND/network/info"
wait_for "blockfrost-shim" 60 http_ok "$SHIM/health"
wait_for "frontend" 60 http_ok "http://127.0.0.1:${FRONTEND_PORT}/"
wait_for "pdf backend" 60 http_ok "http://127.0.0.1:${PDF_PORT}/health"
http_ok "$METADATA_BUCKET_URL/" ||
log "warning: $METADATA_BUCKET_URL does not reach the bucket from this host; see README.md"
step_end "app stack up"
# --- 4. Seed ------------------------------------------------------------------
if [ "${SKIP_SEED:-0}" != "1" ]; then
step_start
"$DEVNET_DIR/seed.sh"
step_end "seed"
fi
# --- 5. Test settings ---------------------------------------------------------
# Exported before a run, these override the suites' own .env files (dotenv
# never overwrites a variable that is already set), so every value a local
# .env could hold for a public network is set here. The test mnemonic is
# generated once per devnet, so re-runs of failed tests reuse the wallets.
mnemonic=""
if [ -f "$DEVNET_STATE_DIR/playwright.env" ]; then
mnemonic="$(sed -n 's/^TEST_WALLET_MNEMONIC=//p' "$DEVNET_STATE_DIR/playwright.env" | tr -d '"')"
fi
if [ -z "$mnemonic" ] || [ "${SKIP_CHAIN:-0}" != "1" ]; then
mnemonic="$(cd "$REPO_ROOT/tests/govtool-frontend/playwright" &&
node -e 'console.log(require("bip39").generateMnemonic(256))')"
fi
{
echo "# Generated by tests/devnet/up.sh; devnet only."
echo "HOST_URL=${PUBLIC_FRONTEND_URL}"
echo "NETWORK=devnet"
echo "KUBER_URL=${KUBER_URL}"
echo "KUBER_API_KEY="
echo "BLOCKFROST_URL=${SHIM}/api"
echo "BLOCKFROST_API_KEY=devnet"
echo "CARDANOAPI_METADATA_URL=${METADATA_BUCKET_URL}"
echo "TEST_WALLET_MNEMONIC=\"${mnemonic}\""
echo "TX_TIMEOUT=${DEVNET_TX_TIMEOUT:-120000}"
echo "IS_HARDFORK_PROPOSAL_ENABLED=true"
echo "CI=true"
echo "TEST_WORKERS=${DEVNET_TEST_WORKERS:-4}"
[ -f "$DEVNET_STATE_DIR/faucet.env" ] && grep '^FAUCET_' "$DEVNET_STATE_DIR/faucet.env"
} > "$DEVNET_STATE_DIR/playwright.env"
chmod 600 "$DEVNET_STATE_DIR/playwright.env"
{
echo "# Generated by tests/devnet/up.sh; devnet only."
echo "BASE_URL=${BACKEND}"
echo "NETWORK=devnet"
echo "KUBER_URL=${KUBER_URL}"
echo "KUBER_API_KEY="
} > "$DEVNET_STATE_DIR/pytest.env"
log "up: frontend ${PUBLIC_FRONTEND_URL}, backend ${BACKEND}, pdf ${PUBLIC_PDF_URL}, shim ${SHIM}"
log "timings: $(tr '\n' ';' < "$DEVNET_STATE_DIR/timings.txt")"
log "run the suites with tests/devnet/run-tests.sh pytest|playwright"