Files
salvium-rs/test/legacy-js/debug-burn.js
T
Matt Hess 733ecd2681 Migrate all JS tests to Rust: 9-crate workspace, 703 tests, 0 JS remaining
Add root Cargo workspace with 9 crates: salvium-crypto (extended),
  salvium-types, salvium-consensus, salvium-wallet, salvium-tx,
  salvium-rpc, salvium-miner (extended), salvium-cli, salvium-multisig.

  New modules: chain_state, block_weight, alt_chain, validation,
  offline signing, stake lifecycle, wallet sync/query/encryption/utxo,
  randomx utilities, and full multisig crate with CARROT support.

  Delete 188 JS test/helper/debug files; archive integration test
  scripts to test/legacy-js/ for live testnet use. Testnet integration
  tests (transfer, stake, burn, convert, sweep) remain as #[ignore]-
  gated Rust tests runnable with --ignored against a live daemon.
2026-02-17 23:09:35 +00:00

58 lines
2.0 KiB
JavaScript

#!/usr/bin/env bun
import { DaemonRPC } from '../src/rpc/daemon.js';
import { burn } from '../src/wallet/transfer.js';
import { createWalletSync } from '../src/wallet-sync.js';
import { MemoryStorage } from '../src/wallet-store.js';
import { readFileSync } from 'fs';
const daemon = new DaemonRPC({ url: 'http://node12.whiskymine.io:29081' });
const walletAJson = JSON.parse(readFileSync('/home/mxhess/testnet-wallet/wallet-a.json', 'utf-8'));
const keysA = {
viewSecretKey: walletAJson.viewSecretKey,
spendSecretKey: walletAJson.spendSecretKey,
viewPublicKey: walletAJson.viewPublicKey,
spendPublicKey: walletAJson.spendPublicKey,
address: walletAJson.address,
};
// Load cached sync state
const CACHE_FILE = '/home/mxhess/testnet-wallet/wallet-a-sync.json';
const storage = new MemoryStorage();
try {
const cached = JSON.parse(readFileSync(CACHE_FILE, 'utf-8'));
storage.load(cached);
const cachedHeight = await storage.getSyncHeight();
console.log(`Resuming sync from block ${cachedHeight}...`);
} catch {
console.log('Starting fresh sync...');
}
const sync = createWalletSync({
daemon,
keys: keysA,
storage,
network: 'testnet'
});
await sync.start();
await Bun.write(CACHE_FILE, JSON.stringify(storage.dump()));
console.log('\n--- Burn Test: 1 SAL ---');
try {
const result = await burn({
wallet: { keys: keysA, storage, carrotKeys: walletAJson.carrotKeys },
daemon,
amount: 1_00_000_000n, // 1 SAL
options: { priority: 'default', network: 'testnet', dryRun: false }
});
console.log(`TX Hash: ${result.txHash}`);
console.log(`Fee: ${Number(result.fee) / 1e8} SAL`);
console.log(`Burned: ${Number(result.burnAmount) / 1e8} SAL`);
console.log(`Inputs: ${result.inputCount}, Outputs: ${result.outputCount}`);
console.log(`Serialized: ${result.serializedHex.length / 2} bytes`);
console.log('BROADCAST OK');
} catch (e) {
console.error(`FAILED: ${e.message}`);
if (e.stack) console.error(e.stack.split('\n').slice(1, 4).join('\n'));
}