#!/bin/bash
# Test RPC endpoints
# Usage: ./scripts/test-rpc.sh <HTTP_URL> [WS_URL]

set -e

HTTP_URL="${1:-http://localhost:9545}"
WS_URL="${2:-ws://localhost:9546}"

echo "Testing RPC Translator endpoints..."
echo "HTTP URL: $HTTP_URL"
echo "WS URL: $WS_URL"
echo ""

# Test health endpoint
echo "1. Testing health endpoint..."
curl -s "$HTTP_URL/health" | jq '.' || echo "Failed"
echo ""

# Test eth_chainId
echo "2. Testing eth_chainId..."
curl -s -X POST "$HTTP_URL" \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_chainId",
    "params": [],
    "id": 1
  }' | jq '.' || echo "Failed"
echo ""

# Test eth_blockNumber
echo "3. Testing eth_blockNumber..."
curl -s -X POST "$HTTP_URL" \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_blockNumber",
    "params": [],
    "id": 2
  }' | jq '.' || echo "Failed"
echo ""

# Test eth_gasPrice
echo "4. Testing eth_gasPrice..."
curl -s -X POST "$HTTP_URL" \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_gasPrice",
    "params": [],
    "id": 3
  }' | jq '.' || echo "Failed"
echo ""

echo "✅ RPC tests complete!"
echo ""
echo "Note: To test eth_sendTransaction, you need:"
echo "  - A wallet address in the allowlist"
echo "  - Web3Signer configured with that wallet's key"
echo "  - Proper nonce and gas settings"
echo ""
