-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.sh
More file actions
executable file
·239 lines (203 loc) · 8.02 KB
/
Copy pathscript.sh
File metadata and controls
executable file
·239 lines (203 loc) · 8.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
# Prover API Test Suite
# Automated testing script for all Prover API improvements
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Test counters
TESTS_RUN=0
TESTS_PASSED=0
TESTS_FAILED=0
# Backend process tracking
BACKEND_PID=""
BACKEND_STARTED_BY_SCRIPT=false
# Cleanup function
cleanup() {
if [ "$BACKEND_STARTED_BY_SCRIPT" = true ] && [ -n "$BACKEND_PID" ]; then
echo -e "\n${YELLOW}Stopping backend (PID: $BACKEND_PID)...${NC}"
kill $BACKEND_PID 2>/dev/null || true
wait $BACKEND_PID 2>/dev/null || true
echo -e "${GREEN}Backend stopped.${NC}"
fi
}
# Register cleanup function
trap cleanup EXIT INT TERM
# Function to print test header
print_test() {
echo -e "\n${BLUE}========================================${NC}"
echo -e "${BLUE}Test $1: $2${NC}"
echo -e "${BLUE}========================================${NC}\n"
TESTS_RUN=$((TESTS_RUN + 1))
}
# Function to print success
print_success() {
echo -e "${GREEN}✅ PASSED${NC}: $1\n"
TESTS_PASSED=$((TESTS_PASSED + 1))
}
# Function to print failure
print_fail() {
echo -e "${RED}❌ FAILED${NC}: $1\n"
TESTS_FAILED=$((TESTS_FAILED + 1))
}
# Function to print warning
print_warning() {
echo -e "${YELLOW}⚠️ WARNING${NC}: $1\n"
}
# Function to check if backend is running
check_backend() {
if curl -s http://localhost:3001/health > /dev/null 2>&1; then
return 0
else
return 1
fi
}
# Function to start backend
start_backend() {
echo -e "${YELLOW}Starting backend...${NC}"
cd backend
RUST_LOG=debug cargo run > /tmp/backend.log 2>&1 &
BACKEND_PID=$!
cd ..
BACKEND_STARTED_BY_SCRIPT=true
echo -e "${YELLOW}Waiting for backend to be ready (PID: $BACKEND_PID)...${NC}"
# Wait up to 60 seconds for backend to start
for i in {1..60}; do
if check_backend; then
echo -e "${GREEN}Backend is ready!${NC}\n"
return 0
fi
sleep 1
echo -n "."
done
echo -e "\n${RED}Backend failed to start within 60 seconds${NC}"
echo -e "${YELLOW}Check /tmp/backend.log for errors${NC}"
return 1
}
echo -e "${BLUE}"
echo "╔════════════════════════════════════════════════════════╗"
echo "║ Prover API Fix - Automated Test Suite ║"
echo "╔════════════════════════════════════════════════════════╗"
echo -e "${NC}\n"
# Check if backend is running
print_test "0" "Backend Status Check"
if check_backend; then
print_success "Backend is already running on port 3001"
else
echo -e "${YELLOW}Backend is not running. Starting it automatically...${NC}\n"
if start_backend; then
print_success "Backend started successfully on port 3001"
else
print_fail "Failed to start backend!"
echo -e "${YELLOW}Try starting it manually:${NC}"
echo " cd backend"
echo " RUST_LOG=debug cargo run"
exit 1
fi
fi
# Test 1: Overall Health Check
print_test "1" "Overall System Health Check"
HEALTH_RESPONSE=$(curl -s http://localhost:3001/api/health)
if echo "$HEALTH_RESPONSE" | grep -q '"status":"healthy"'; then
print_success "System is healthy"
# Check Prover API status in health response
if echo "$HEALTH_RESPONSE" | grep -q '"reachable":true'; then
print_success "Prover API is reachable"
# Extract latency
LATENCY=$(echo "$HEALTH_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['prover_api']['latency_ms'])" 2>/dev/null || echo "unknown")
echo -e " ${GREEN}→${NC} Latency: ${LATENCY}ms"
else
print_warning "Prover API may not be reachable"
fi
# Check mock mode
if echo "$HEALTH_RESPONSE" | grep -q '"mock_mode":true'; then
echo -e " ${YELLOW}→${NC} Mock mode: ENABLED"
else
echo -e " ${GREEN}→${NC} Mock mode: DISABLED"
fi
else
print_fail "Health check failed"
echo "$HEALTH_RESPONSE"
fi
# Test 2: Prover API Specific Health Check
print_test "2" "Prover API Health Check"
PROVER_RESPONSE=$(curl -s http://localhost:3001/api/health/prover)
if echo "$PROVER_RESPONSE" | grep -q '"reachable":true'; then
LATENCY=$(echo "$PROVER_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['latency_ms'])" 2>/dev/null || echo "unknown")
API_URL=$(echo "$PROVER_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['url'])" 2>/dev/null || echo "unknown")
print_success "Prover API is reachable"
echo -e " ${GREEN}→${NC} URL: $API_URL"
echo -e " ${GREEN}→${NC} Latency: ${LATENCY}ms"
else
print_fail "Prover API is not reachable"
echo "$PROVER_RESPONSE"
fi
# Test 3: Unit Tests
print_test "3" "Unit Tests"
echo "Running cargo test in backend directory..."
cd backend
if cargo test 2>&1 | tee /tmp/test_output.txt | tail -20; then
# Count passed tests
PASSED=$(grep "test result:" /tmp/test_output.txt | grep -oE "[0-9]+ passed" | grep -oE "[0-9]+" || echo "0")
FAILED=$(grep "test result:" /tmp/test_output.txt | grep -oE "[0-9]+ failed" | grep -oE "[0-9]+" || echo "0")
if [ "$FAILED" -eq "0" ]; then
print_success "All unit tests passed ($PASSED tests)"
else
print_fail "$FAILED test(s) failed"
fi
else
print_fail "Unit tests encountered compilation errors"
fi
cd ..
# Test 4: Mock Mode Spell Prove Endpoint
print_test "4" "Mock Mode Spell Prove Endpoint"
SPELL_RESPONSE=$(curl -s -X POST http://localhost:3001/api/spells/prove \
-H "Content-Type: application/json" \
-d '{
"spell_yaml": "version: 8\nstate: []",
"app_binary": "",
"prev_txs": [],
"funding_utxo": "test:0",
"funding_utxo_value": 10000,
"change_address": "tb1qtest",
"fee_rate": 10.0
}')
if echo "$SPELL_RESPONSE" | grep -q '"success":true'; then
TX_COUNT=$(echo "$SPELL_RESPONSE" | python3 -c "import sys, json; print(len(json.load(sys.stdin)['transactions']))" 2>/dev/null || echo "0")
print_success "Spell prove endpoint working"
echo -e " ${GREEN}→${NC} Returned $TX_COUNT transaction(s)"
echo -e " ${GREEN}→${NC} Mock mode functioning correctly"
else
print_fail "Spell prove endpoint failed"
echo "$SPELL_RESPONSE"
fi
# Test 5: Environment Validation (check logs)
print_test "5" "Environment Validation Check"
print_warning "Manual check required - verify startup logs show:"
echo " ✅ === Environment Validation ==="
echo " ✅ Prover API URL displayed"
echo " ✅ Mock mode status shown"
echo " ✅ Configuration displayed with ✅/⚠️ indicators"
echo ""
echo "Check the backend terminal for these messages on startup."
# Final Summary
echo -e "\n${BLUE}========================================${NC}"
echo -e "${BLUE} Test Summary ${NC}"
echo -e "${BLUE}========================================${NC}\n"
echo -e "Total Tests Run: ${BLUE}$TESTS_RUN${NC}"
echo -e "Tests Passed: ${GREEN}$TESTS_PASSED${NC}"
echo -e "Tests Failed: ${RED}$TESTS_FAILED${NC}"
if [ $TESTS_FAILED -eq 0 ]; then
echo -e "\n${GREEN}╔════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ ✅ ALL TESTS PASSED! 🎉 ║${NC}"
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}\n"
exit 0
else
echo -e "\n${RED}╔════════════════════════════════════════╗${NC}"
echo -e "${RED}║ ❌ SOME TESTS FAILED ║${NC}"
echo -e "${RED}╔════════════════════════════════════════╗${NC}\n"
exit 1
fi