#!/bin/bash
# Quick verification of tunnel routing

echo "=== Testing Tunnel Endpoints ==="
echo ""

test_url() {
    local url=$1
    local name=$2
    echo -n "Testing $name... "
    HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$url" 2>&1)
    if [[ "$HTTP_CODE" =~ ^[2] ]]; then
        echo "✓ OK ($HTTP_CODE)"
        return 0
    else
        echo "✗ Failed ($HTTP_CODE)"
        return 1
    fi
}

test_rpc() {
    local url=$1
    local name=$2
    echo -n "Testing $name... "
    RESPONSE=$(curl -s -X POST "$url" -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' 2>&1)
    HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$url" -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' 2>&1)
    if [[ "$HTTP_CODE" =~ ^[2] ]] && echo "$RESPONSE" | grep -q "result"; then
        echo "✓ OK ($HTTP_CODE)"
        return 0
    else
        echo "✗ Failed ($HTTP_CODE)"
        return 1
    fi
}

test_url "https://explorer.d-bis.org/api/v2/stats" "Explorer"
test_rpc "https://rpc-http-pub.d-bis.org" "RPC Public"
test_rpc "https://rpc-http-prv.d-bis.org" "RPC Private"
test_url "https://dbis-admin.d-bis.org" "DBIS Admin"
test_url "https://dbis-api.d-bis.org/health" "DBIS API"
test_url "https://mim4u.org" "MIM4U"

echo ""
echo "=== Verification Complete ==="
