|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +MINA_BIN="${MINA_BIN:-./target/release/mina}" |
| 6 | +# Convert to absolute path if it's a relative path |
| 7 | +if [[ "${MINA_BIN}" != /* ]]; then |
| 8 | + MINA_BIN="$(pwd)/${MINA_BIN}" |
| 9 | +fi |
| 10 | + |
| 11 | +# Add the directory containing the mina binary to PATH |
| 12 | +# so documentation scripts can find 'mina' command |
| 13 | +MINA_DIR="$(dirname "${MINA_BIN}")" |
| 14 | +export PATH="${MINA_DIR}:${PATH}" |
| 15 | + |
| 16 | +SCRIPT_DIR="website/docs/developers/scripts/cli" |
| 17 | +QUERY_FILE="website/docs/developers/scripts/graphql-api/queries/query/sync-status.graphql" |
| 18 | +GRAPHQL_NODE="${GRAPHQL_NODE:-https://mina-rust-plain-3.gcp.o1test.net/graphql}" |
| 19 | + |
| 20 | +echo "Testing that 'mina internal graphql' commands are available..." |
| 21 | + |
| 22 | +# Test 'mina internal' command exists |
| 23 | +"${MINA_BIN}" internal --help > /dev/null || { |
| 24 | + echo "ERROR: 'mina internal' command not found" |
| 25 | + exit 1 |
| 26 | +} |
| 27 | + |
| 28 | +# Test 'mina internal graphql' command exists |
| 29 | +"${MINA_BIN}" internal graphql --help > /dev/null || { |
| 30 | + echo "ERROR: 'mina internal graphql' command not found" |
| 31 | + exit 1 |
| 32 | +} |
| 33 | + |
| 34 | +# Test 'mina internal graphql list' command exists |
| 35 | +"${MINA_BIN}" internal graphql list --help > /dev/null || { |
| 36 | + echo "ERROR: 'mina internal graphql list' command not found" |
| 37 | + exit 1 |
| 38 | +} |
| 39 | + |
| 40 | +# Test 'mina internal graphql inspect' command exists |
| 41 | +"${MINA_BIN}" internal graphql inspect --help > /dev/null || { |
| 42 | + echo "ERROR: 'mina internal graphql inspect' command not found" |
| 43 | + exit 1 |
| 44 | +} |
| 45 | + |
| 46 | +# Test 'mina internal graphql run' command exists |
| 47 | +"${MINA_BIN}" internal graphql run --help > /dev/null || { |
| 48 | + echo "ERROR: 'mina internal graphql run' command not found" |
| 49 | + exit 1 |
| 50 | +} |
| 51 | + |
| 52 | +echo "" |
| 53 | +echo "Testing documentation scripts execution against ${GRAPHQL_NODE}..." |
| 54 | + |
| 55 | +# Function to test a script against the o1Labs node |
| 56 | +test_script() { |
| 57 | + local script="$1" |
| 58 | + local extra_args="${2:-}" |
| 59 | + |
| 60 | + if [[ ! -f "${SCRIPT_DIR}/${script}" ]]; then |
| 61 | + echo "ERROR: Script ${script} not found" |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + |
| 65 | + echo "Running ${script}..." |
| 66 | + |
| 67 | + # Export MINA_BIN for scripts to use, and add --node flag if needed |
| 68 | + export MINA_BIN |
| 69 | + if [[ -n "${extra_args}" ]]; then |
| 70 | + # Run script with modifications |
| 71 | + if output=$(bash -c "cd ${SCRIPT_DIR} && ${extra_args}" 2>&1); then |
| 72 | + echo " SUCCESS: ${script} executed successfully" |
| 73 | + return 0 |
| 74 | + else |
| 75 | + echo "ERROR: ${script} failed:" |
| 76 | + echo "$output" |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | + else |
| 80 | + # Run script as-is |
| 81 | + if output=$(bash "${SCRIPT_DIR}/${script}" 2>&1); then |
| 82 | + echo " SUCCESS: ${script} executed successfully" |
| 83 | + return 0 |
| 84 | + else |
| 85 | + echo "ERROR: ${script} failed:" |
| 86 | + echo "$output" |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | + fi |
| 90 | +} |
| 91 | + |
| 92 | +# Test all documentation scripts against the o1Labs node |
| 93 | +# Scripts that don't have --node need it added |
| 94 | +test_script "graphql-list.sh" "${MINA_BIN} internal graphql list --node ${GRAPHQL_NODE}" |
| 95 | +test_script "graphql-inspect.sh" "${MINA_BIN} internal graphql inspect syncStatus --node ${GRAPHQL_NODE}" |
| 96 | +test_script "graphql-inspect-remote.sh" |
| 97 | +test_script "graphql-run-simple.sh" "${MINA_BIN} internal graphql run 'query { syncStatus }' --node ${GRAPHQL_NODE}" |
| 98 | +test_script "graphql-run-stdin.sh" "echo 'query { version }' | ${MINA_BIN} internal graphql run --node ${GRAPHQL_NODE}" |
| 99 | + |
| 100 | +# graphql-run-file.sh needs a query.graphql file in the current directory |
| 101 | +echo "Running graphql-run-file.sh..." |
| 102 | +if [[ ! -f "${QUERY_FILE}" ]]; then |
| 103 | + echo "ERROR: Query file ${QUERY_FILE} not found" |
| 104 | + exit 1 |
| 105 | +fi |
| 106 | +# Create symlink in current directory for the script |
| 107 | +ln -sf "${PWD}/${QUERY_FILE}" query.graphql |
| 108 | +if output=$(${MINA_BIN} internal graphql run -f query.graphql --node "${GRAPHQL_NODE}" 2>&1); then |
| 109 | + echo " SUCCESS: graphql-run-file.sh executed successfully" |
| 110 | +else |
| 111 | + echo "ERROR: graphql-run-file.sh failed:" |
| 112 | + echo "$output" |
| 113 | + rm -f query.graphql |
| 114 | + exit 1 |
| 115 | +fi |
| 116 | +rm -f query.graphql |
| 117 | + |
| 118 | +test_script "graphql-run-variables.sh" "${MINA_BIN} internal graphql run 'query(\$maxLen: Int!) { bestChain(maxLength: \$maxLen) { stateHash } }' -v '{\"maxLen\": 5}' --node ${GRAPHQL_NODE}" |
| 119 | +test_script "graphql-run-remote.sh" |
| 120 | + |
| 121 | +echo "" |
| 122 | +echo "SUCCESS: All 'mina internal graphql' commands and documentation scripts tested" |
0 commit comments