Skip to content

Commit 146fb99

Browse files
authored
Merge pull request #1402 from o1-labs/dw/graphql-e2e-tests
CI: add GraphQL integration
2 parents 2ec7ecc + ead9d95 commit 146fb99

File tree

8 files changed

+329
-0
lines changed

8 files changed

+329
-0
lines changed
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
name: Remote GraphQL Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
schedule:
8+
# Run daily at 00:00 UTC
9+
- cron: '0 0 * * *'
10+
11+
env:
12+
GRAPHQL_ENDPOINT: http://mina-rust-plain-3.gcp.o1test.net/graphql
13+
14+
jobs:
15+
remote-graphql-tests:
16+
name: Test Remote GraphQL Endpoint
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Check GraphQL endpoint availability
25+
run: |
26+
echo "Testing GraphQL endpoint availability..."
27+
28+
if curl -s --max-time 10 -X POST $GRAPHQL_ENDPOINT \
29+
-H "Content-Type: application/json" \
30+
-d '{"query":"{ networkID }"}' > /dev/null; then
31+
echo "✓ GraphQL endpoint is accessible"
32+
else
33+
echo "✗ GraphQL endpoint is not accessible"
34+
exit 1
35+
fi
36+
37+
- name: Test sync_status query
38+
run: |
39+
echo "Testing syncStatus query..."
40+
41+
response=$(GRAPHQL_ENDPOINT=$GRAPHQL_ENDPOINT ./website/docs/developers/scripts/graphql-queries/sync_status.sh)
42+
echo "Response: $response"
43+
44+
status=$(echo "$response" | jq -r '.data.syncStatus // empty')
45+
if [ -n "$status" ]; then
46+
echo "✓ Sync Status: $status"
47+
48+
case "$status" in
49+
"SYNCED"|"CATCHUP"|"BOOTSTRAP"|"CONNECTING"|"LISTENING")
50+
echo "✓ Valid sync status received"
51+
;;
52+
*)
53+
echo "? Unknown sync status: $status"
54+
;;
55+
esac
56+
else
57+
echo "✗ Failed to get sync status"
58+
exit 1
59+
fi
60+
61+
- name: Test best_chain query
62+
run: |
63+
echo "Testing bestChain query..."
64+
65+
response=$(GRAPHQL_ENDPOINT=$GRAPHQL_ENDPOINT ./website/docs/developers/scripts/graphql-queries/best_chain.sh)
66+
echo "Response: $response"
67+
68+
state_hash=$(echo "$response" | jq -r '.data.bestChain[0].stateHash // empty')
69+
if [ -n "$state_hash" ]; then
70+
echo "✓ Best chain query successful"
71+
72+
# Extract block height if available
73+
height=$(echo "$response" | jq -r '.data.bestChain[0].protocolState.consensusState.blockHeight // empty')
74+
if [ -n "$height" ]; then
75+
echo " Latest block height: $height"
76+
fi
77+
else
78+
echo "✗ Failed to get best chain"
79+
exit 1
80+
fi
81+
82+
- name: Test block query by height
83+
run: |
84+
echo "Testing block query by height..."
85+
86+
# Get current height from best chain first
87+
best_chain_response=$(GRAPHQL_ENDPOINT=$GRAPHQL_ENDPOINT ./website/docs/developers/scripts/graphql-queries/best_chain.sh)
88+
89+
current_height=$(echo "$best_chain_response" | jq -r '.data.bestChain[0].protocolState.consensusState.blockHeight // empty')
90+
if [ -n "$current_height" ]; then
91+
echo "Current height: $current_height"
92+
93+
# Test with current height
94+
response=$(GRAPHQL_ENDPOINT=$GRAPHQL_ENDPOINT ./website/docs/developers/scripts/graphql-queries/block_by_height.sh $current_height)
95+
echo "Block query response: $response"
96+
97+
block_state_hash=$(echo "$response" | jq -r '.data.block.stateHash // empty')
98+
if [ -n "$block_state_hash" ]; then
99+
echo "✓ Block query by height successful"
100+
else
101+
echo "✗ Failed to get block by height"
102+
exit 1
103+
fi
104+
else
105+
echo "? Could not determine current height, skipping block query test"
106+
fi
107+
108+
- name: Test genesis_block query
109+
run: |
110+
echo "Testing genesisBlock query..."
111+
112+
response=$(GRAPHQL_ENDPOINT=$GRAPHQL_ENDPOINT ./website/docs/developers/scripts/graphql-queries/genesis_block.sh)
113+
echo "Response: $response"
114+
115+
genesis_state_hash=$(echo "$response" | jq -r '.data.genesisBlock.stateHash // empty')
116+
if [ -n "$genesis_state_hash" ]; then
117+
echo "✓ Genesis block query successful"
118+
119+
# Extract genesis block height
120+
genesis_height=$(echo "$response" | jq -r '.data.genesisBlock.protocolState.consensusState.blockHeight // empty')
121+
if [ -n "$genesis_height" ]; then
122+
echo "Genesis block height: $genesis_height"
123+
fi
124+
else
125+
echo "✗ Failed to get genesis block"
126+
exit 1
127+
fi
128+
129+
- name: Test genesis_constants query
130+
run: |
131+
echo "Testing genesisConstants query..."
132+
133+
response=$(GRAPHQL_ENDPOINT=$GRAPHQL_ENDPOINT ./website/docs/developers/scripts/graphql-queries/genesis_constants.sh)
134+
echo "Response: $response"
135+
136+
account_creation_fee=$(echo "$response" | jq -r '.data.genesisConstants.accountCreationFee // empty')
137+
if [ -n "$account_creation_fee" ]; then
138+
echo "✓ Genesis constants query successful"
139+
140+
# Extract and display some key constants
141+
coinbase=$(echo "$response" | jq -r '.data.genesisConstants.coinbase // empty')
142+
if [ -n "$coinbase" ]; then
143+
echo " Coinbase reward: $coinbase"
144+
fi
145+
146+
fee=$(echo "$response" | jq -r '.data.genesisConstants.accountCreationFee // empty')
147+
if [ -n "$fee" ]; then
148+
echo " Account creation fee: $fee"
149+
fi
150+
else
151+
echo "✗ Failed to get genesis constants"
152+
exit 1
153+
fi
154+
155+
- name: Test daemon_status query
156+
run: |
157+
echo "Testing daemonStatus query..."
158+
159+
response=$(GRAPHQL_ENDPOINT=$GRAPHQL_ENDPOINT ./website/docs/developers/scripts/graphql-queries/daemon_status.sh)
160+
echo "Response: $response"
161+
162+
chain_id_check=$(echo "$response" | jq -r '.data.daemonStatus.chainId // empty')
163+
if [ -n "$chain_id_check" ]; then
164+
echo "✓ Daemon status query successful"
165+
166+
# Extract chain ID
167+
chain_id=$(echo "$response" | jq -r '.data.daemonStatus.chainId // empty')
168+
if [ -n "$chain_id" ]; then
169+
echo " Chain ID: $chain_id"
170+
fi
171+
172+
# Extract commit ID if available
173+
commit_id=$(echo "$response" | jq -r '.data.daemonStatus.commitId // empty')
174+
if [ -n "$commit_id" ]; then
175+
echo " Commit ID: $commit_id"
176+
fi
177+
else
178+
echo "✗ Failed to get daemon status"
179+
exit 1
180+
fi
181+
182+
- name: Test network information queries
183+
run: |
184+
echo "Testing network information queries..."
185+
186+
response=$(GRAPHQL_ENDPOINT=$GRAPHQL_ENDPOINT ./website/docs/developers/scripts/graphql-queries/network_info.sh)
187+
echo "Response: $response"
188+
189+
network_id=$(echo "$response" | jq -r '.data.networkID // empty')
190+
if [ -n "$network_id" ]; then
191+
echo "✓ Network ID: $network_id"
192+
else
193+
echo "✗ Failed to get network ID"
194+
exit 1
195+
fi
196+
197+
version=$(echo "$response" | jq -r '.data.version // empty')
198+
if [ -n "$version" ]; then
199+
echo "✓ Node version: $version"
200+
else
201+
echo "? Version query failed (might not be available)"
202+
fi
203+
204+
- name: Test complex nested query
205+
run: |
206+
echo "Testing complex nested query..."
207+
208+
query='{ bestChain(maxLength: 2) { stateHash protocolState { consensusState { blockHeight epoch slot } blockchainState { snarkedLedgerHash } } } syncStatus networkID }'
209+
210+
response=$(curl -s --max-time 15 -X POST $GRAPHQL_ENDPOINT \
211+
-H "Content-Type: application/json" \
212+
-d "{\"query\":\"$query\"}")
213+
214+
echo "Complex query response: $response"
215+
216+
# Check if all expected fields are present
217+
state_hash_complex=$(echo "$response" | jq -r '.data.bestChain[0].stateHash // empty')
218+
sync_status_complex=$(echo "$response" | jq -r '.data.syncStatus // empty')
219+
network_id_complex=$(echo "$response" | jq -r '.data.networkID // empty')
220+
221+
if [ -n "$state_hash_complex" ] && [ -n "$sync_status_complex" ] && [ -n "$network_id_complex" ]; then
222+
echo "✓ Complex nested query successful"
223+
else
224+
echo "✗ Complex nested query failed"
225+
exit 1
226+
fi
227+
228+
- name: Test error handling
229+
run: |
230+
echo "Testing GraphQL error handling..."
231+
232+
# Test invalid query
233+
echo "Testing invalid query syntax..."
234+
error_response=$(curl -s --max-time 10 -X POST $GRAPHQL_ENDPOINT \
235+
-H "Content-Type: application/json" \
236+
-d '{"query":"{ invalidField }"}')
237+
238+
errors=$(echo "$error_response" | jq -r '.errors // empty')
239+
if [ -n "$errors" ]; then
240+
echo "✓ Invalid query properly returns errors"
241+
else
242+
echo "? Invalid query handling unclear"
243+
fi
244+
245+
# Test malformed JSON
246+
echo "Testing malformed request..."
247+
malformed_response=$(curl -s --max-time 10 -X POST $GRAPHQL_ENDPOINT \
248+
-H "Content-Type: application/json" \
249+
-d '{"query":"}' || echo "request_failed")
250+
251+
if echo "$malformed_response" | jq -e '.errors' > /dev/null 2>&1 || echo "$malformed_response" | grep -q "request_failed"; then
252+
echo "✓ Malformed requests are handled"
253+
else
254+
echo "? Malformed request handling unclear"
255+
fi
256+
257+
- name: Performance check
258+
run: |
259+
echo "Testing GraphQL performance..."
260+
261+
start_time=$(date +%s%N)
262+
263+
response=$(curl -s --max-time 10 -X POST $GRAPHQL_ENDPOINT \
264+
-H "Content-Type: application/json" \
265+
-d '{"query":"{ syncStatus networkID }"}')
266+
267+
end_time=$(date +%s%N)
268+
duration_ms=$(( (end_time - start_time) / 1000000 ))
269+
270+
echo "Simple query took: ${duration_ms}ms"
271+
272+
if [ $duration_ms -lt 5000 ]; then
273+
echo "✓ Query performance is good (< 5s)"
274+
elif [ $duration_ms -lt 10000 ]; then
275+
echo "⚠ Query performance is acceptable (< 10s)"
276+
else
277+
echo "? Query performance might be slow (> 10s)"
278+
fi
279+
280+
perf_sync_status=$(echo "$response" | jq -r '.data.syncStatus // empty')
281+
if [ -n "$perf_sync_status" ]; then
282+
echo "✓ Performance test query successful"
283+
else
284+
echo "✗ Performance test query failed"
285+
exit 1
286+
fi
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
curl -X POST "${GRAPHQL_ENDPOINT:-http://127.0.0.1:3085/graphql}" \
4+
-H "Content-Type: application/json" \
5+
-d '{"query":"{ bestChain(maxLength: 3) { stateHash protocolState { consensusState { blockHeight epoch slot } blockchainState { snarkedLedgerHash } } } }"}'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
HEIGHT="$1"
4+
5+
if [ -z "$HEIGHT" ]; then
6+
echo "Usage: $0 <height>"
7+
echo "Example: $0 12345"
8+
exit 1
9+
fi
10+
11+
curl -X POST "${GRAPHQL_ENDPOINT:-http://127.0.0.1:3085/graphql}" \
12+
-H "Content-Type: application/json" \
13+
-d "{\"query\":\"{ block(height: $HEIGHT) { stateHash protocolState { consensusState { blockHeight epoch slot } blockchainState { snarkedLedgerHash } } transactions { userCommands { id } zkappCommands { id } } } }\"}"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
curl -X POST "${GRAPHQL_ENDPOINT:-http://127.0.0.1:3085/graphql}" \
4+
-H "Content-Type: application/json" \
5+
-d '{"query":"{ daemonStatus { chainId commitId addrsAndPorts { bindIp clientPort libp2pPort } } }"}'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
curl -X POST "${GRAPHQL_ENDPOINT:-http://127.0.0.1:3085/graphql}" \
4+
-H "Content-Type: application/json" \
5+
-d '{"query":"{ genesisBlock { stateHash protocolState { consensusState { blockHeight epoch slot } blockchainState { snarkedLedgerHash } } transactions { userCommands { id } zkappCommands { id } } } }"}'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
curl -X POST "${GRAPHQL_ENDPOINT:-http://127.0.0.1:3085/graphql}" \
4+
-H "Content-Type: application/json" \
5+
-d '{"query":"{ genesisConstants { accountCreationFee coinbase } }"}'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
curl -X POST "${GRAPHQL_ENDPOINT:-http://127.0.0.1:3085/graphql}" \
4+
-H "Content-Type: application/json" \
5+
-d '{"query":"{ networkID version }"}'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
curl -X POST "${GRAPHQL_ENDPOINT:-http://127.0.0.1:3085/graphql}" \
4+
-H "Content-Type: application/json" \
5+
-d '{"query":"{ syncStatus }"}'

0 commit comments

Comments
 (0)