- OFAC como CERTEZA en flujo y simulador; exchange con su consecuencia. - Polvo propio no heredado; polvo con forma de rastreo PROBABLE. - Formato de dirección con tipoDireccion (mayúsculas, bitcoin:, tb1p, 2…, suma). - Tx en crudo reconoce PSBT/txid/dirección; firma BIP-322 reconocida. - Tarifa bajo la mínima; errores de red en llano (errorDeNodo); copiar que falla. - Comprobar transacción, plural, SIN CONFIRMAR, pie del Markdown en signet, EUR editable, fuera «clustering». - test40 nuevo; test35 y test18 ampliados. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L5npnUYgSPkAaHkdaeUqBr
71 lines
5.0 KiB
JavaScript
71 lines
5.0 KiB
JavaScript
// v1.49.3 — parche 2a, tercera parte: OFAC con su certeza en el simulador,
|
|
// polvo con forma de rastreo, polvo propio que no es «heredado» y errores de
|
|
// red dichos en llano.
|
|
//
|
|
// Uso: node tests/test40.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}» en el código de la app`); 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" };
|
|
const ENTITY_INDEX = new Map(); const OFAC_SET = new Set();
|
|
${cut("// ── FORMATO: lógica pura", "// ── fin formato")}
|
|
${cut("function detectWallets", "function analyzeAddress")}
|
|
${cut("function analyzeAddress", "// ── SIMULADOR DE GASTO")}
|
|
${cut("// ── SIMULADOR DE GASTO", "// ── fin simulador")}
|
|
${cut("function errorDeNodo", "// ── fin errorDeNodo")}
|
|
return { analyzeTx, hechosDeGasto, errorDeNodo };`)();
|
|
const T = JSON.parse(fs.readFileSync(path.join(__dirname, "fixtures", "contraste-25oct.json"), "utf8")).txs;
|
|
|
|
let pass = 0, fail = 0;
|
|
const ok = (n, c, x) => { console.log(` ${c ? "✓" : "✗"} ${n}`); if (!c && x !== undefined) console.log(" " + x); c ? pass++ : fail++; };
|
|
const ch = (a, id) => a.checks.find(c => c.id === id);
|
|
const WP = "v0_p2wpkh";
|
|
const IN = (v, a) => ({ txid: "aa".repeat(32), vout: 0, sequence: 0xfffffffd, prevout: { value: v, scriptpubkey_type: WP, scriptpubkey_address: a, scriptpubkey: "0014" + "ab".repeat(20) } });
|
|
const OUT = (v, a) => ({ value: v, scriptpubkey_type: WP, scriptpubkey_address: a, scriptpubkey: "0014" + "cd".repeat(20) });
|
|
const TX = (vin, vout) => ({ txid: "ee".repeat(32), version: 2, locktime: 0, weight: 800, fee: vin.reduce((s, v) => s + v.prevout.value, 0) - vout.reduce((s, o) => s + o.value, 0), status: { confirmed: true, block_height: 900000 }, vin, vout });
|
|
|
|
console.log("=== Polvo ===\n");
|
|
{
|
|
const d = ch(E.analyzeTx(T.dust), "dust");
|
|
ok("655c533b…: 555 sat y el resto de vuelta a quien paga → forma de rastreo, PROBABLE", d && d.certainty === "PROBABLE" && /forma de polvo para rastrear/.test(d.label), d && `${d.certainty} · ${d.label}`);
|
|
const muchas = ch(E.analyzeTx(TX([IN(100000, "bc1qA")], [OUT(600, "bc1qB"), OUT(600, "bc1qC"), OUT(600, "bc1qD"), OUT(96000, "bc1qE")])), "dust");
|
|
ok("tres salidas diminutas iguales: también PROBABLE", muchas && muchas.certainty === "PROBABLE");
|
|
const suelta = ch(E.analyzeTx(TX([IN(100000, "bc1qA")], [OUT(700, "bc1qB"), OUT(97000, "bc1qC")])), "dust");
|
|
ok("una salida pequeña y el resto a otra dirección: sigue POSIBLE", suelta && suelta.certainty === "POSIBLE");
|
|
const tx = TX([IN(100000, "bc1qMIA")], [OUT(700, "bc1qB"), OUT(97000, "bc1qMIA2")]);
|
|
const envio = E.analyzeTx(tx, { misDirecciones: new Set(["bc1qMIA", "bc1qMIA2"]) });
|
|
ok("si lo mandas tú, el polvo no es «heredado» ni suma a lo que decidieron otros", !ch(envio, "dust").heredado && envio.exposicion.puntos === 0, JSON.stringify(envio.exposicion));
|
|
const recibo = E.analyzeTx(tx, { misDirecciones: new Set(["bc1qB"]) });
|
|
ok("si lo recibes, sí", ch(recibo, "dust").heredado === true && recibo.exposicion.puntos > 0);
|
|
}
|
|
|
|
console.log("\n=== Simulador: OFAC ===\n");
|
|
{
|
|
const h = E.hechosDeGasto({ monedas: [], destino: "bc1qX", clusters: [], walletAddrs: null, labels: new Map(), entidad: { name: "Sancionada", cat: "ofac" } });
|
|
const o = h.find(x => x.id === "destino_entidad");
|
|
ok("destino en la lista OFAC: CERTEZA y «copia local de la lista», no «etiqueta de terceros»", o && o.certeza === "CERTEZA" && /copia local de la lista de sanciones OFAC/.test(o.texto) && !/etiqueta de terceros/.test(o.texto), o && o.texto);
|
|
const x = E.hechosDeGasto({ monedas: [], destino: "bc1qX", clusters: [], walletAddrs: null, labels: new Map(), entidad: { name: "ExPrueba", cat: "exchange", src: "richlist" } }).find(x => x.id === "destino_entidad");
|
|
ok("exchange: etiqueta de terceros y qué supone si pide identificación", x && x.certeza === "PROBABLE" && /etiqueta de terceros/.test(x.texto) && /pide identificación/.test(x.texto), x && x.texto);
|
|
}
|
|
|
|
console.log("\n=== Errores de red en llano ===\n");
|
|
{
|
|
const e502 = E.errorDeNodo(new Error("HTTP 502"), "txoko-metrics");
|
|
ok("502: dice qué pasa y qué comando mirar", /servicio que hay detrás no/.test(e502) && /systemctl status txoko-metrics/.test(e502), e502);
|
|
const ff = E.errorDeNodo(new TypeError("Failed to fetch"));
|
|
ok("Failed to fetch: no se llega al nodo (apagado, Tailscale, certificado)", /No se llega al nodo/.test(ff) && /Tailscale/.test(ff), ff);
|
|
const ab = new Error("x"); ab.name = "AbortError";
|
|
ok("timeout: sin respuesta a tiempo", /Sin respuesta a tiempo/.test(E.errorDeNodo(ab, "mempool")));
|
|
ok("ninguno sale en inglés", ![e502, ff].some(t => /Failed to fetch|HTTP \d/.test(t)));
|
|
}
|
|
|
|
console.log(`\n${pass} correctas, ${fail} fallidas`);
|
|
process.exit(fail ? 1 : 0);
|