Security Enhancements: - Add input validation middleware with express-validator - Validate token addresses (Ethereum format) - Validate risk levels (1-10 range) - Validate query parameters with sensible limits - XSS protection with request sanitization - Add authentication middleware (optional, infrastructure ready) - API key generation and validation - IP-based access control - Flexible auth combining multiple methods - Add rate limiting middleware with express-rate-limit - Bot control: 10 requests/minute (prevent spam) - General API: 100 requests/15min - Read operations: 200 requests/15min - Health checks: 300 requests/15min API Server Updates: - Integrate all middleware into api-server.ts - Add CORS origin restriction - Add request sanitization - Enhanced logging with IP and user-agent - All 8 endpoints now protected with appropriate middleware Testing Infrastructure: - Add integration tests for bot lifecycle (BotState) - Add integration tests for all API endpoints - Add comprehensive manual testing checklist (TESTING.md) - Backend testing procedures - Frontend testing procedures - Error handling verification - Performance metrics - Security checks - Production deployment verification Dependencies: - express-rate-limit@^8.2.1 - express-validator@^7.3.0
16 KiB
๐งช Production Testing Checklist
Complete guide for testing the Immortal AI Trading Bot before and after deployment.
Pre-Test Setup
Requirements
- Backend server installed and configured
- Frontend built and ready
- MetaMask browser extension installed
- opBNB Testnet configured in MetaMask
- Test BNB in wallet (from https://testnet.bnbchain.org/faucet-smart)
- .env file configured with valid API keys
Environment Verification
# Backend (.env file should have):
OPENROUTER_API_KEY=sk-or-v1-[your-key]
WALLET_PRIVATE_KEY=0x[your-testnet-key]
RPC_URL_TESTNET=https://opbnb-testnet-rpc.bnbchain.org
NETWORK=testnet
CHAIN_ID=5611
API_PORT=3001
# Frontend (.env.local should have):
NEXT_PUBLIC_API_URL=http://localhost:3001
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=[your-project-id]
NEXT_PUBLIC_USE_MAINNET=false
Phase 1: Backend Testing
1.1 Server Startup Tests
# Start backend
npm run dev # or bun run dev
Expected Output:
๐ Immortal AI Trading Bot - Production Mode
โ
Environment validation passed
๐ Current Configuration:
Network: TESTNET
Chain ID: 5611
RPC: https://opbnb-testnet-rpc.bnbchain.org...
Wallet: 0x[your-address]...
๐ฐ Trading Parameters:
Max Trade: 1.0 BNB
Stop Loss: 10%
Slippage: 2%
Interval: 300s
๐ Integrations:
OpenRouter: โ
Configured
Telegram: โ
Configured (or โช Optional)
Greenfield: โช Optional
API server listening on port 3001
๐ค Bot is ready - use the frontend to start trading
๐ Frontend: http://localhost:3000
๐ API Server: http://localhost:3001
Checklist:
- No error messages during startup
- Environment validation passes
- Configuration summary displays correctly
- All required integrations show as configured
- API server starts on correct port
1.2 Health Endpoint Test
curl http://localhost:3001/health
Expected Response:
{
"status": "ok",
"timestamp": 1234567890000,
"botRunning": false
}
Checklist:
- Returns HTTP 200 status
- JSON response is valid
statusis "ok"timestampis present and recentbotRunningreflects actual bot state
1.3 Bot Status Endpoint Test
curl http://localhost:3001/api/bot-status
Expected Response (when stopped):
{
"running": false,
"watchlist": [],
"riskLevel": 5,
"config": null
}
Checklist:
- Returns HTTP 200 status
runningis false initiallywatchlistis empty arrayriskLevelhas default valueconfigis null when not running
1.4 Start Bot Endpoint Test
curl -X POST http://localhost:3001/api/start-bot \
-H "Content-Type: application/json" \
-d '{"tokens":[],"risk":5}'
Expected Response:
{
"status": "started",
"message": "Bot is now running",
"config": {
"tokens": [],
"riskLevel": 5,
"interval": 300000,
"maxTradeAmount": 1.0,
"stopLoss": 10,
"network": "testnet"
}
}
Checklist:
- Returns HTTP 200 status
- Bot starts successfully
- Configuration is returned
- Backend logs show bot started
- Health endpoint now shows
botRunning: true
1.5 Stop Bot Endpoint Test
curl -X POST http://localhost:3001/api/stop-bot
Expected Response:
{
"status": "stopped",
"message": "Bot has been stopped"
}
Checklist:
- Returns HTTP 200 status
- Bot stops successfully
- Backend logs show bot stopped
- Health endpoint now shows
botRunning: false
1.6 Trade Logs Endpoint Test
curl http://localhost:3001/api/trade-logs?limit=10
Expected Response:
{
"total": 0,
"logs": []
}
Checklist:
- Returns HTTP 200 status
- Returns array (even if empty)
- Respects limit parameter
1.7 Trading Stats Endpoint Test
curl http://localhost:3001/api/trading-stats
Expected Response:
{
"totalTrades": 0,
"wins": 0,
"losses": 0,
"winRate": 0,
"totalPL": 0,
"avgPL": 0
}
Checklist:
- Returns HTTP 200 status
- All stat fields present
- Values are numbers
- Initial values are zero
1.8 Error Handling Tests
Test: Double Start
# Start bot
curl -X POST http://localhost:3001/api/start-bot \
-H "Content-Type: application/json" \
-d '{"tokens":[],"risk":5}'
# Try to start again (should fail)
curl -X POST http://localhost:3001/api/start-bot \
-H "Content-Type: application/json" \
-d '{"tokens":[],"risk":5}'
Expected:
- Second request returns HTTP 400
- Error message: "Bot is already running"
Test: Stop Non-Running Bot
# Ensure bot is stopped first
curl -X POST http://localhost:3001/api/stop-bot
# Try to stop again (should fail)
curl -X POST http://localhost:3001/api/stop-bot
Expected:
- Returns HTTP 400
- Error message: "Bot is not running"
Phase 2: Frontend Testing
2.1 Frontend Startup
# In a new terminal
cd apps/frontend
npm run dev # or bun run dev
Expected:
โฒ Next.js 14.x.x
- Local: http://localhost:3000
- ready in Xms
Checklist:
- Compiles without errors
- Starts on port 3000
- No build warnings for production issues
2.2 Initial Load Test
Navigate to: http://localhost:3000
Expected:
- Page loads without errors
- Header displays "Immortal AI Trading Bot"
- "Connect Wallet" button visible
- No console errors in browser DevTools
- Styles load correctly
- Gradient backgrounds render
2.3 Backend Connection Test
Check: Dashboard should detect backend
Expected:
- No "Backend Server Not Running" error
- If backend is down, error displays clearly
- If backend is up, dashboard shows normally
- Error messages are user-friendly
2.4 Wallet Connection Tests
Test 1: Connect Wallet
- Click "Connect Wallet" button
Expected:
- RainbowKit modal appears
- MetaMask option is visible
- Can select wallet
Test 2: MetaMask Connection
- Click MetaMask option
- Approve connection in MetaMask
Expected:
- MetaMask opens
- Connection request appears
- After approval, wallet address displays
- Address is truncated (0x1234...5678)
- Balance shows (if available)
Test 3: Network Switching
- Ensure on opBNB Testnet
- Try switching to different network in MetaMask
Expected:
- App detects network change
- Warning appears if wrong network
- Can switch back to opBNB Testnet
- Chain ID 5611 is correct
Test 4: Disconnect Wallet
- Click wallet address dropdown
- Click "Disconnect"
Expected:
- Wallet disconnects
- "Connect Wallet" button appears again
- Can reconnect successfully
2.5 Dashboard Tab Tests
Navigate to Dashboard tab (should be default)
Test 1: Bot Status Display
Expected:
- Bot status card shows "Stopped" (red indicator)
- Configuration inputs are enabled
- Start button is visible and enabled
Test 2: Token Watchlist
Test adding tokens:
- Enter token address:
0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82 - Click "+ Add Token"
Expected:
- Input accepts 0x format
- New input field appears
- Can add multiple tokens
- Can remove tokens (โ button)
- Minimum 1 input always present
Test auto-discovery:
- Leave all token inputs empty
- Check hint text
Expected:
- Hint says "Leave empty to auto-discover trending tokens"
- Empty array is valid (no validation error)
Test 3: Risk Level Slider
- Move slider from 1 to 10
Expected:
- Slider moves smoothly
- Value updates (1/10, 2/10, etc.)
- Label changes (Conservative โ Moderate โ Aggressive)
- Color changes (green โ yellow โ red)
Test 4: Start Bot
- Configure settings (tokens + risk)
- Click "๐ Start Trading Bot"
Expected:
- Button shows loading state ("โณ Starting...")
- API request sent to backend
- Bot status changes to "Running" (green animated indicator)
- Configuration inputs become disabled
- Stop button appears
- No errors in console
Test 5: Stop Bot
- With bot running, click "๐ Stop Bot"
Expected:
- Button shows loading state ("โณ Stopping...")
- API request sent to backend
- Bot status changes to "Stopped" (red indicator)
- Configuration inputs become enabled
- Start button appears
- No errors
2.6 Trading Stats Tab Tests
Navigate to Stats tab
Expected:
- Stats cards display
- Shows: Total Trades, Win Rate, Total P/L
- Values are 0 initially (or real data if trades exist)
- Loading skeleton shows briefly
- Auto-refreshes every 30 seconds
- No errors in console
Test Refresh:
- Wait 30+ seconds
Expected:
- Stats automatically update
- No page flicker
- Smooth update transition
2.7 Memories Tab Tests
Navigate to Memories tab
Expected:
- Memories list displays
- Shows empty state if no trades: "No trade memories yet"
- Filter buttons visible (All, Profit, Loss, Pending)
- Auto-refreshes every 60 seconds
- No errors
Test Filters (if memories exist):
- Click "Profit" filter
- Click "Loss" filter
- Click "All" filter
Expected:
- List filters correctly
- Active filter is highlighted
- Empty state shows if no matches
- Filter state persists
Test Refresh:
- Click refresh button (if available)
Expected:
- Loading state shows
- Data refreshes
- Returns to previous state
2.8 Discover Tab Tests
Navigate to Discover tab
Expected:
- Token cards display
- Shows trending tokens from DexScreener
- Each card shows: symbol, name, price, volume, liquidity
- Auto-refreshes every 120 seconds (2 min)
- No errors
Test Token Card Features:
- Find a token card
- Check links and copy button
Expected:
- DexScreener link works (opens in new tab)
- PancakeSwap link works (opens in new tab)
- Copy address button works
- Tooltip shows "Copied!" after clicking
- Address is valid (0x format)
2.9 Staking Tab Tests
Navigate to Staking tab
Expected:
- Staking UI displays
- Shows "Contracts Not Deployed" warning (if not deployed)
- Balance display shows 0.00 or real balance
- Staking tiers display (4 tiers)
- APY percentages show
- Stake button is disabled until contracts deployed
Phase 3: Error Handling Tests
3.1 Backend Down Scenario
Test:
- Stop backend server
- Refresh frontend
Expected:
- "Backend Server Not Running" error displays
- Error message is clear and helpful
- Suggests starting API server
- Shows command:
npm run dev - All API-dependent features show errors
- No silent failures
- No infinite loading states
Recovery:
- Start backend server
- Wait or refresh frontend
Expected:
- Error disappears
- Frontend auto-recovers
- Can use all features again
3.2 Invalid Configuration Tests
Test 1: Invalid Token Address
- Enter invalid address:
0xinvalid - Try to start bot
Expected:
- Validation error (either client or server)
- Error message explains format
- Bot doesn't start
- User can correct
Test 2: Out of Range Risk
- Try to set risk < 1 or > 10 (via DevTools if needed)
Expected:
- Slider prevents invalid values
- OR server validates and rejects
- Error message is clear
3.3 Network Issues
Test 1: Wallet on Wrong Network
- Connect wallet
- Switch MetaMask to different network (e.g., Ethereum mainnet)
Expected:
- App detects wrong network
- Warning/error message displays
- Bot operations are prevented
- User prompted to switch networks
Test 2: Insufficient Balance
- Use wallet with < 0.01 BNB
Expected:
- Balance shows correctly
- Warning about low balance (if implemented)
- Bot may start but can't trade (logged in backend)
Phase 4: Performance Tests
4.1 Page Load Performance
Test:
- Open DevTools โ Network tab
- Hard refresh page (Ctrl+Shift+R)
Metrics:
- Initial HTML load < 200ms
- Total page load < 2 seconds
- No failed requests
- All assets load successfully
4.2 API Response Times
Test:
- Open DevTools โ Network tab
- Start bot
- Check API calls
Metrics:
/api/start-botresponds < 500ms/api/bot-statusresponds < 100ms/api/trading-statsresponds < 200ms- No timeout errors
4.3 Real-Time Updates
Test:
- Start bot
- Watch Stats tab
- Time updates
Metrics:
- Stats refresh exactly every 30s
- No duplicate requests
- No missed intervals
- No memory leaks (check DevTools Memory)
4.4 Memory Leaks
Test:
- Open DevTools โ Performance
- Start recording
- Navigate between tabs 10 times
- Stop recording
Expected:
- Memory usage stays stable
- No unbounded growth
- Cleanup happens on tab change
- No console warnings about memory
Phase 5: Security Tests
5.1 Environment Variables
Check:
# These should NOT be in frontend bundle:
grep -r "sk-or-v1" apps/frontend/.next/
grep -r "0xYOUR_ACTUAL" apps/frontend/.next/
Expected:
- No private keys in frontend code
- No API keys in frontend code
- Only NEXT_PUBLIC_ vars in frontend
- .env not committed to git
5.2 Network Tab Inspection
Test:
- Open DevTools โ Network
- Perform actions (start bot, etc.)
- Inspect all requests
Expected:
- No sensitive data in request headers
- No private keys in payloads
- HTTPS in production (HTTP OK for localhost)
- No leaked credentials
5.3 Console Inspection
Test:
- Open DevTools โ Console
- Use all features
- Check for leaks
Expected:
- No private keys logged
- No API secrets logged
- Error messages don't leak sensitive info
- Stack traces are helpful but safe
Phase 6: Production Deployment Verification
6.1 Backend Production
After deploying to VPS:
# Test production API
curl https://api.yourdomain.com/health
Expected:
- Returns 200 OK
- HTTPS certificate valid
- Response time < 1 second
- Uptime monitoring active
6.2 Frontend Production
After deploying to Vercel:
Visit: https://yourdomain.com
Expected:
- Loads over HTTPS
- SSL certificate valid
- Connects to production API
- All features work
- No console errors
- Assets load from CDN
6.3 End-to-End Production Test
Complete flow on production:
- Visit production frontend
- Connect wallet
- Configure and start bot
- Check stats update
- Check memories sync
- Stop bot
Expected:
- All steps work smoothly
- Real data from DexScreener
- Real trades execute (testnet)
- Telegram alerts sent (if configured)
- Greenfield stores data (if configured)
- No errors in production logs
Testing Summary
Critical Tests (Must Pass)
- Backend starts without errors
- Frontend loads without errors
- Wallet connection works
- Bot can start and stop
- Real-time data updates work
- Error handling is graceful
- No sensitive data leaks
Important Tests (Should Pass)
- All API endpoints respond correctly
- Validation prevents invalid inputs
- Network switching works
- Performance meets targets
- Memory usage is stable
Nice-to-Have Tests (Can Defer)
- Greenfield integration works
- Telegram alerts work
- Staking contracts deployed
- Advanced features tested
Bug Reporting Template
If you find bugs during testing:
### Bug Report
**Title:** [Short description]
**Severity:** Critical / High / Medium / Low
**Steps to Reproduce:**
1.
2.
3.
**Expected Behavior:**
[What should happen]
**Actual Behavior:**
[What actually happened]
**Screenshots:**
[If applicable]
**Environment:**
- Browser: [Chrome/Firefox/Safari]
- OS: [Windows/Mac/Linux]
- Backend: [Running/Stopped]
- Network: [Testnet/Mainnet]
**Console Errors:**
[Paste any console errors]
**Additional Notes:**
[Any other relevant information]
Sign-Off
Pre-Production Checklist
- All critical tests pass
- All important tests pass
- Known bugs documented
- Performance acceptable
- Security verified
- Documentation complete
Tested by: _________________
Date: _________________
Sign-off: _________________
Ready for Production: YES / NO
If NO, blocking issues: 1. 2. 3.