v1.27.0: revisión externa, ronda 3 (coherencia entre vistas)
Mapa de UTXOs sobre analyzeTx (mismos cortes y reglas); UTXOs «no disponible» en vez de 0; CoinJoin con Math.ceil; salidas gastables para los recuentos (OP_RETURN); entrada de más frente a la salida menor (POSIBLE); denominador alcanzable (137); CIOH no agrupa CoinJoin; banda no se convierte en certeza; textos de pool, comisión e importes. test13: 34/39; test15 nuevo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L5npnUYgSPkAaHkdaeUqBr
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
// v1.27 — ronda 3 de la revisión externa: coherencia entre vistas.
|
||||
//
|
||||
// CIOH sin CoinJoin (H-08), denominador alcanzable (H-16), entrada de más
|
||||
// frente a la salida menor (H-15), OP_RETURN (H-09), comisión en el texto
|
||||
// (H-11), pool de minería (H-10) y monedas sin gastar «no disponibles» (W-10).
|
||||
//
|
||||
// Uso: node tests/test15.js
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const lines = fs.readFileSync(process.env.TXOKO_HTML || path.join(__dirname, "..", "dashboard.html"), "utf8").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");
|
||||
};
|
||||
const E = new Function(`const C = { green:"g", amber:"a", red:"r", t2:"t", blue:"b", purple:"p" };
|
||||
const ENTITY_INDEX = new Map([["bc1qPOOL", { name:"PoolX", cat:"mining", src:"oficial" }]]); const OFAC_SET = new Set();
|
||||
${cut("// ── FORMATO: lógica pura", "// ── fin formato")}
|
||||
${cut("function unionFindCluster", "function buildWalletReport")}
|
||||
${cut("function detectWallets", "function analyzeAddress")}
|
||||
${cut("function analyzeAddress", "// ── fetch con timeout")}
|
||||
return { analyzeTx, analyzeAddress, unionFindCluster };`)();
|
||||
|
||||
let pass = 0, fail = 0;
|
||||
const ok = (n, c, x) => { console.log(` ${c ? "✓" : "✗"} ${n}`); if (!c && x) console.log(" " + x); c ? pass++ : fail++; };
|
||||
const IN = (v,t,a,x={}) => ({ prevout:{ value:v, scriptpubkey_type:t, scriptpubkey_address:a }, txid:"aa", vout:0, sequence:0xffffffff, ...x });
|
||||
const OUT = (v,t,a,spk) => ({ value:v, scriptpubkey_type:t, scriptpubkey_address:a, scriptpubkey: spk || "0014"+"11".repeat(20) });
|
||||
const TX = (vin, vout, x={}) => ({ txid:"ff".repeat(32), vin, vout, weight:800, fee:2000, locktime:0, status:{ confirmed:true, block_height:955000 }, ...x });
|
||||
const WP = "v0_p2wpkh";
|
||||
const check = (r, id) => r.checks.find(c => c.id === id);
|
||||
|
||||
console.log("=== CIOH y CoinJoin ===\n");
|
||||
{
|
||||
const vin = [0,1,2,3,4].map(i => IN(1000000, WP, "A"+i, { txid:String(i).repeat(64) }));
|
||||
const vout = [0,1,2,3,4].map(i => OUT(990000, WP, "B"+i, "0014"+String(i).repeat(40)));
|
||||
const cj = TX(vin, vout, { weight:2500, fee:50000 });
|
||||
const { clusters, enCoinJoin } = E.unionFindCluster([cj], new Set(["A0","A1"]));
|
||||
ok("[H-08] dos direcciones propias en un CoinJoin: no se agrupan", clusters.length === 0, JSON.stringify(clusters));
|
||||
ok("[H-08] y se anotan aparte", enCoinJoin.length === 1);
|
||||
const normal = TX([IN(500000,WP,"A0"), IN(500000,WP,"A1")], [OUT(990000,WP,"B")]);
|
||||
ok("fuera de un CoinJoin sí se agrupan", E.unionFindCluster([normal], new Set(["A0","A1"])).clusters.length === 1);
|
||||
}
|
||||
|
||||
console.log("\n=== Nota ===\n");
|
||||
{
|
||||
// Peor caso alcanzable de vinculación + polvo: 24 direcciones + polvo de otra.
|
||||
const vin = Array.from({length:24}, (_,i) => IN(100000, WP, "N"+i, { txid:String(i%10).repeat(64), vout:i }));
|
||||
vin.push(IN(200, WP, "POLVO", { txid:"ab".repeat(32) }));
|
||||
const r = E.analyzeTx(TX(vin, [OUT(2390000, WP, "D")], { weight:9000, fee:10000 }));
|
||||
const restado = r.checks.filter(c => ["input_linkage","dust_spent"].includes(c.id) && !c.pass && !c.informational).reduce((s,c)=>s+(c.penalty||0),0);
|
||||
ok("[H-16] vinculación + polvo restan como mucho 30 (lo que cuenta el denominador)", restado <= 30, `restado=${restado}`);
|
||||
const src = lines.join("\n");
|
||||
ok("[H-16] el denominador ya no es la suma bruta de los pesos", /BONUS_CAMBIO_MAX/.test(src) && /Math\.max\(weights\.input_linkage, weights\.dust_spent\)/.test(src));
|
||||
}
|
||||
{
|
||||
const r = E.analyzeTx(TX([IN(60000,WP,"A1"),IN(50000,WP,"A2")],[OUT(10000,WP,"P","0014"+"1".repeat(40)),OUT(99000,"v1_p2tr","C","5120"+"2".repeat(64))], { weight:900, fee:1000 }));
|
||||
const c = check(r, "unnecessary_input");
|
||||
ok("[H-15] la entrada de más frente a la salida menor es POSIBLE", c.pass === false && c.certainty === "POSIBLE", `${c.pass} ${c.certainty}`);
|
||||
}
|
||||
{
|
||||
const base = TX([IN(1000000,WP,"A")],[OUT(100000,WP,"B","0014"+"1".repeat(40)),OUT(898765,WP,"C","0014"+"2".repeat(40))]);
|
||||
const r2 = E.analyzeTx({ ...base, vout:[...base.vout, { value:0, scriptpubkey_type:"op_return", scriptpubkey:"6a0b"+"00".repeat(11), scriptpubkey_address:null }] });
|
||||
ok("[H-09] con un OP_RETURN, el pago sigue contando como de dos salidas (cifra redonda)", check(r2,"round_numbers").pass === false);
|
||||
}
|
||||
|
||||
console.log("\n=== Textos ===\n");
|
||||
{
|
||||
// Comisión de 20 000 sat sin campo `fee`: el texto la calcula.
|
||||
const r = E.analyzeTx(TX([IN(1000000,WP,"A")],[OUT(500000,WP,"B","0014"+"1".repeat(40)),OUT(480000,WP,"C","0014"+"2".repeat(40))], { fee:undefined }));
|
||||
const t = r.checks.map(c => c.detail || "").join(" ");
|
||||
ok("[H-11] la comisión calculada no sale como «undefined»", !/undefined sats/.test(t));
|
||||
const p = E.analyzeTx(TX([IN(1000000,WP,"bc1qPOOL")],[OUT(990000,WP,"B")]));
|
||||
const m = check(p, "entity_mining");
|
||||
ok("[H-10] una etiqueta de pool no se presenta como recompensa de minado comprobada", m && /no lo demuestra/.test(m.detail) && !/proceden de una recompensa de minado —/.test(m.detail), m && m.detail);
|
||||
}
|
||||
|
||||
console.log("\n=== Monedas sin gastar ===\n");
|
||||
{
|
||||
const a = E.analyzeAddress({ address:"bc1qX", chain_stats:{ tx_count:1, funded_txo_count:1, spent_txo_count:0, funded_txo_sum:5000 }, utxos:null });
|
||||
const c = check(a, "utxo_count");
|
||||
ok("[W-10] /utxo no disponible: «no disponible», no «0 monedas»", c.informational && !/^0 moneda/.test(c.detail), c.label);
|
||||
}
|
||||
|
||||
console.log(`\n${pass} correctos, ${fail} fallos`);
|
||||
process.exit(fail ? 1 : 0);
|
||||
Reference in New Issue
Block a user