#!/usr/bin/env bare
// Test transaction replication between devices
require('bare-node-runtime/global')
const {
initializeStorage,
storeTx,
getTxHistory,
closeStorage
} = require('./lib/wallet-storage.cjs')
const IdentityKey = require('keet-identity-key')
const fs = require('bare-fs')
const path = require('bare-path')
const os = require('bare-os')
const MNEMONIC_FILE = path.join(os.homedir(), '.hyper-wallet', '.mnemonic')
async function main() {
console.log('🧪 Testing Transaction Replication\n')
// Load identity
const mnemonic = fs.readFileSync(MNEMONIC_FILE, 'utf8').trim()
const identity = await IdentityKey.from({ mnemonic })
// Initialize storage
await initializeStorage(identity)
// Create test transaction
const tx = {
hash: 'test-tx-' + Date.now(),
chain: 'bitcoin',
to: 'tb1qtest123abc',
amount: '0.001',
fee: '0.0001',
timestamp: Date.now(),
status: 'pending'
}
console.log('Creating transaction:', tx.hash)
await storeTx(tx)
// Wait for Autobase to process
await new Promise(resolve => setTimeout(resolve, 2000))
// Get history
const history = await getTxHistory()
console.log('\n📊 Transaction History:')
for (const t of history) {
console.log(` ${t.hash} - ${t.chain} - ${t.amount} to ${t.to}`)
}
console.log(`\nTotal: ${history.length} transaction(s)`)
await closeStorage()
}
main().catch(err => {
console.error('Error:', err.message)
process.exit(1)
})