minimal-xec-wallet
Version:
A minimalist eCash (XEC) wallet npm library, for use in web apps. Supports eTokens.
80 lines (68 loc) ⢠2.48 kB
JavaScript
/*
Simple UTXO consolidation test to debug wallet issues
*/
const MinimalXECWallet = require('../../index')
const fs = require('fs')
async function simpleTest () {
try {
console.log('š§ Simple UTXO Consolidation Test...\n')
// Load wallet data directly
const walletData = JSON.parse(fs.readFileSync('./wallet.json'))
console.log('ā
Wallet loaded:')
console.log(` Address: ${walletData.xecAddress}`)
console.log('')
// Initialize wallet
console.log('š§ Initializing wallet...')
const wallet = new MinimalXECWallet(walletData.mnemonic)
await wallet.walletInfoPromise
console.log('ā
Wallet info ready')
await wallet.initialize()
console.log('ā
Wallet initialized')
console.log('')
// Check if wallet is properly initialized
console.log('š Wallet State Check:')
console.log(` isInitialized: ${wallet.isInitialized}`)
console.log(` walletInfo exists: ${!!wallet.walletInfo}`)
console.log(` utxos exists: ${!!wallet.utxos}`)
console.log(` consolidateUtxos exists: ${!!wallet.consolidateUtxos}`)
console.log('')
// Try to get balance
console.log('š° Getting balance...')
try {
const balance = await wallet.getXecBalance()
console.log(` Balance: ${JSON.stringify(balance)}`)
} catch (err) {
console.log(` Balance error: ${err.message}`)
}
console.log('')
// Try to get UTXOs
console.log('š¦ Getting UTXOs...')
try {
const utxos = await wallet.getUtxos()
console.log(` UTXOs count: ${utxos.length}`)
if (utxos.length > 0) {
console.log(` First UTXO: ${JSON.stringify(utxos[0], null, 2)}`)
}
} catch (err) {
console.log(` UTXOs error: ${err.message}`)
}
console.log('')
// Try consolidation analysis
console.log('š Testing consolidation analysis...')
try {
const dryRunResult = await wallet.optimize(true)
console.log(` Dry run success: ${dryRunResult.success}`)
console.log(` Message: ${dryRunResult.message}`)
console.log(` Transactions: ${dryRunResult.transactions.length}`)
} catch (err) {
console.log(` Consolidation error: ${err.message}`)
}
} catch (err) {
console.error('\nā Test failed:', err.message)
console.log('\nš§ Debugging info:')
console.log(` Error type: ${err.constructor.name}`)
console.log(` Stack: ${err.stack}`)
}
}
// Run test
simpleTest()