Skip to content

Commit 1141c46

Browse files
committed
Add GraphQL compatibility testing workflow for OCaml node
- Add comprehensive CI workflow to test GraphQL queries against OCaml node - Create individual test scripts for each GraphQL endpoint for easy debugging - Use configurable Docker image for OCaml node deployment - Include act documentation for local testing - Update website GraphQL API documentation with implementation status table - Add reproducible test scripts in .github/scripts/test-graphql-remote/ - Update OCaml node update script to include new workflow file
1 parent 5ba8f5d commit 1141c46

16 files changed

+1120
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# GraphQL Remote Test Scripts
2+
3+
This directory contains individual test scripts that can be run against any GraphQL endpoint to verify compatibility with the Mina GraphQL API.
4+
5+
## Usage
6+
7+
### Run All Tests
8+
9+
```bash
10+
# Test against the default endpoint
11+
./run-all-tests.sh
12+
13+
# Test against a custom endpoint
14+
./run-all-tests.sh http://your-node:3085/graphql
15+
16+
# Using environment variable
17+
GRAPHQL_ENDPOINT=http://your-node:3085/graphql ./run-all-tests.sh
18+
```
19+
20+
### Run Individual Tests
21+
22+
Each test script can be run independently:
23+
24+
```bash
25+
# Test basic connectivity
26+
./check-endpoint-availability.sh http://localhost:3085/graphql
27+
28+
# Test specific queries
29+
./test-sync-status.sh http://localhost:3085/graphql
30+
./test-daemon-status.sh http://localhost:3085/graphql
31+
./test-best-chain.sh http://localhost:3085/graphql
32+
```
33+
34+
## Test Scripts
35+
36+
### Core Functionality
37+
- `check-endpoint-availability.sh` - Verify GraphQL endpoint is accessible
38+
- `test-sync-status.sh` - Test syncStatus query
39+
- `test-network-info.sh` - Test networkID and version queries
40+
41+
### Blockchain Data
42+
- `test-daemon-status.sh` - Test daemonStatus query
43+
- `test-best-chain.sh` - Test bestChain query
44+
- `test-block-by-height.sh` - Test block query by height
45+
- `test-genesis-block.sh` - Test genesisBlock query
46+
- `test-genesis-constants.sh` - Test genesisConstants query
47+
48+
### Advanced Tests
49+
- `test-complex-nested-query.sh` - Test complex nested GraphQL queries
50+
- `test-error-handling.sh` - Test GraphQL error handling
51+
52+
### Test Runner
53+
- `run-all-tests.sh` - Master script that runs all tests in sequence
54+
55+
## Prerequisites
56+
57+
- `curl` - For making HTTP requests
58+
- `jq` - For parsing JSON responses
59+
- Access to the website GraphQL scripts (must run from repo root)
60+
61+
## CI Integration
62+
63+
These scripts are used by the GitHub Actions workflow in `.github/workflows/test-graphql-compatibility.yml` to test GraphQL compatibility between Rust and OCaml node implementations.
64+
65+
To run the CI workflow locally using `act`:
66+
67+
```bash
68+
# Install act via gh CLI
69+
gh extension install https://github.com/nektos/gh-act
70+
71+
# Run the workflow
72+
gh act --workflows .github/workflows/test-graphql-compatibility.yml
73+
74+
# Run specific job
75+
gh act --workflows .github/workflows/test-graphql-compatibility.yml --job test-ocaml-node-graphql
76+
```
77+
78+
## Tested Endpoints
79+
80+
These scripts test only the GraphQL endpoints that are implemented in the Rust node:
81+
82+
**Queries:**
83+
- `syncStatus` - Node synchronization status
84+
- `networkID` - Network identifier
85+
- `version` - Node version
86+
- `daemonStatus` - Comprehensive daemon status
87+
- `bestChain` - Best chain blocks
88+
- `block` - Individual block by height/hash
89+
- `genesisBlock` - Genesis block
90+
- `genesisConstants` - Network constants
91+
- `account` - Account information
92+
- `pooledUserCommands` - User commands in transaction pool
93+
- `pooledZkappCommands` - zkApp commands in transaction pool
94+
- `snarkPool` - Completed SNARK work
95+
- `pendingSnarkWork` - Pending SNARK work
96+
- `currentSnarkWorker` - Current SNARK worker info
97+
98+
**Mutations:** (tested via website scripts)
99+
- `sendPayment` - Send payment transactions
100+
- `sendDelegation` - Send delegation transactions
101+
- `sendZkapp` - Send zkApp transactions
102+
103+
## Exit Codes
104+
105+
- `0` - All tests passed
106+
- `1` - One or more tests failed
107+
108+
## Output Format
109+
110+
The scripts provide colored output:
111+
- 🟢 Green: Test passed
112+
- 🔴 Red: Test failed
113+
- 🟡 Yellow: Test information/headers
114+
- 🔵 Blue: Section headers
115+
116+
## Debugging
117+
118+
To debug failed tests:
119+
120+
1. Run individual test scripts to isolate issues
121+
2. Check the GraphQL endpoint is accessible
122+
3. Verify the node is running and synced
123+
4. Check the raw curl commands in the scripts
124+
5. Use the website's GraphQL scripts directly for comparison
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
# Check GraphQL endpoint availability
3+
# Usage: ./01-check-endpoint-availability.sh [GRAPHQL_ENDPOINT]
4+
5+
set -e
6+
7+
GRAPHQL_ENDPOINT="${1:-${GRAPHQL_ENDPOINT:-http://mina-rust-plain-3.gcp.o1test.net/graphql}}"
8+
9+
echo "Testing GraphQL endpoint availability..."
10+
echo "Endpoint: $GRAPHQL_ENDPOINT"
11+
12+
if curl -s --max-time 10 -X POST "$GRAPHQL_ENDPOINT" \
13+
-H "Content-Type: application/json" \
14+
-d '{"query":"{ networkID }"}' > /dev/null; then
15+
echo "✓ GraphQL endpoint is accessible"
16+
exit 0
17+
else
18+
echo "✗ GraphQL endpoint is not accessible"
19+
exit 1
20+
fi
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/bin/bash
2+
# Master test runner for GraphQL remote tests
3+
# Usage: ./run-all-tests.sh [GRAPHQL_ENDPOINT]
4+
#
5+
# This script runs all individual GraphQL test scripts against a remote endpoint.
6+
# It's useful for testing compatibility with different node implementations.
7+
8+
set -e
9+
10+
GRAPHQL_ENDPOINT="${1:-${GRAPHQL_ENDPOINT:-http://mina-rust-plain-3.gcp.o1test.net/graphql}}"
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
13+
14+
# Colors for output
15+
RED='\033[0;31m'
16+
GREEN='\033[0;32m'
17+
YELLOW='\033[1;33m'
18+
BLUE='\033[0;34m'
19+
NC='\033[0m' # No Color
20+
21+
TOTAL_TESTS=0
22+
PASSED_TESTS=0
23+
FAILED_TESTS=0
24+
25+
echo -e "${BLUE}GraphQL Remote Test Suite${NC}"
26+
echo -e "${BLUE}========================${NC}"
27+
echo "Endpoint: $GRAPHQL_ENDPOINT"
28+
echo "Script directory: $SCRIPT_DIR"
29+
echo "Repository root: $REPO_ROOT"
30+
echo ""
31+
32+
# Change to repository root for access to website scripts
33+
cd "$REPO_ROOT"
34+
35+
# Function to run a test script
36+
run_test() {
37+
local test_name="$1"
38+
local script_path="$2"
39+
40+
((TOTAL_TESTS++))
41+
echo -e "${YELLOW}[$TOTAL_TESTS]${NC} Running $test_name..."
42+
43+
if [ ! -f "$script_path" ]; then
44+
echo -e "${RED} ✗ Script not found: $script_path${NC}"
45+
((FAILED_TESTS++))
46+
return 1
47+
fi
48+
49+
# Make script executable
50+
chmod +x "$script_path"
51+
52+
# Run the test with the endpoint
53+
if "$script_path" "$GRAPHQL_ENDPOINT"; then
54+
echo -e "${GREEN} ✓ PASSED${NC}"
55+
((PASSED_TESTS++))
56+
return 0
57+
else
58+
echo -e "${RED} ✗ FAILED${NC}"
59+
((FAILED_TESTS++))
60+
return 1
61+
fi
62+
}
63+
64+
# List of GraphQL endpoints implemented in Rust (based on our analysis)
65+
echo -e "${BLUE}Testing GraphQL endpoints that are implemented in Rust node:${NC}"
66+
echo ""
67+
68+
# Core network and status queries
69+
run_test "Check endpoint availability" "$SCRIPT_DIR/check-endpoint-availability.sh"
70+
run_test "Sync status query" "$SCRIPT_DIR/test-sync-status.sh"
71+
run_test "Network ID query" "$SCRIPT_DIR/test-network-info.sh"
72+
73+
# Daemon and blockchain info
74+
run_test "Daemon status query" "$SCRIPT_DIR/test-daemon-status.sh"
75+
run_test "Best chain query" "$SCRIPT_DIR/test-best-chain.sh"
76+
run_test "Block query by height" "$SCRIPT_DIR/test-block-by-height.sh"
77+
run_test "Genesis block query" "$SCRIPT_DIR/test-genesis-block.sh"
78+
run_test "Genesis constants query" "$SCRIPT_DIR/test-genesis-constants.sh"
79+
80+
# Advanced queries
81+
run_test "Complex nested query" "$SCRIPT_DIR/test-complex-nested-query.sh"
82+
run_test "Error handling" "$SCRIPT_DIR/test-error-handling.sh"
83+
84+
echo ""
85+
echo -e "${BLUE}===============================================${NC}"
86+
echo -e "${BLUE}Test Results Summary${NC}"
87+
echo -e "${BLUE}===============================================${NC}"
88+
echo "Total tests: $TOTAL_TESTS"
89+
echo -e "Passed: ${GREEN}$PASSED_TESTS${NC}"
90+
echo -e "Failed: ${RED}$FAILED_TESTS${NC}"
91+
92+
if [ $FAILED_TESTS -eq 0 ]; then
93+
echo -e "${GREEN}🎉 All tests passed!${NC}"
94+
echo ""
95+
echo "The endpoint appears to be compatible with the expected GraphQL schema."
96+
echo "All implemented Rust node endpoints work correctly."
97+
else
98+
echo -e "${RED}❌ Some tests failed${NC}"
99+
echo ""
100+
echo "Some GraphQL endpoints may not be working correctly or may have"
101+
echo "different implementations between the Rust and OCaml nodes."
102+
103+
success_rate=$(( PASSED_TESTS * 100 / TOTAL_TESTS ))
104+
echo "Success rate: $success_rate%"
105+
106+
if [ $success_rate -ge 80 ]; then
107+
echo -e "${YELLOW}Most endpoints are working correctly.${NC}"
108+
elif [ $success_rate -ge 50 ]; then
109+
echo -e "${YELLOW}Moderate compatibility - some issues detected.${NC}"
110+
else
111+
echo -e "${RED}Low compatibility - significant issues detected.${NC}"
112+
fi
113+
114+
exit 1
115+
fi
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
# Test best chain query
3+
# Usage: ./03-test-best-chain.sh [GRAPHQL_ENDPOINT]
4+
5+
set -e
6+
7+
GRAPHQL_ENDPOINT="${1:-${GRAPHQL_ENDPOINT:-http://mina-rust-plain-3.gcp.o1test.net/graphql}}"
8+
9+
echo "Testing bestChain query..."
10+
echo "Endpoint: $GRAPHQL_ENDPOINT"
11+
12+
response=$(GRAPHQL_ENDPOINT="$GRAPHQL_ENDPOINT" ./website/docs/developers/scripts/graphql-api/queries/curl/best-chain.sh)
13+
echo "Response: $response"
14+
15+
state_hash=$(echo "$response" | jq -r '.data.bestChain[0].stateHash // empty')
16+
if [ -n "$state_hash" ]; then
17+
echo "✓ Best chain query successful"
18+
19+
# Extract block height if available
20+
height=$(echo "$response" | jq -r '.data.bestChain[0].protocolState.consensusState.blockHeight // empty')
21+
if [ -n "$height" ]; then
22+
echo " Latest block height: $height"
23+
fi
24+
else
25+
echo "✗ Failed to get best chain"
26+
exit 1
27+
fi
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Test block query by height
3+
# Usage: ./04-test-block-by-height.sh [GRAPHQL_ENDPOINT]
4+
5+
set -e
6+
7+
GRAPHQL_ENDPOINT="${1:-${GRAPHQL_ENDPOINT:-http://mina-rust-plain-3.gcp.o1test.net/graphql}}"
8+
9+
echo "Testing block query by height..."
10+
echo "Endpoint: $GRAPHQL_ENDPOINT"
11+
12+
# Get current height from best chain first
13+
best_chain_response=$(GRAPHQL_ENDPOINT="$GRAPHQL_ENDPOINT" ./website/docs/developers/scripts/graphql-api/queries/curl/best-chain.sh)
14+
15+
current_height=$(echo "$best_chain_response" | jq -r '.data.bestChain[0].protocolState.consensusState.blockHeight // empty')
16+
if [ -n "$current_height" ]; then
17+
echo "Current height: $current_height"
18+
19+
# Test with current height - use website script if available, otherwise create query
20+
if [ -f "./website/docs/developers/scripts/graphql-api/queries/curl/block.sh" ]; then
21+
response=$(GRAPHQL_ENDPOINT="$GRAPHQL_ENDPOINT" ./website/docs/developers/scripts/graphql-api/queries/curl/block.sh)
22+
else
23+
# Fallback: create direct query
24+
response=$(curl -s --max-time 15 -X POST "$GRAPHQL_ENDPOINT" \
25+
-H "Content-Type: application/json" \
26+
-d "{\"query\":\"{ block(height: $current_height) { stateHash protocolState { consensusState { blockHeight } } } }\"}")
27+
fi
28+
29+
echo "Block query response: $response"
30+
31+
block_state_hash=$(echo "$response" | jq -r '.data.block.stateHash // empty')
32+
if [ -n "$block_state_hash" ]; then
33+
echo "✓ Block query by height successful"
34+
else
35+
echo "✗ Failed to get block by height"
36+
exit 1
37+
fi
38+
else
39+
echo "? Could not determine current height, skipping block query test"
40+
fi
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# Test complex nested query
3+
# Usage: ./test-complex-nested-query.sh [GRAPHQL_ENDPOINT]
4+
5+
set -e
6+
7+
GRAPHQL_ENDPOINT="${1:-${GRAPHQL_ENDPOINT:-http://mina-rust-plain-3.gcp.o1test.net/graphql}}"
8+
9+
echo "Testing complex nested query..."
10+
echo "Endpoint: $GRAPHQL_ENDPOINT"
11+
12+
query='{ bestChain(maxLength: 2) { stateHash protocolState { consensusState { blockHeight epoch slot } blockchainState { snarkedLedgerHash } } } syncStatus networkID }'
13+
14+
response=$(curl -s --max-time 15 -X POST "$GRAPHQL_ENDPOINT" \
15+
-H "Content-Type: application/json" \
16+
-d "{\"query\":\"$query\"}")
17+
18+
echo "Complex query response: $response"
19+
20+
# Check if all expected fields are present
21+
state_hash_complex=$(echo "$response" | jq -r '.data.bestChain[0].stateHash // empty')
22+
sync_status_complex=$(echo "$response" | jq -r '.data.syncStatus // empty')
23+
network_id_complex=$(echo "$response" | jq -r '.data.networkID // empty')
24+
25+
if [ -n "$state_hash_complex" ] && [ -n "$sync_status_complex" ] && [ -n "$network_id_complex" ]; then
26+
echo "✓ Complex nested query successful"
27+
else
28+
echo "✗ Complex nested query failed"
29+
exit 1
30+
fi

0 commit comments

Comments
 (0)