#!/bin/bash

echo "=== Test Mode Verification ==="
echo ""

# Expected test keys from .test_keys
EXPECTED_ADMIN_PUBKEY="8ff74724ed641b3c28e5a86d7c5cbc49c37638ace8c6c38935860e7a5eedde0e"
EXPECTED_SERVER_PUBKEY="52e366edfa4e9cc6a6d4653828e51ccf828a2f5a05227d7a768f33b5a198681a"

echo "1. Checking database keys (should be OLD keys, not test keys)..."
DB_ADMIN_PUBKEY=$(sqlite3 db/ginxsom.db "SELECT value FROM config WHERE key = 'admin_pubkey'")
DB_BLOSSOM_PUBKEY=$(sqlite3 db/ginxsom.db "SELECT value FROM config WHERE key = 'blossom_pubkey'")
DB_BLOSSOM_SECKEY=$(sqlite3 db/ginxsom.db "SELECT seckey FROM blossom_seckey WHERE id = 1")

echo "   Database admin_pubkey: '$DB_ADMIN_PUBKEY'"
echo "   Database blossom_pubkey: '$DB_BLOSSOM_PUBKEY'"
echo "   Database blossom_seckey: '$DB_BLOSSOM_SECKEY'"
echo ""

# Verify database was NOT modified with test keys
if [ "$DB_ADMIN_PUBKEY" = "$EXPECTED_ADMIN_PUBKEY" ]; then
    echo "   ❌ FAIL: Database admin_pubkey matches test key (should NOT be modified)"
    exit 1
else
    echo "   ✓ PASS: Database admin_pubkey is different from test key (not modified)"
fi

if [ "$DB_BLOSSOM_PUBKEY" = "$EXPECTED_SERVER_PUBKEY" ]; then
    echo "   ❌ FAIL: Database blossom_pubkey matches test key (should NOT be modified)"
    exit 1
else
    echo "   ✓ PASS: Database blossom_pubkey is different from test key (not modified)"
fi

echo ""
echo "2. Checking server is running..."
if curl -s http://localhost:9001/ > /dev/null; then
    echo "   ✓ PASS: Server is responding"
else
    echo "   ❌ FAIL: Server is not responding"
    exit 1
fi

echo ""
echo "3. Verifying test keys from .test_keys file..."
echo "   Expected admin pubkey: $EXPECTED_ADMIN_PUBKEY"
echo "   Expected server pubkey: $EXPECTED_SERVER_PUBKEY"

echo ""
echo "=== All Tests Passed ==="
echo "Test mode is working correctly:"
echo "  - Test keys are loaded in memory"
echo "  - Database was NOT modified"
echo "  - Server is running with test keys"