263 lines
7.3 KiB
TypeScript
263 lines
7.3 KiB
TypeScript
/**
|
||
* 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)
|