#!/bin/sh # End-to-end smoke test of the js/wasm light client: # # torly relay <- WebSocket -> bridge <- TCP P2P -> test node # wasm client <- NIP-44 events -> relay -> bridge # # Requirements: tinygo, node (21+, or 20 with --experimental-websocket), and a # built torly. Set TORLY_BIN if torly is not at ../torly/torly. 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 "wasm-smoke: torly not found at $TORLY_BIN (set TORLY_BIN)" >&2 exit 2 fi if ! command -v "$NODE" >/dev/null 2>&1; then echo "wasm-smoke: node not found" >&2 exit 2 fi TMP=$(mktemp -d "${TMPDIR:-/tmp}/nostrino-smoke.XXXXXX") PORT=${PORT:-34567} 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 echo "== building commands ==" (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 echo "== using wasm $WASM ==" cp "$WASM" "$TMP/nostrino.wasm" else echo "== building wasm ==" (cd "$ROOT" && "$TINYGO" build -target wasm -o "$TMP/nostrino.wasm" ./cmd/nostrino-wasm) fi echo "== starting torly on 127.0.0.1:$PORT ==" 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 if curl -fsS -m 1 "http://127.0.0.1:$PORT/" >/dev/null 2>&1; then break; fi sleep 0.1 done echo "== starting test node on 127.0.0.1:$NODE_PORT ==" "$TMP/nostrino-testnode" -listen "127.0.0.1:$NODE_PORT" -blocks 50 >"$TMP/testnode.log" 2>&1 & PIDS="$PIDS $!" sleep 0.5 echo "== starting bridge ==" "$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 if [ -f "$TMP/bridge/gateway.uri" ]; then break; fi sleep 0.1 done if [ ! -f "$TMP/bridge/gateway.uri" ]; then echo "wasm-smoke: no gateway URI" >&2 cat "$TMP/bridge.log" >&2 exit 1 fi echo "== running wasm client in node ==" "$NODE" --experimental-websocket "$ROOT/scripts/wasm-smoke.cjs" \ "$TMP/nostrino.wasm" "$TMP/bridge/gateway.uri" "626c6f636b2d37"