Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YA7U5k2DMU8ZdD6MztyVYS
69 lines
4.2 KiB
JavaScript
69 lines
4.2 KiB
JavaScript
// v1.32.1 — dirección con saldo pero sin historial (Mempool sobre Fulcrum con
|
|
// una dirección de exchange): no puede salir como «sin usar».
|
|
//
|
|
// Uso: node tests/test21.js
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const lines = require("./fuente.js")().split("\n");
|
|
const cut = (desde, hasta) => {
|
|
const s = lines.findIndex(l => l.includes(desde));
|
|
const e = lines.findIndex((l, i) => i > s && l.includes(hasta));
|
|
if (s === -1 || e === -1) { console.error(`No se localiza ${desde}`); process.exit(1); }
|
|
return lines.slice(s, e).join("\n");
|
|
};
|
|
// analyzeAddress va desde su firma hasta la siguiente función del mismo nivel.
|
|
const cutFn = nombre => {
|
|
const s = lines.findIndex(l => l.startsWith(" function " + nombre));
|
|
const e = lines.findIndex((l, i) => i > s && /^ (function |const |\/\/)/.test(l));
|
|
if (s === -1 || e === -1) { console.error(`No se localiza ${nombre}`); process.exit(1); }
|
|
return lines.slice(s, e).join("\n");
|
|
};
|
|
const E = new Function(`const C = { green:"g", amber:"a", red:"r", t2:"t", blue:"b", purple:"p" };
|
|
${cut("// ── FORMATO: lógica pura", "// ── fin formato")}
|
|
${cut("const ENTITY_INDEX = new Map([", "// ── Wallet fingerprinting")}
|
|
${cut("function detectWallets", "function analyzeAddress")}
|
|
${cutFn("analyzeAddress")}
|
|
return { historialOculto, analyzeAddress, analyzeTx };`);
|
|
let F;
|
|
try { F = E(); } catch (e) { console.error("No se pudo cargar:", e.message); process.exit(1); }
|
|
let pass = 0, fail = 0;
|
|
const ok = (n, c, x) => { console.log(` ${c ? "✓" : "✗"} ${n}`); if (!c && x) console.log(" " + x); c ? pass++ : fail++; };
|
|
const st = (tx, sum, electrum = true) => ({ address: "bc1qprueba", electrum,
|
|
chain_stats: { funded_txo_count: 0, funded_txo_sum: sum, spent_txo_count: 0, spent_txo_sum: 0, tx_count: tx },
|
|
mempool_stats: { funded_txo_count: 0, funded_txo_sum: 0, spent_txo_count: 0, spent_txo_sum: 0, tx_count: 0 } });
|
|
|
|
console.log("=== Historial no disponible ===\n");
|
|
// Respuesta real de un nodo MiniBolt (Mempool 3.2 + Fulcrum) para una
|
|
// dirección de exchange: saldo de ~22 BTC y 0 transacciones.
|
|
ok("saldo y 0 transacciones en modo Electrum → historial oculto", F.historialOculto(st(0, 2213542691)) === true);
|
|
ok("dirección de verdad sin usar (0 y 0) → no", F.historialOculto(st(0, 0)) === false);
|
|
ok("con transacciones → no", F.historialOculto(st(3, 5000)) === false);
|
|
ok("sin modo Electrum (Esplora) → no", F.historialOculto(st(0, 5000, false)) === false);
|
|
const a = F.analyzeAddress({ ...st(0, 2213542691), txs: [], utxos: [] });
|
|
ok("analyzeAddress no la da por «sin usar»", !a.unused && a.sinHistorial === true, JSON.stringify({ band: a.band, summary: a.summary }));
|
|
ok("y lo explica con un aviso propio", a.checks.some(c => c.id === "historial_oculto"));
|
|
const u = F.analyzeAddress({ ...st(0, 0), txs: [], utxos: [] });
|
|
ok("una sin usar de verdad sigue saliendo «sin usar»", u.unused === true && !u.sinHistorial);
|
|
|
|
console.log("\n=== Recuento de pistas del cambio ===\n");
|
|
{
|
|
// Cambio que vuelve a la dirección que gasta + la otra salida es redonda:
|
|
// en el dibujo se ven 2 pistas, y el texto tiene que decir 2 (decía 3,
|
|
// porque la vuelta a la dirección pesa doble en la nota).
|
|
const A = "bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu", B = "bc1qnjg0jd8228aq7egyzacy8cys3knf9xvrerkf9g";
|
|
const spk = "0014" + "11".repeat(20);
|
|
const tx = { txid: "ab".repeat(32), version: 2, locktime: 0, fee: 743, weight: 561, size: 222,
|
|
status: { confirmed: true, block_height: 900000 },
|
|
vin: [{ txid: "cd".repeat(32), vout: 0, sequence: 0xfffffffd, witness: ["30", "02"],
|
|
prevout: { scriptpubkey: spk, scriptpubkey_type: "v0_p2wpkh", scriptpubkey_address: A, value: 50000000 } }],
|
|
vout: [{ scriptpubkey: spk, scriptpubkey_type: "v0_p2wpkh", scriptpubkey_address: A, value: 29999257 },
|
|
{ scriptpubkey: "0014" + "22".repeat(20), scriptpubkey_type: "v0_p2wpkh", scriptpubkey_address: B, value: 20000000 }] };
|
|
const r = F.analyzeTx(tx);
|
|
const c = r.checks.find(x => x.id === "change_detection");
|
|
ok("vuelta a la dirección + cifra redonda → «2 señales apuntan»", c && /2 señales apuntan/.test(c.detail), c && c.detail.slice(0, 90));
|
|
}
|
|
|
|
console.log(`\n${pass} correctas, ${fail} fallidas`);
|
|
process.exit(fail ? 1 : 0);
|