112 lines
3.9 KiB
JavaScript
112 lines
3.9 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Database Test Script
|
|
*
|
|
* Tests the PollCelo database connection and basic operations
|
|
*
|
|
* Usage:
|
|
* npx tsx scripts/test-db.ts
|
|
*/
|
|
|
|
import { getDb } from '@/lib/db';
|
|
import { createPoll } from '@/lib/db/polls';
|
|
import { Poll } from '@/types';
|
|
|
|
async function testDatabase() {
|
|
console.log('๐งช Testing PollCelo Database Connection...\n');
|
|
|
|
try {
|
|
// Test database connection
|
|
console.log('๐ก Testing database connection...');
|
|
const db = getDb(process.env.DATABASE_URL!);
|
|
console.log('โ
Database connection successful!\n');
|
|
|
|
// Test basic poll operations
|
|
console.log('๐ Testing poll operations...');
|
|
|
|
const testPoll: Omit<Poll, 'id' | 'totalPot' | 'winnersCount' | 'protocolFee'> = {
|
|
creatorFid: 1,
|
|
creatorAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
|
|
question: 'Test Poll - Will this database work?',
|
|
description: 'Testing database operations',
|
|
emoji: '๐งช',
|
|
startTime: Date.now(),
|
|
endTime: Date.now() + (24 * 60 * 60 * 1000), // 24 hours
|
|
status: 'active',
|
|
verificationType: 'manual',
|
|
verificationConfig: {},
|
|
creationFee: 5,
|
|
options: [
|
|
{ id: 'opt1', text: 'Yes', emoji: 'โ
', votes: 0, totalAmount: 0 },
|
|
{ id: 'opt2', text: 'No', emoji: 'โ', votes: 0, totalAmount: 0 },
|
|
]
|
|
};
|
|
|
|
// Create test poll
|
|
console.log('๐ Creating test poll...');
|
|
const createdPoll = await createPoll(testPoll);
|
|
console.log(`โ
Test poll created with ID: ${createdPoll.id}\n`);
|
|
|
|
// Test poll retrieval
|
|
console.log('๐ Testing poll retrieval...');
|
|
const { getPollById } = await import('@/lib/db/polls');
|
|
const retrievedPoll = await getPollById(createdPoll.id);
|
|
|
|
if (retrievedPoll) {
|
|
console.log(`โ
Poll retrieved successfully: ${retrievedPoll.question}`);
|
|
console.log(`๐ Options: ${retrievedPoll.options.length} options\n`);
|
|
} else {
|
|
throw new Error('Failed to retrieve created poll');
|
|
}
|
|
|
|
// Test oracle systems integration
|
|
console.log('๐ฎ Testing oracle systems integration...');
|
|
|
|
// Test Chainlink (if configured)
|
|
try {
|
|
const { getChainlinkPrice } = await import('@/lib/oracle/chainlink');
|
|
const btcPrice = await getChainlinkPrice('0x898E82a89c21469df34A8A9a36D1873f74Be3A1D');
|
|
console.log(`โ
Chainlink BTC Price: $${btcPrice?.price || 'N/A'}`);
|
|
} catch (error) {
|
|
console.log('โ ๏ธ Chainlink test failed (this is OK for testing)');
|
|
}
|
|
|
|
// Test ESPN
|
|
try {
|
|
const { getESPNScoreboard } = await import('@/lib/oracle/espn');
|
|
const nflGames = await getESPNScoreboard('football/nfl');
|
|
console.log(`โ
ESPN NFL Games: ${nflGames.length} games found`);
|
|
} catch (error) {
|
|
console.log('โ ๏ธ ESPN test failed (this is OK for testing)');
|
|
}
|
|
|
|
// Test DexScreener
|
|
try {
|
|
const { getDexScreenerTopPairs } = await import('@/lib/oracle/dexscreener');
|
|
const topPairs = await getDexScreenerTopPairs('ethereum');
|
|
console.log(`โ
DexScreener Ethereum Pairs: ${topPairs.length} pairs found`);
|
|
} catch (error) {
|
|
console.log('โ ๏ธ DexScreener test failed (this is OK for testing)');
|
|
}
|
|
|
|
console.log('\n๐ All database tests passed!');
|
|
console.log('\n๐ Next steps:');
|
|
console.log('1. Deploy to Vercel with environment variables');
|
|
console.log('2. Test with real FarCastor frames');
|
|
console.log('3. Create your first production poll!');
|
|
|
|
} catch (error) {
|
|
console.error('โ Database test failed:', error);
|
|
console.error('\n๐ง Troubleshooting:');
|
|
console.error('- Check DATABASE_URL in .env.local');
|
|
console.error('- Verify Neon database is running');
|
|
console.error('- Check network connectivity');
|
|
console.error('- Ensure all dependencies are installed\n');
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Run tests
|
|
testDatabase().catch(console.error);
|