OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-wallet / tests / manual / test-blockscout-provider.cjs

81 lines · javascript ref:
// tests/manual/test-blockscout-provider.cjs - Test Blockscout provider (no API key)
require('bare-node-runtime/global')

const { fetchTransactions, getProviderInfo } = require('../../lib/blockchain-providers.cjs')
const { getConfig } = require('../../lib/config.cjs')

console.log('🧪 Testing Blockscout Provider (No API Key)')
console.log('')

async function test () {
  // Load config (should default to Blockscout)
  const config = getConfig()

  console.log('Config loaded:')
  console.log('  Ethereum provider:', config.blockchain.ethereum.provider)
  console.log('  API key:', config.blockchain.ethereum.apiKey || 'none')
  console.log('')

  // Get provider info
  const providerInfo = getProviderInfo('ethereum', 'blockscout')
  console.log('Blockscout info:')
  console.log('  Name:', providerInfo.name)
  console.log('  Needs API key:', providerInfo.needsApiKey)
  console.log('  Testnet URL:', providerInfo.testnetUrl)
  console.log('')

  // Test with a known Sepolia testnet address (Vitalik's address on testnet)
  const testAddress = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
  console.log('Testing with address:', testAddress)
  console.log('')

  try {
    console.log('📡 Fetching transactions from Blockscout...')
    const transactions = await fetchTransactions('ethereum', testAddress, 'testnet', config)

    if (transactions.useNativeWDK) {
      console.log('❌ Unexpected: Got useNativeWDK signal (should be HTTP API)')
      return
    }

    console.log('')
    console.log(`✅ Success! Retrieved ${transactions.length} transactions`)
    console.log('')

    if (transactions.length > 0) {
      console.log('Sample transaction:')
      const tx = transactions[0]
      console.log('  Hash:', tx.hash)
      console.log('  From:', tx.from)
      console.log('  To:', tx.to)
      console.log('  Value:', tx.value, 'wei')
      console.log('  Block:', tx.blockNumber)
      console.log('  Status:', tx.status)
      console.log('')
    } else {
      console.log('No transactions found for this address')
      console.log('(This is OK - the test address may have no transactions)')
      console.log('')
    }

    console.log('🎉 Blockscout provider works without API key!')
    console.log('')
    console.log('This means:')
    console.log('  ✅ Ethereum transaction sync will work out of the box')
    console.log('  ✅ No external account registration needed')
    console.log('  ✅ Users can start using the wallet immediately')
  } catch (err) {
    console.error('')
    console.error('❌ Error:', err.message)
    console.error('')
    console.error('This could mean:')
    console.error('  - Network connectivity issue')
    console.error('  - Blockscout API rate limit')
    console.error('  - API format changed')
    console.error('')
    console.error('Try again in a few moments')
  }
}

test()