idb-smoke.sh raw
1 #!/bin/sh
2 # Persistence smoke test: torly + test node + bridge + wasm + IndexedDB.
3 # Requires `node --experimental-websocket`, tinygo, a built torly, and the
4 # fake-indexeddb package (npm install fake-indexeddb).
5 set -eu
6
7 ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
8 TORLY_BIN=${TORLY_BIN:-$HOME/s/tinygo/torly/torly}
9 TINYGO=${TINYGO:-tinygo}
10 NODE=${NODE:-node}
11 if [ -x "$HOME/.local/goroot/bin/go" ]; then
12 GOROOT=$HOME/.local/goroot
13 export GOROOT
14 PATH=$GOROOT/bin:$PATH
15 export PATH
16 fi
17 if [ ! -x "$TORLY_BIN" ]; then
18 echo "idb-smoke: torly not found at $TORLY_BIN (set TORLY_BIN)" >&2
19 exit 2
20 fi
21
22 TMP=$(mktemp -d "${TMPDIR:-/tmp}/nostrino-idb.XXXXXX")
23 PORT=${PORT:-34577}
24 NODE_PORT=$((PORT + 1))
25 BRIDGE_PORT=$((PORT + 2))
26 PIDS=
27 cleanup() {
28 for pid in $PIDS; do kill "$pid" 2>/dev/null || true; done
29 wait 2>/dev/null || true
30 rm -rf "$TMP"
31 }
32 trap cleanup EXIT INT TERM
33
34 (cd "$ROOT" && go build -o "$TMP/nostrino-bridge" ./cmd/nostrino-bridge \
35 && go build -o "$TMP/nostrino-testnode" ./cmd/nostrino-testnode)
36
37 if [ -n "${WASM:-}" ] && [ -f "${WASM}" ]; then
38 cp "$WASM" "$TMP/nostrino.wasm"
39 else
40 (cd "$ROOT" && "$TINYGO" build -target wasm -o "$TMP/nostrino.wasm" ./cmd/nostrino-wasm)
41 fi
42
43 TORLY_PORT=$PORT TORLY_DATA_DIR="$TMP/torly" TORLY_BLOSSOM_ENABLED=false \
44 "$TORLY_BIN" serve >"$TMP/torly.log" 2>&1 &
45 PIDS="$PIDS $!"
46 for i in $(seq 1 100); do
47 curl -fsS -m 1 "http://127.0.0.1:$PORT/" >/dev/null 2>&1 && break
48 sleep 0.1
49 done
50
51 "$TMP/nostrino-testnode" -listen "127.0.0.1:$NODE_PORT" -blocks 30 >"$TMP/testnode.log" 2>&1 &
52 PIDS="$PIDS $!"
53 sleep 0.5
54
55 "$TMP/nostrino-bridge" -relay "ws://127.0.0.1:$PORT" -node "127.0.0.1:$NODE_PORT" \
56 -bridge-listen "127.0.0.1:$BRIDGE_PORT" -bridge-url "ws://127.0.0.1:$BRIDGE_PORT/nostrino" \
57 -chain regtest -data "$TMP/bridge" >"$TMP/bridge.log" 2>&1 &
58 PIDS="$PIDS $!"
59 for i in $(seq 1 100); do
60 [ -f "$TMP/bridge/gateway.uri" ] && break
61 sleep 0.1
62 done
63 if [ ! -f "$TMP/bridge/gateway.uri" ]; then
64 echo "idb-smoke: no gateway URI" >&2
65 cat "$TMP/bridge.log" >&2
66 exit 1
67 fi
68
69 "$NODE" --experimental-websocket "$ROOT/scripts/idb-smoke.cjs" \
70 "$TMP/nostrino.wasm" "$TMP/bridge/gateway.uri"
71