#!/bin/sh # Persistence smoke test: torly + test node + bridge + wasm + IndexedDB. # Requires `node --experimental-websocket`, tinygo, a built torly, and the # fake-indexeddb package (npm install fake-indexeddb). set -eu ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) TORLY_BIN=${TORLY_BIN:-$HOME/s/tinygo/torly/torly} TINYGO=${TINYGO:-tinygo} NODE=${NODE:-node} if [ -x "$HOME/.local/goroot/bin/go" ]; then GOROOT=$HOME/.local/goroot export GOROOT PATH=$GOROOT/bin:$PATH export PATH fi if [ ! -x "$TORLY_BIN" ]; then echo "idb-smoke: torly not found at $TORLY_BIN (set TORLY_BIN)" >&2 exit 2 fi TMP=$(mktemp -d "${TMPDIR:-/tmp}/nostrino-idb.XXXXXX") PORT=${PORT:-34577} NODE_PORT=$((PORT + 1)) BRIDGE_PORT=$((PORT + 2)) PIDS= cleanup() { for pid in $PIDS; do kill "$pid" 2>/dev/null || true; done wait 2>/dev/null || true rm -rf "$TMP" } trap cleanup EXIT INT TERM (cd "$ROOT" && go build -o "$TMP/nostrino-bridge" ./cmd/nostrino-bridge \ && go build -o "$TMP/nostrino-testnode" ./cmd/nostrino-testnode) if [ -n "${WASM:-}" ] && [ -f "${WASM}" ]; then cp "$WASM" "$TMP/nostrino.wasm" else (cd "$ROOT" && "$TINYGO" build -target wasm -o "$TMP/nostrino.wasm" ./cmd/nostrino-wasm) fi TORLY_PORT=$PORT TORLY_DATA_DIR="$TMP/torly" TORLY_BLOSSOM_ENABLED=false \ "$TORLY_BIN" serve >"$TMP/torly.log" 2>&1 & PIDS="$PIDS $!" for i in $(seq 1 100); do curl -fsS -m 1 "http://127.0.0.1:$PORT/" >/dev/null 2>&1 && break sleep 0.1 done "$TMP/nostrino-testnode" -listen "127.0.0.1:$NODE_PORT" -blocks 30 >"$TMP/testnode.log" 2>&1 & PIDS="$PIDS $!" sleep 0.5 "$TMP/nostrino-bridge" -relay "ws://127.0.0.1:$PORT" -node "127.0.0.1:$NODE_PORT" \ -bridge-listen "127.0.0.1:$BRIDGE_PORT" -bridge-url "ws://127.0.0.1:$BRIDGE_PORT/nostrino" \ -chain regtest -data "$TMP/bridge" >"$TMP/bridge.log" 2>&1 & PIDS="$PIDS $!" for i in $(seq 1 100); do [ -f "$TMP/bridge/gateway.uri" ] && break sleep 0.1 done if [ ! -f "$TMP/bridge/gateway.uri" ]; then echo "idb-smoke: no gateway URI" >&2 cat "$TMP/bridge.log" >&2 exit 1 fi "$NODE" --experimental-websocket "$ROOT/scripts/idb-smoke.cjs" \ "$TMP/nostrino.wasm" "$TMP/bridge/gateway.uri"