# 🎯 Docker Deployment - Expected Results

## When Running `./test-docker.sh`

You should see output similar to this:

```
🐳 H2H Docker Deployment Test
==============================

✅ Docker daemon is running

🛑 Stopping existing containers...
🏗️  Building Docker images (this may take 3-5 minutes)...
=> [backend 1/6] FROM docker.io/library/python:3.11-slim
=> [frontend 1/5] FROM docker.io/library/node:18-alpine
✅ Images built successfully

🚀 Starting services...
✅ Services started

⏳ Waiting for services to be ready...
......

📦 Container Status:
NAME                          STATUS         PORTS
h2h-prototype-backend-1       Up X seconds   0.0.0.0:8000->8000/tcp
h2h-prototype-frontend-1      Up X seconds   0.0.0.0:5173->5173/tcp

🔍 Testing backend API...
✅ Backend responding (HTTP 200)
   URL: http://localhost:8000/docs

🔍 Testing frontend...
✅ Frontend responding (HTTP 200)
   URL: http://localhost:5173

🌱 Seeding database...
✅ Database seeded with test data
   Users: alice@example.com, bob@example.com, charlie@example.com
   Password: password123

🔐 Testing authentication...
✅ Login endpoint working
✅ Authenticated endpoints working

⛓️  Checking blockchain integration...
✅ Backend blockchain services present (5 files)
✅ Frontend blockchain hooks present (3 files)

📝 Checking logs for errors...
✅ No backend errors
✅ No frontend errors

==============================
📊 Test Summary
==============================

🌐 Access Points:
   Frontend: http://localhost:5173
   Backend API Docs: http://localhost:8000/docs

👤 Test Credentials:
   Email: alice@example.com
   Password: password123

🔧 Useful Commands:
   View logs: docker compose logs -f
   Stop services: docker compose down
   Restart: docker compose restart
   Shell access: docker compose exec backend bash

🎉 Docker deployment successful!

Next steps:
1. Open http://localhost:5173 in your browser
2. Login with test credentials
3. Check for blockchain badges (⛓️) in the UI
4. Look for 'Connect Wallet' button in header
5. Verify gas estimate panels in bet creation
```

## Visual Verification Checklist

### ✅ Login Page (http://localhost:5173)

```
┌─────────────────────────────────────┐
│  H2H                                │
├─────────────────────────────────────┤
│                                     │
│  Login to H2H                       │
│                                     │
│  Email: [alice@example.com    ]    │
│  Password: [••••••••••••••••••]    │
│                                     │
│  [ Login ]                          │
│                                     │
└─────────────────────────────────────┘
```

**Expected**: Form accepts credentials and redirects to dashboard

---

### ✅ Dashboard/Marketplace

```
┌─────────────────────────────────────────────────────────┐
│  H2H  Dashboard  Marketplace  My Bets  Wallet          │
│                              [⛓️ Connect Wallet]  Alice  │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  Available Bets                                         │
│                                                         │
│  ┌──────────────────────────────────────────┐          │
│  │ Super Bowl Winner              [OPEN] ⛓️ │          │
│  │ Sports • $100 • 1.5x / 2x                │          │
│  └──────────────────────────────────────────┘          │
│                                                         │
└─────────────────────────────────────────────────────────┘
```

**Expected**:
- ⛓️ Blockchain badge on bet cards (if bet has blockchain_tx_hash)
- "Connect Wallet" button in header
- Navigation links working

---

### ✅ Create Bet Modal

Click "Create Bet" button:

```
┌─────────────────────────────────────┐
│  Create New Bet               [X]   │
├─────────────────────────────────────┤
│                                     │
│  Title: [________________]          │
│  Description: [__________]          │
│  Category: [Sports ▼]               │
│  Stake: [$100_______]               │
│                                     │
│  ┌─────────────────────────────┐   │
│  │ Estimated Gas Cost          │   │
│  │ 0.000025 ETH    ≈ $0.05    │   │
│  └─────────────────────────────┘   │
│                                     │
│  [Cancel]  [Create Bet]             │
└─────────────────────────────────────┘
```

**Expected**: Gas estimate panel appears when stake amount is entered

---

### ✅ Bet Detail Page

Click on a bet card:

```
┌─────────────────────────────────────────────────────────┐
│  H2H  Dashboard  Marketplace  My Bets  Wallet          │
│                              [⛓️ Connect Wallet]  Alice  │
├─────────────────────────────────────────────────────────┤
│  ← Back                                                 │
│                                                         │
│  Super Bowl LVIII Winner                                │
│  Sports  [OPEN] ⛓️ On-Chain  [View on Explorer ↗]      │
│                                                         │
│  Details...                                             │
│                                                         │
│  ┌───────────────────────────────────────────┐         │
│  │ Estimated Gas Cost                        │         │
│  │ 0.000045 ETH             ≈ $0.09         │         │
│  └───────────────────────────────────────────┘         │
│                                                         │
│  [Accept Bet - $100]                                    │
└─────────────────────────────────────────────────────────┘
```

**Expected**:
- Blockchain badge with Etherscan link
- Gas estimate before accept button
- Accept button triggers transaction modal

---

### ✅ Wallet Page

```
┌─────────────────────────────────────────────────────────┐
│  H2H  Dashboard  Marketplace  My Bets  Wallet          │
│                              [⛓️ 0xAb12...3456]  Alice  │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  💰 Wallet Balance                                      │
│  ┌─────────────────────────────────────────┐           │
│  │ Available Balance:         $725.00      │           │
│  │ Locked in Escrow:          $175.00      │           │
│  │ Total:                     $900.00      │           │
│  └─────────────────────────────────────────┘           │
│                                                         │
│  ─────────────────────────────────────────────          │
│                                                         │
│  On-Chain Escrow ⛓️                                     │
│  ┌─────────────────────────────────────────┐           │
│  │ Locked in Smart Contract                │           │
│  │ 0.08 ETH          ≈ $175.00            │           │
│  │                                         │           │
│  │ Wallet Balance: 1.2 ETH                 │           │
│  │ Wallet Address: 0xAb12...3456           │           │
│  └─────────────────────────────────────────┘           │
└─────────────────────────────────────────────────────────┘
```

**Expected**:
- On-Chain Escrow section (if wallet connected)
- Shows wallet address in header when connected

---

### ✅ Transaction Modal

When creating or accepting a bet:

```
┌──────────────────────────┐
│                          │
│      🔄                  │
│                          │
│  Confirming Transaction  │
│                          │
│  Please wait while your  │
│  transaction is being    │
│  processed...            │
│                          │
│  [Spinner animation]     │
│                          │
│  Do not close window     │
│                          │
└──────────────────────────┘
```

Then on success:

```
┌──────────────────────────┐
│                          │
│      ✓                   │
│                          │
│  Transaction Confirmed!  │
│                          │
│  Your bet has been       │
│  created on blockchain!  │
│                          │
│  0xabc123...def456       │
│  [View on Explorer ↗]    │
│                          │
│  [Close]                 │
│                          │
└──────────────────────────┘
```

**Expected**: Modal shows transaction progress and success state

---

## Backend API Documentation (http://localhost:8000/docs)

```
┌─────────────────────────────────────────────────────────┐
│  H2H API - Swagger UI                                   │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  Authentication                                         │
│    POST  /api/v1/auth/login                            │
│    POST  /api/v1/auth/register                         │
│                                                         │
│  Bets                                                   │
│    GET   /api/v1/bets/                                 │
│    POST  /api/v1/bets/                                 │
│    GET   /api/v1/bets/{id}                             │
│    POST  /api/v1/bets/{id}/accept                      │
│                                                         │
│  Wallet                                                 │
│    GET   /api/v1/wallet/                               │
│                                                         │
└─────────────────────────────────────────────────────────┘
```

**Expected**: Interactive API documentation with all endpoints

---

## Container Logs

### Backend Logs (docker compose logs backend)

```
backend-1  | INFO:     Uvicorn running on http://0.0.0.0:8000
backend-1  | INFO:     Started server process [1]
backend-1  | INFO:     Waiting for application startup.
backend-1  | INFO:     Application startup complete.
backend-1  | INFO:     127.0.0.1 - "GET /docs HTTP/1.1" 200 OK
```

**No errors expected** ✅

### Frontend Logs (docker compose logs frontend)

```
frontend-1 |
frontend-1 |   VITE v5.0.0  ready in 1234 ms
frontend-1 |
frontend-1 |   ➜  Local:   http://localhost:5173/
frontend-1 |   ➜  Network: http://172.18.0.3:5173/
```

**No errors expected** ✅

---

## Docker Container Status

```bash
$ docker compose ps
```

Expected output:

```
NAME                          IMAGE                     STATUS         PORTS
h2h-prototype-backend-1       h2h-prototype-backend     Up 2 minutes   0.0.0.0:8000->8000/tcp
h2h-prototype-frontend-1      h2h-prototype-frontend    Up 2 minutes   0.0.0.0:5173->5173/tcp
```

Both containers should show "Up" status ✅

---

## File Verification

```bash
$ docker compose exec backend ls -la app/blockchain/services/
```

Expected files:
```
blockchain_service.py
blockchain_indexer.py
oracle_node.py
oracle_aggregator.py
__init__.py
```

```bash
$ docker compose exec frontend ls -la src/blockchain/hooks/
```

Expected files:
```
useWeb3Wallet.ts
useBlockchainBet.ts
useGasEstimate.ts
```

---

## Common Issues & Solutions

### ❌ "Cannot connect to Docker daemon"

**Solution**: Start Docker Desktop application

```bash
open -a Docker
# Wait for Docker to start (green icon in menu bar)
./test-docker.sh
```

---

### ❌ "Port already in use"

**Solution**: Kill processes using the ports

```bash
lsof -ti:8000 | xargs kill -9
lsof -ti:5173 | xargs kill -9
docker compose down
docker compose up -d
```

---

### ❌ Frontend shows blank page

**Solution**: Check browser console for errors, rebuild frontend

```bash
# Check logs
docker compose logs frontend

# Rebuild
docker compose build --no-cache frontend
docker compose up -d frontend
```

---

### ❌ Backend import errors

**Solution**: Rebuild with fresh dependencies

```bash
docker compose build --no-cache backend
docker compose up -d backend
```

---

### ❌ Database errors

**Solution**: Reset database volume

```bash
docker compose down -v
docker compose up -d
docker compose exec backend python seed_data.py
```

---

## Success Indicators

✅ **You know it's working when:**

1. Both containers show "Up" in `docker compose ps`
2. http://localhost:5173 loads the login page
3. http://localhost:8000/docs shows Swagger UI
4. Can login with alice@example.com / password123
5. See blockchain badges (⛓️) on bet cards
6. "Connect Wallet" button appears in header
7. Gas estimate panels show in modals
8. No red errors in browser console
9. Logs show no critical errors

---

## Performance Expectations

**Build Time**: 3-5 minutes (first time)
**Startup Time**: 10-30 seconds
**Memory Usage**:
- Backend: < 200MB
- Frontend: < 500MB

**Response Times**:
- API calls: < 100ms
- Page loads: < 2s
- Login: < 500ms

---

Need help? Check `DOCKER_TESTING_GUIDE.md` for detailed troubleshooting!
