celo-poll/scripts/test-verification.ts
2025-12-08 16:31:30 +03:00

263 lines
7.3 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Verification Testing Script
* Tests the full verification flow for each oracle type
*
* Usage: npx tsx scripts/test-verification.ts
*/
import { verifyPoll } from '../lib/oracle'
console.log('🧪 Testing Poll Verification System...\n')
async function testChainlinkVerification() {
console.log('━'.repeat(80))
console.log('1ļøāƒ£ CHAINLINK VERIFICATION TEST')
console.log('━'.repeat(80))
try {
const options = [
{ id: 'opt1', text: 'Above $50,000' },
{ id: 'opt2', text: 'Below $50,000' },
]
const result = await verifyPoll(
'test-chainlink-1',
options,
{
verificationType: 'chainlink',
verificationConfig: {
feedAddress: '0x898E82a89c21469df34A8A9a36D1873f74Be3A1D', // BTC/USD on Celo
targetPrice: 50000,
comparisonType: 'above',
},
},
Date.now()
)
if (result.success) {
console.log('\nāœ… Verification successful!')
console.log(` Correct option: ${options[result.optionIndex!].text}`)
console.log(` Proof:`, JSON.stringify(result.proof, null, 2))
} else {
console.log(`\nāŒ Verification failed: ${result.error}`)
}
return result.success
} catch (error: any) {
console.error('\nāŒ Test failed:', error.message)
return false
}
}
async function testCurveVerification() {
console.log('\n━'.repeat(80))
console.log('2ļøāƒ£ CURVE FINANCE VERIFICATION TEST')
console.log('━'.repeat(80))
try {
const options = [
{ id: 'opt1', text: 'Above $0.99' },
{ id: 'opt2', text: 'Below $0.99' },
]
const result = await verifyPoll(
'test-curve-1',
options,
{
verificationType: 'curve',
verificationConfig: {
chain: 'celo',
tokenAddress: '0x765DE816845861e75A25fCA122bb6898B8B1282a', // cUSD
targetPrice: 0.99,
comparisonType: 'above',
},
},
Date.now()
)
if (result.success) {
console.log('\nāœ… Verification successful!')
console.log(` Correct option: ${options[result.optionIndex!].text}`)
console.log(` Proof:`, JSON.stringify(result.proof, null, 2))
} else {
console.log(`\nāŒ Verification failed: ${result.error}`)
}
return result.success
} catch (error: any) {
console.error('\nāŒ Test failed:', error.message)
return false
}
}
async function testDexScreenerVerification() {
console.log('\n━'.repeat(80))
console.log('3ļøāƒ£ DEXSCREENER VERIFICATION TEST')
console.log('━'.repeat(80))
try {
const options = [
{ id: 'opt1', text: 'Above $2000' },
{ id: 'opt2', text: 'Below $2000' },
]
const result = await verifyPoll(
'test-dexscreener-1',
options,
{
verificationType: 'dexscreener',
verificationConfig: {
chain: 'ethereum',
pairAddress: '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640', // ETH/USDC Uniswap V3
targetPrice: 2000,
comparisonType: 'above',
},
},
Date.now()
)
if (result.success) {
console.log('\nāœ… Verification successful!')
console.log(` Correct option: ${options[result.optionIndex!].text}`)
console.log(` Proof:`, JSON.stringify(result.proof, null, 2))
} else {
console.log(`\nāŒ Verification failed: ${result.error}`)
}
return result.success
} catch (error: any) {
console.error('\nāŒ Test failed:', error.message)
return false
}
}
async function testESPNVerification() {
console.log('\n━'.repeat(80))
console.log('4ļøāƒ£ ESPN SPORTS VERIFICATION TEST')
console.log('━'.repeat(80))
try {
console.log('\nāš ļø Note: Using a completed game for testing')
console.log(' This will only work if the game has finished\n')
const options = [
{ id: 'opt1', text: 'Home Team' },
{ id: 'opt2', text: 'Away Team' },
{ id: 'opt3', text: 'Draw' },
]
const result = await verifyPoll(
'test-espn-1',
options,
{
verificationType: 'espn',
verificationConfig: {
sport: 'football/nfl',
// Use a completed game ID (Super Bowl LVII)
gameId: '401437937',
},
},
Date.now()
)
if (result.success) {
console.log('\nāœ… Verification successful!')
console.log(` Correct option: ${options[result.optionIndex!].text}`)
console.log(` Proof:`, JSON.stringify(result.proof, null, 2))
} else {
console.log(`\nāŒ Verification failed: ${result.error}`)
console.log(' This is expected if no games are completed recently')
}
return result.success
} catch (error: any) {
console.error('\nāŒ Test failed:', error.message)
return false
}
}
async function testExternalAPIVerification() {
console.log('\n━'.repeat(80))
console.log('5ļøāƒ£ EXTERNAL API VERIFICATION TEST')
console.log('━'.repeat(80))
try {
const options = [
{ id: 'opt1', text: 'BTC above $50k' },
{ id: 'opt2', text: 'BTC below $50k' },
]
const result = await verifyPoll(
'test-api-1',
options,
{
verificationType: 'api',
verificationConfig: {
apiEndpoint: 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd',
jsonPath: 'bitcoin.usd',
comparisonType: 'above',
targetValue: 50000,
},
},
Date.now()
)
if (result.success) {
console.log('\nāœ… Verification successful!')
console.log(` Correct option: ${options[result.optionIndex!].text}`)
console.log(` Proof:`, JSON.stringify(result.proof, null, 2))
} else {
console.log(`\nāŒ Verification failed: ${result.error}`)
}
return result.success
} catch (error: any) {
console.error('\nāŒ Test failed:', error.message)
return false
}
}
async function runAllTests() {
console.log('šŸš€ Testing full verification flow for all oracle types...\n')
const results = {
chainlink: false,
curve: false,
dexscreener: false,
espn: false,
external: false,
}
results.chainlink = await testChainlinkVerification()
results.curve = await testCurveVerification()
results.dexscreener = await testDexScreenerVerification()
results.espn = await testESPNVerification()
results.external = await testExternalAPIVerification()
// Summary
console.log('\n━'.repeat(80))
console.log('šŸ“Š VERIFICATION TEST SUMMARY')
console.log('━'.repeat(80))
console.log(`\n1. Chainlink: ${results.chainlink ? 'āœ… PASSED' : 'āŒ FAILED'}`)
console.log(`2. Curve: ${results.curve ? 'āœ… PASSED' : 'āŒ FAILED'}`)
console.log(`3. DexScreener: ${results.dexscreener ? 'āœ… PASSED' : 'āŒ FAILED'}`)
console.log(`4. ESPN: ${results.espn ? 'āœ… PASSED' : 'āš ļø SKIPPED (no recent games)'}`)
console.log(`5. External API: ${results.external ? 'āœ… PASSED' : 'āŒ FAILED'}`)
const passed = Object.values(results).filter(r => r).length
const total = Object.keys(results).length
console.log(`\n${passed}/${total} tests passed`)
if (passed >= total - 1) { // Allow ESPN to fail
console.log('\nšŸŽ‰ Verification system is working correctly!')
} else {
console.log('\nāš ļø Some verifications failed. Check the logs above.')
}
console.log('\n' + '━'.repeat(80))
}
// Run tests
runAllTests().catch(console.error)