|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# ============================================================================ |
| 5 | +# E2E Test Network Setup Script |
| 6 | +# Downloads IOTA binaries, starts network, publishes iota-names packages, |
| 7 | +# then restarts services with injected configs. |
| 8 | +# ============================================================================ |
| 9 | + |
| 10 | +# TODO Remove '-alpha' when https://github.com/iotaledger/iota/pull/9538 is in mainnet release |
| 11 | +IOTA_BINARY_VERSION="${IOTA_BINARY_VERSION:-v1.14.0-alpha}" |
| 12 | +EPOCH_DURATION_MS="${EPOCH_DURATION_MS:-10000}" |
| 13 | +CONFIG_DIR="${CONFIG_DIR:-$(pwd)/persisted-localnet}" |
| 14 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 15 | +GRAPHQL_CONFIG="${GRAPHQL_CONFIG:-$(pwd)/graphql-config.toml}" |
| 16 | +DB_URL="${DB_URL:-postgres://postgres:postgrespw@localhost:5432/iota_indexer}" |
| 17 | + |
| 18 | +ADMIN_MNEMONIC="${ADMIN_MNEMONIC:?ADMIN_MNEMONIC environment variable is required}" |
| 19 | + |
| 20 | + |
| 21 | +declare -a PIDS=() |
| 22 | +PID_IOTA="" |
| 23 | +PID_INDEXER_WRITER="" |
| 24 | +PID_INDEXER_READER="" |
| 25 | +PID_GRAPHQL="" |
| 26 | + |
| 27 | +wait_for_url() { |
| 28 | + local url=$1 |
| 29 | + local name=$2 |
| 30 | + local log_file=${3:-} |
| 31 | + local max_attempts=${4:-60} |
| 32 | + |
| 33 | + echo "Waiting for $name at $url..." |
| 34 | + for i in $(seq 1 "$max_attempts"); do |
| 35 | + if curl -s -o /dev/null --connect-timeout 2 "$url" 2>/dev/null; then |
| 36 | + echo "$name is ready" |
| 37 | + return 0 |
| 38 | + fi |
| 39 | + sleep 1 |
| 40 | + done |
| 41 | + echo "ERROR: $name failed to become ready at $url after $max_attempts attempts" |
| 42 | + if [[ -n "$log_file" && -f "$log_file" ]]; then |
| 43 | + echo "=== Last 50 lines of $log_file ===" |
| 44 | + tail -50 "$log_file" |
| 45 | + echo "=== End of log ===" |
| 46 | + fi |
| 47 | + return 1 |
| 48 | +} |
| 49 | + |
| 50 | +download_binaries() { |
| 51 | + echo "=== Downloading IOTA binaries (version: $IOTA_BINARY_VERSION) ===" |
| 52 | + |
| 53 | + local os_name arch_name |
| 54 | + os_name=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 55 | + arch_name=$(uname -m) |
| 56 | + |
| 57 | + [[ "$os_name" == "darwin" ]] && os_name="macos" |
| 58 | + [[ "$arch_name" == "aarch64" ]] && arch_name="arm64" |
| 59 | + |
| 60 | + local asset_name="iota-$IOTA_BINARY_VERSION-${os_name}-${arch_name}.tgz" |
| 61 | + local download_url="https://github.com/iotaledger/iota/releases/download/$IOTA_BINARY_VERSION/$asset_name" |
| 62 | + |
| 63 | + echo "Downloading from: $download_url" |
| 64 | + curl -sL "$download_url" -o iota.tgz |
| 65 | + tar -zxvf iota.tgz |
| 66 | + chmod +x ./iota ./iota-indexer ./iota-graphql-rpc |
| 67 | + |
| 68 | + export PATH="$(pwd):$PATH" |
| 69 | + [[ -n "${GITHUB_PATH:-}" ]] && echo "$(pwd)" >> "$GITHUB_PATH" |
| 70 | + |
| 71 | + echo "Binaries downloaded and added to PATH" |
| 72 | +} |
| 73 | + |
| 74 | +# ============================================================================ |
| 75 | +# Initial startup (without iota-names config) |
| 76 | +# ============================================================================ |
| 77 | +start_initial_network() { |
| 78 | + echo "=== Phase 1: Starting initial network ===" |
| 79 | + |
| 80 | + # Start iota node with force-regenesis for fresh state |
| 81 | + ./iota start \ |
| 82 | + --network.config "$CONFIG_DIR" \ |
| 83 | + --with-faucet \ |
| 84 | + --faucet-amount 100000000000000 > iota-node.log 2>&1 & |
| 85 | + PID_IOTA=$! |
| 86 | + PIDS+=("$PID_IOTA") |
| 87 | + |
| 88 | + wait_for_url "http://127.0.0.1:9000/health" "iota-node" "iota-node.log" |
| 89 | + wait_for_url "http://127.0.0.1:9123" "faucet" "iota-node.log" |
| 90 | + |
| 91 | + # Start indexer-writer |
| 92 | + ./iota-indexer \ |
| 93 | + --db-url "$DB_URL" \ |
| 94 | + indexer \ |
| 95 | + --rpc-client-url "http://127.0.0.1:9000" \ |
| 96 | + --remote-store-url "http://127.0.0.1:9000/api/v1" \ |
| 97 | + --reset-db > indexer-writer.log 2>&1 & |
| 98 | + PID_INDEXER_WRITER=$! |
| 99 | + PIDS+=("$PID_INDEXER_WRITER") |
| 100 | + |
| 101 | + sleep 5 |
| 102 | + |
| 103 | + # Start indexer-reader |
| 104 | + ./iota-indexer \ |
| 105 | + --db-url "$DB_URL" \ |
| 106 | + --metrics-address "0.0.0.0:9185" \ |
| 107 | + json-rpc-service \ |
| 108 | + --rpc-client-url "http://127.0.0.1:9000" \ |
| 109 | + --rpc-address "0.0.0.0:9124" > indexer-reader.log 2>&1 & |
| 110 | + PID_INDEXER_READER=$! |
| 111 | + PIDS+=("$PID_INDEXER_READER") |
| 112 | + |
| 113 | + wait_for_url "http://127.0.0.1:9124" "indexer-reader" "indexer-reader.log" |
| 114 | + |
| 115 | + # Start graphql (no config yet) |
| 116 | + ./iota-graphql-rpc start-server \ |
| 117 | + --node-rpc-url "http://127.0.0.1:9000" \ |
| 118 | + --prom-port 9186 \ |
| 119 | + --port 9125 > graphql.log 2>&1 & |
| 120 | + PID_GRAPHQL=$! |
| 121 | + PIDS+=("$PID_GRAPHQL") |
| 122 | + |
| 123 | + wait_for_url "http://127.0.0.1:9125" "graphql" "graphql.log" |
| 124 | + |
| 125 | + echo "=== Phase 1 complete ===" |
| 126 | +} |
| 127 | + |
| 128 | +# ============================================================================ |
| 129 | +# Publish iota-names |
| 130 | +# ============================================================================ |
| 131 | +publish_iota_names() { |
| 132 | + echo "=== Phase 2: Publishing iota-names ===" |
| 133 | + ./iota keytool import "$ADMIN_MNEMONIC" ed25519 |
| 134 | + |
| 135 | + ./iota client --yes new-env --alias localnet --rpc http://127.0.0.1:9000 |
| 136 | + ./iota client switch --env localnet |
| 137 | + ./iota client faucet |
| 138 | + sleep 5 |
| 139 | + |
| 140 | + # Update auction constants for e2e tests |
| 141 | + bash dapp/scripts/update_auctions_constants.sh |
| 142 | + |
| 143 | + pushd scripts > /dev/null |
| 144 | + export NETWORK=localnet |
| 145 | + pnpm ts-node init/init.ts localnet |
| 146 | + pnpm ts-node tests/register-name.ts |
| 147 | + sleep 5 |
| 148 | + |
| 149 | + echo "Published package info:" |
| 150 | + cat ./package-info/localnet.json |
| 151 | + |
| 152 | + # Load env vars into current shell |
| 153 | + eval "$(pnpm ts-node utils/envs.ts localnet bash)" |
| 154 | + popd > /dev/null |
| 155 | + |
| 156 | + # Export for subsequent functions |
| 157 | + export IOTA_NAMES_PACKAGE_ADDRESS |
| 158 | + export IOTA_NAMES_OBJECT_ID |
| 159 | + export IOTA_NAMES_PAYMENTS_PACKAGE_ADDRESS |
| 160 | + export IOTA_NAMES_REGISTRY_ID |
| 161 | + export IOTA_NAMES_REVERSE_REGISTRY_ID |
| 162 | + |
| 163 | + echo "=== Phase 2 complete ===" |
| 164 | +} |
| 165 | + |
| 166 | +# ============================================================================ |
| 167 | +# Stop localnet and inject iota-names |
| 168 | +# ============================================================================ |
| 169 | +stop_and_inject_configs() { |
| 170 | + echo "=== Phase 3: Stopping localnet processes and injecting iota-names configs ===" |
| 171 | + |
| 172 | + for pid in $PID_IOTA $PID_INDEXER_WRITER $PID_INDEXER_READER $PID_GRAPHQL; do |
| 173 | + echo "Stopping PID: $pid" |
| 174 | + kill "$pid" 2>/dev/null || true |
| 175 | + wait "$pid" 2>/dev/null || true |
| 176 | + done |
| 177 | + |
| 178 | + for log in iota-node.log indexer-writer.log indexer-reader.log graphql.log; do |
| 179 | + echo -e "\n\n========== RESTARTED HERE ==========\n\n" >> "$log" |
| 180 | + done |
| 181 | + |
| 182 | + # Inject config into fullnode.yaml |
| 183 | + echo "Injecting config into $CONFIG_DIR/fullnode.yaml" |
| 184 | + cat >> "$CONFIG_DIR/fullnode.yaml" <<EOF |
| 185 | +iota-names-config: |
| 186 | + package-address: "$IOTA_NAMES_PACKAGE_ADDRESS" |
| 187 | + object-id: "$IOTA_NAMES_OBJECT_ID" |
| 188 | + payments-package-address: "$IOTA_NAMES_PAYMENTS_PACKAGE_ADDRESS" |
| 189 | + registry-id: "$IOTA_NAMES_REGISTRY_ID" |
| 190 | + reverse-registry-id: "$IOTA_NAMES_REVERSE_REGISTRY_ID" |
| 191 | +EOF |
| 192 | + |
| 193 | + # Create graphql config TOML from template |
| 194 | + echo "Creating graphql config at $GRAPHQL_CONFIG" |
| 195 | + envsubst < "$SCRIPT_DIR/templates/graphql-config.toml.template" > "$GRAPHQL_CONFIG" |
| 196 | + |
| 197 | + echo "=== Phase 3 complete ===" |
| 198 | +} |
| 199 | + |
| 200 | +# ============================================================================ |
| 201 | +# Phase 4: Restart with configs |
| 202 | +# ============================================================================ |
| 203 | +restart_with_configs() { |
| 204 | + echo "=== Phase 4: Restarting services with configs ===" |
| 205 | + |
| 206 | + # Restart iota |
| 207 | + ./iota start \ |
| 208 | + --network.config "$CONFIG_DIR" \ |
| 209 | + --with-faucet \ |
| 210 | + --faucet-amount 100000000000000 >> iota-node.log 2>&1 & |
| 211 | + PID_IOTA=$! |
| 212 | + PIDS+=("$PID_IOTA") |
| 213 | + |
| 214 | + wait_for_url "http://127.0.0.1:9000/health" "iota-node" "iota-node.log" |
| 215 | + |
| 216 | + # restart indexer-writer |
| 217 | + ./iota-indexer \ |
| 218 | + --db-url "$DB_URL" \ |
| 219 | + indexer \ |
| 220 | + --rpc-client-url "http://127.0.0.1:9000" \ |
| 221 | + --remote-store-url "http://127.0.0.1:9000/api/v1" \ |
| 222 | + --reset-db >> indexer-writer.log 2>&1 & |
| 223 | + PID_INDEXER_WRITER=$! |
| 224 | + PIDS+=("$PID_INDEXER_WRITER") |
| 225 | + |
| 226 | + sleep 5 |
| 227 | + |
| 228 | + # Restart indexer-reader with iota-names params |
| 229 | + ./iota-indexer \ |
| 230 | + --db-url "$DB_URL" \ |
| 231 | + --metrics-address "0.0.0.0:9185" \ |
| 232 | + json-rpc-service \ |
| 233 | + --rpc-client-url "http://127.0.0.1:9000" \ |
| 234 | + --rpc-address "0.0.0.0:9124" \ |
| 235 | + --iota-names-package-address "$IOTA_NAMES_PACKAGE_ADDRESS" \ |
| 236 | + --iota-names-object-id "$IOTA_NAMES_OBJECT_ID" \ |
| 237 | + --iota-names-payments-package-address "$IOTA_NAMES_PAYMENTS_PACKAGE_ADDRESS" \ |
| 238 | + --iota-names-registry-id "$IOTA_NAMES_REGISTRY_ID" \ |
| 239 | + --iota-names-reverse-registry-id "$IOTA_NAMES_REVERSE_REGISTRY_ID" >> indexer-reader.log 2>&1 & |
| 240 | + PID_INDEXER_READER=$! |
| 241 | + PIDS+=("$PID_INDEXER_READER") |
| 242 | + |
| 243 | + wait_for_url "http://127.0.0.1:9124" "indexer-reader" "indexer-reader.log" |
| 244 | + |
| 245 | + # Restart graphql with config file |
| 246 | + ./iota-graphql-rpc start-server \ |
| 247 | + --node-rpc-url "http://127.0.0.1:9000" \ |
| 248 | + --port 9125 \ |
| 249 | + --prom-port 9186 \ |
| 250 | + --config "$GRAPHQL_CONFIG" >> graphql.log 2>&1 & |
| 251 | + PID_GRAPHQL=$! |
| 252 | + PIDS+=("$PID_GRAPHQL") |
| 253 | + |
| 254 | + wait_for_url "http://127.0.0.1:9125" "graphql" "graphql.log" |
| 255 | + |
| 256 | + echo "=== Phase 4 complete ===" |
| 257 | +} |
| 258 | + |
| 259 | +# ============================================================================ |
| 260 | +# Main |
| 261 | +# ============================================================================ |
| 262 | +main() { |
| 263 | + echo "==============================================" |
| 264 | + echo "IOTA E2E Network Setup" |
| 265 | + echo "==============================================" |
| 266 | + |
| 267 | + download_binaries |
| 268 | + start_initial_network |
| 269 | + publish_iota_names |
| 270 | + stop_and_inject_configs |
| 271 | + restart_with_configs |
| 272 | + |
| 273 | + echo "==============================================" |
| 274 | + echo "Network ready with iota-names configuration" |
| 275 | + echo "==============================================" |
| 276 | +} |
| 277 | + |
| 278 | +main "$@" |
0 commit comments