#!/bin/bash # End-to-End Flow Test Script # Tests: create plan → sign → execute → view receipt echo -e "\n========================================" echo -e " END-TO-END FLOW TEST" echo -e "========================================\n" # Colors GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[0;33m' NC='\033[0m' # No Color # Check if orchestrator is running echo -e "1. Checking orchestrator service..." if ! curl -s http://localhost:8080/health > /dev/null 2>&1; then echo -e " ${RED}❌ Orchestrator not running${NC}" echo -e " Start it with: cd orchestrator && npm run dev" exit 1 fi echo -e " ${GREEN}✅ Orchestrator is running${NC}" # Check if webapp is running echo -e "\n2. Checking webapp service..." if ! curl -s http://localhost:3000 > /dev/null 2>&1; then echo -e " ${YELLOW}⚠️ Webapp not running (optional for API tests)${NC}" else echo -e " ${GREEN}✅ Webapp is running${NC}" fi # Test 1: Create a plan echo -e "\n3. Creating a test plan..." PLAN_DATA='{ "creator": "test-user-123", "steps": [ { "type": "borrow", "adapter": "aave", "params": { "asset": "USDC", "amount": "1000" } }, { "type": "swap", "adapter": "uniswap", "params": { "tokenIn": "USDC", "tokenOut": "ETH", "amountIn": "1000" } } ], "maxRecursion": 3, "maxLtv": 0.6 }' CREATE_RESPONSE=$(curl -s -X POST http://localhost:8080/api/plans \ -H "Content-Type: application/json" \ -d "$PLAN_DATA" \ -w "\n%{http_code}") HTTP_CODE=$(echo "$CREATE_RESPONSE" | tail -n1) BODY=$(echo "$CREATE_RESPONSE" | sed '$d') if [ "$HTTP_CODE" = "201" ] || [ "$HTTP_CODE" = "200" ]; then echo -e " ${GREEN}✅ Plan created successfully${NC}" # Extract plan_id if command -v jq &> /dev/null; then PLAN_ID=$(echo "$BODY" | jq -r '.plan_id // .id // empty' 2>/dev/null) if [ -n "$PLAN_ID" ] && [ "$PLAN_ID" != "null" ]; then echo -e " Plan ID: $PLAN_ID" else echo -e " ${YELLOW}⚠️ Could not extract plan_id from response${NC}" PLAN_ID="" fi else echo -e " ${YELLOW}⚠️ jq not installed, cannot extract plan_id${NC}" PLAN_ID="" fi else echo -e " ${RED}❌ Failed to create plan (HTTP $HTTP_CODE)${NC}" echo -e " Response: $BODY" exit 1 fi # Test 2: Get the plan if [ -n "$PLAN_ID" ]; then echo -e "\n4. Retrieving plan..." GET_RESPONSE=$(curl -s -w "\n%{http_code}" http://localhost:8080/api/plans/$PLAN_ID) GET_HTTP_CODE=$(echo "$GET_RESPONSE" | tail -n1) if [ "$GET_HTTP_CODE" = "200" ]; then echo -e " ${GREEN}✅ Plan retrieved successfully${NC}" else echo -e " ${YELLOW}⚠️ Could not retrieve plan (HTTP $GET_HTTP_CODE)${NC}" fi fi # Test 3: Add signature (mock) if [ -n "$PLAN_ID" ]; then echo -e "\n5. Adding signature to plan..." SIGNATURE_DATA='{ "signature": "0x1234567890abcdef", "messageHash": "0xabcdef1234567890", "signerAddress": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb" }' SIGN_RESPONSE=$(curl -s -X POST http://localhost:8080/api/plans/$PLAN_ID/signature \ -H "Content-Type: application/json" \ -d "$SIGNATURE_DATA" \ -w "\n%{http_code}") SIGN_HTTP_CODE=$(echo "$SIGN_RESPONSE" | tail -n1) if [ "$SIGN_HTTP_CODE" = "200" ] || [ "$SIGN_HTTP_CODE" = "201" ]; then echo -e " ${GREEN}✅ Signature added successfully${NC}" else echo -e " ${YELLOW}⚠️ Could not add signature (HTTP $SIGN_HTTP_CODE)${NC}" fi fi # Test 4: Validate plan if [ -n "$PLAN_ID" ]; then echo -e "\n6. Validating plan..." VALIDATE_RESPONSE=$(curl -s -X POST http://localhost:8080/api/plans/$PLAN_ID/validate \ -w "\n%{http_code}") VALIDATE_HTTP_CODE=$(echo "$VALIDATE_RESPONSE" | tail -n1) if [ "$VALIDATE_HTTP_CODE" = "200" ]; then echo -e " ${GREEN}✅ Plan validation successful${NC}" if command -v jq &> /dev/null; then VALID=$(echo "$VALIDATE_RESPONSE" | sed '$d' | jq -r '.valid // false' 2>/dev/null) if [ "$VALID" = "true" ]; then echo -e " Plan is valid: ${GREEN}✅${NC}" else echo -e " Plan validation: ${YELLOW}⚠️${NC}" fi fi else echo -e " ${YELLOW}⚠️ Could not validate plan (HTTP $VALIDATE_HTTP_CODE)${NC}" fi fi # Test 5: Check execution endpoint (if available) echo -e "\n7. Testing execution endpoint..." EXEC_RESPONSE=$(curl -s -X POST http://localhost:8080/api/execution/execute \ -H "Content-Type: application/json" \ -d "{\"plan_id\": \"$PLAN_ID\"}" \ -w "\n%{http_code}" 2>/dev/null) if [ $? -eq 0 ]; then EXEC_HTTP_CODE=$(echo "$EXEC_RESPONSE" | tail -n1) if [ "$EXEC_HTTP_CODE" = "200" ] || [ "$EXEC_HTTP_CODE" = "202" ]; then echo -e " ${GREEN}✅ Execution endpoint accessible${NC}" else echo -e " ${YELLOW}⚠️ Execution endpoint returned HTTP $EXEC_HTTP_CODE${NC}" fi else echo -e " ${YELLOW}⚠️ Execution endpoint not available or requires authentication${NC}" fi # Summary echo -e "\n========================================" echo -e " TEST SUMMARY" echo -e "========================================\n" echo -e "${GREEN}✅ Basic flow test completed${NC}" if [ -n "$PLAN_ID" ]; then echo -e " Test plan ID: $PLAN_ID" echo -e " View plan: http://localhost:8080/api/plans/$PLAN_ID" fi echo -e "\n📝 Next steps:" echo -e " 1. Test full execution flow via webapp UI" echo -e " 2. Verify receipt generation" echo -e " 3. Check audit logs" echo ""