#!/bin/sh # Build the binaries, start the rig, run both clients, prove relay failover, tear it down. set -eu ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) DOCKER="$ROOT/docker" export GOROOT=${GOROOT:-/home/mleku/sdk/go1.24.6} export PATH="$GOROOT/bin:/home/mleku/s/.local/goroot/bin:$PATH" echo "== building binaries" mkdir -p "$DOCKER/bin" (cd "$ROOT" && CGO_ENABLED=0 go build -trimpath -o "$DOCKER/bin/nostrino-testnode" ./cmd/nostrino-testnode \ && CGO_ENABLED=0 go build -trimpath -o "$DOCKER/bin/nostrino-bridge" ./cmd/nostrino-bridge \ && CGO_ENABLED=0 go build -trimpath -o "$DOCKER/bin/nostrino-discover" ./cmd/nostrino-discover \ && CGO_ENABLED=0 go build -trimpath -o "$DOCKER/bin/nostrino-neutrino" ./cmd/nostrino-neutrino) (cd "${TORLY_REPO:-$ROOT/../torly}" && CGO_ENABLED=0 go build -trimpath -o "$DOCKER/bin/torly" ./cmd/torly) cd "$DOCKER" compose="docker compose -f compose.yml" cleanup() { $compose --profile clients down -v --remove-orphans >/dev/null 2>&1 || true; } trap cleanup EXIT INT TERM echo "== starting relays, nodes and gateways" $compose up -d --wait relay-a relay-b node-btc node-blake node-alt gw-a gw-b echo "== waiting for the gateways to be announced on both relays" for attempt in $(seq 1 60); do if $compose exec -T relay-a wget -qO- http://127.0.0.1:3334/health >/dev/null 2>&1 \ && $compose run --rm --no-deps client-a sh -c \ 'nostrino-discover -relay ws://relay-a:3334 -chain btc >/dev/null' >/dev/null 2>&1; then break fi sleep 2 done echo "== client A, told only about relay-a" $compose run --rm --no-deps client-a echo "== client B, told only about relay-b" $compose run --rm --no-deps client-b echo "== failover: stop relay-a, a client on relay-b still works" $compose stop relay-a >/dev/null $compose run --rm --no-deps client-b echo "== recovery: start relay-a, a client on relay-a works again" $compose start relay-a >/dev/null sleep 4 $compose run --rm --no-deps client-a echo "== all rig checks passed"