v1.24.5: peritaje — paginar el historial hasta la creación, coste real según el nº de transacciones, «seguir buscando» a demanda
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ node tests/test7.js
|
||||
node tests/test8.js # regresión de la revisión de heurísticas del 2026-10-13
|
||||
node tests/test9.js # lógica del rastro de procedencia
|
||||
node tests/test10.js # peritaje a demanda y datos guardados
|
||||
node tests/test11.js # Satoshi→Hal y las pizzas: P2PK, comisión 0, tarifa, peritaje sin dirección, nunca «sin gastar» sin pruebas
|
||||
node tests/test11.js # Satoshi→Hal y las pizzas: P2PK, comisión 0, tarifa, peritaje sin dirección, nunca «sin gastar» sin pruebas, historiales largos
|
||||
```
|
||||
|
||||
`test7` es de criptografía pero se extrae sola igual que las dos anteriores: no
|
||||
|
||||
+4
-3
@@ -3,7 +3,8 @@
|
||||
// Extrae del dashboard.html el analizador, el bloque «PERITAJE: lógica pura»
|
||||
// y el bloque «ALMACÉN» y los ejecuta con node. Comprueba:
|
||||
//
|
||||
// · el coste antes de comprobar («entre N y N×8 consultas»);
|
||||
// · el coste antes de comprobar («entre 2N y N×10 consultas»: total del
|
||||
// historial + hasta 8 páginas + lista de UTXO);
|
||||
// · el reparto por importes y el aviso de dilución (con importe robado);
|
||||
// · las paradas: sin gastar, depósito en exchange, CoinJoin, abanico, tope;
|
||||
// · las pistas por salida (pago o cambio, polvo, exchange, CoinJoin…);
|
||||
@@ -62,8 +63,8 @@ const k = P.claveSalida;
|
||||
console.log("=== 1. Coste antes de comprobar ===\n");
|
||||
{
|
||||
const c = P.costeComprobacion(3);
|
||||
ok("3 salidas: entre 3 y 24 consultas", c.min === 3 && c.max === 24 && /entre 3 y 24 consultas/.test(c.texto), c);
|
||||
ok("1 salida: entre 1 y 8", /entre 1 y 8/.test(P.costeComprobacion(1).texto));
|
||||
ok("3 salidas: entre 6 y 30 consultas", c.min === 6 && c.max === 30 && /entre 6 y 30 consultas/.test(c.texto), c);
|
||||
ok("1 salida: entre 2 y 10", /entre 2 y 10/.test(P.costeComprobacion(1).texto));
|
||||
ok("el máximo es el de estadoSalida (8 páginas)", P.PER_MAX_PAGINAS === 8);
|
||||
const pend = P.salidasPorComprobar(X[P2], new Map());
|
||||
ok("no se cobran consultas por el depósito en exchange ni por el polvo", pend.length === 1 && pend[0] === 1, pend);
|
||||
|
||||
+65
-4
@@ -36,6 +36,13 @@
|
||||
// tiene que incluir la tx que creó la salida, y «sin gastar» se confirma
|
||||
// con la lista de UTXO.
|
||||
//
|
||||
// Visto en el nodo real con la v1.24.4:
|
||||
// 11. al seguir la salida de ea44… (dirección 15kDhR…) se paró en «1 página
|
||||
// revisada»: una página corta se tomaba por la última. El historial va
|
||||
// de lo nuevo a lo viejo y una dirección antigua tiene muchas tx después:
|
||||
// ahora se pagina hasta la creación (o el tope), se cuenta el coste real
|
||||
// con el recuento de la dirección y se puede seguir buscando.
|
||||
//
|
||||
// Uso: node tests/test11.js
|
||||
|
||||
const fs = require("fs");
|
||||
@@ -70,7 +77,8 @@ const T = new Function(preludio + src + `
|
||||
pistasSalida: ${def("pistasSalida")}, salidasPorComprobar: ${def("salidasPorComprobar")},
|
||||
repartoSalida: ${def("repartoSalida")}, scripthashDe: ${def("scripthashDe")},
|
||||
estadoSalida: ${def("estadoSalida")}, resultadoVigilancia: ${def("resultadoVigilancia")},
|
||||
diffVigilancia: ${def("diffVigilancia")}, esSalidaDeDatos: ${def("esSalidaDeDatos")} };`)();
|
||||
diffVigilancia: ${def("diffVigilancia")}, costeHistorial: ${def("costeHistorial")},
|
||||
costeComprobacion: ${def("costeComprobacion")}, esSalidaDeDatos: ${def("esSalidaDeDatos")} };`)();
|
||||
|
||||
let pass = 0, fail = 0;
|
||||
function ok(nombre, f, extra) {
|
||||
@@ -171,7 +179,9 @@ async function okAsync(nombre, f) {
|
||||
cond ? pass++ : fail++;
|
||||
}
|
||||
// Un nodo simulado: rutas -> respuesta (o Error). Anota lo que se pide.
|
||||
const nodo = (rutas) => { const pedidas = []; const f = async u => { pedidas.push(u); const r = rutas[u]; if (r instanceof Error) throw r; if (r === undefined) throw new Error("el nodo respondió HTTP 404"); return r; }; f.pedidas = pedidas; return f; };
|
||||
// Sin ruta de estadísticas definida responde {} (sin recuento); una página
|
||||
// /txs/chain/ no definida, [] (fin del historial).
|
||||
const nodo = (rutas) => { const pedidas = []; const f = async u => { pedidas.push(u); const r = rutas[u]; if (r instanceof Error) throw r; if (r === undefined) { if (/\/txs\/chain\//.test(u)) return []; if (!/\/(txs|utxo)/.test(u)) return {}; throw new Error("el nodo respondió HTTP 404"); } return r; }; f.pedidas = pedidas; return f; };
|
||||
const RAIZ = `/api/scripthash/${SH}`;
|
||||
const SCRIPT_HAL = TX_A.vout[0].scriptpubkey;
|
||||
(async () => {
|
||||
@@ -182,7 +192,7 @@ const SCRIPT_HAL = TX_A.vout[0].scriptpubkey;
|
||||
await okAsync("10. Hal: historial [ea44…, f4184…] → la gastó ea44e972…, se sigue el salto", async () => {
|
||||
const g = nodo({ [`${RAIZ}/txs`]: [EA44, TX_A] });
|
||||
const r = await T.estadoSalida(g, undefined, TX_A.txid, 0, 8, SCRIPT_HAL);
|
||||
return r.estado === "gastada" && r.tx.txid === EA44.txid && g.pedidas[0] === `${RAIZ}/txs`;
|
||||
return r.estado === "gastada" && r.tx.txid === EA44.txid && g.pedidas[1] === `${RAIZ}/txs`;
|
||||
});
|
||||
await okAsync("10. historial vacío → sin conclusión, nunca «sin gastar»", async () => {
|
||||
try { await T.estadoSalida(nodo({ [`${RAIZ}/txs`]: [], [`${RAIZ}/utxo`]: [] }), undefined, TX_A.txid, 0, 8, SCRIPT_HAL); return false; }
|
||||
@@ -210,11 +220,62 @@ const SCRIPT_HAL = TX_A.vout[0].scriptpubkey;
|
||||
const d = T.diffVigilancia({ checks: [{ fecha: 0, estado: "sin_gastar" }] }, n);
|
||||
return n.estado === "no_localizada" && d.movida && !/sin moverse/.test(d.texto) && /9 página/.test(d.texto);
|
||||
});
|
||||
// ── Historial profundo: la dirección 15kDhR… que recibió de ea44… tiene
|
||||
// muchas tx posteriores; la creación y el gasto están en la página 10.
|
||||
const DIR = "15kDhRxxxxxxxxxxxxxxxxxxxxxxcEEV";
|
||||
const N = 300, ALTURA0 = 400000;
|
||||
const hist = Array.from({ length: N }, (_, k) => ({ txid: "h" + String(k).padStart(3, "0"), vin: [], vout: [], status: { confirmed: true, block_height: ALTURA0 - k } }));
|
||||
hist[230] = { txid: "gasto15k", vin: [{ txid: EA44.txid, vout: 0 }], vout: [], status: { confirmed: true, block_height: ALTURA0 - 230 } };
|
||||
hist[240] = { ...EA44, status: { confirmed: true, block_height: ALTURA0 - 240 } };
|
||||
const nodoHist = (lista, tam, conTotal = true) => {
|
||||
const raiz = `/api/address/${DIR}`;
|
||||
const f = async u => {
|
||||
f.n++;
|
||||
if (u === raiz) return conTotal ? { chain_stats: { tx_count: lista.length }, mempool_stats: { tx_count: 0 } } : {};
|
||||
if (u === `${raiz}/txs`) return lista.slice(0, tam);
|
||||
if (u.startsWith(`${raiz}/txs/chain/`)) { const k = lista.findIndex(t => t.txid === u.split("/").pop()); return lista.slice(k + 1, k + 1 + tam); }
|
||||
if (u === `${raiz}/utxo`) return [];
|
||||
throw new Error("el nodo respondió HTTP 404");
|
||||
};
|
||||
f.n = 0; return f;
|
||||
};
|
||||
const OPC = { alturaCreacion: ALTURA0 - 240 };
|
||||
await okAsync("11. historial de 300 tx, gasto en la página 10: con tope suficiente se encuentra", async () => {
|
||||
const r = await T.estadoSalida(nodoHist(hist, 25), DIR, EA44.txid, 0, 12, undefined, OPC);
|
||||
return r.estado === "gastada" && r.tx.txid === "gasto15k" && r.paginas === 10 && r.total === 300;
|
||||
});
|
||||
let pendiente;
|
||||
await okAsync("11. con tope de 8 páginas: «no se pudo comprobar: revisadas 8 de 12», con cursor, nunca «sin gastar»", async () => {
|
||||
const g = nodoHist(hist, 25);
|
||||
pendiente = await T.estadoSalida(g, DIR, EA44.txid, 0, 8, undefined, OPC);
|
||||
const p = T.paradaSalida({ ...EA44, vout: [{ scriptpubkey_address: DIR, scriptpubkey: "76a9", value: 1000000000 }] }, 0, { estado: pendiente.estado, paginas: pendiente.paginas, totalPaginas: pendiente.totalPaginas });
|
||||
return pendiente.estado === "incompleto" && pendiente.paginas === 8 && pendiente.totalPaginas === 12
|
||||
&& /revisadas 8 de 12 páginas/.test(pendiente.texto) && pendiente.cursor?.last === "h199"
|
||||
&& p?.motivo === "incompleto" && !/sin gastar/.test(p.titulo) && /no quiere decir que siga sin gastar/.test(p.texto)
|
||||
&& g.n === 9; // 1 recuento + 8 páginas
|
||||
});
|
||||
await okAsync("11. «seguir buscando» continúa desde el cursor (sin repetir páginas) y encuentra el gasto", async () => {
|
||||
const g = nodoHist(hist, 25);
|
||||
const r = await T.estadoSalida(g, DIR, EA44.txid, 0, 8, undefined, { ...OPC, cursor: pendiente.cursor });
|
||||
return r.estado === "gastada" && r.tx.txid === "gasto15k" && r.paginas === 10 && g.n === 2;
|
||||
});
|
||||
await okAsync("11. un servidor que pagina de 10 en 10: una página corta no es la última", async () => {
|
||||
const r = await T.estadoSalida(nodoHist(hist, 10, false), DIR, EA44.txid, 0, 30, undefined, OPC);
|
||||
return r.estado === "gastada" && r.paginas === 24;
|
||||
});
|
||||
await okAsync("11. pasada la altura de la creación sin verla → sin conclusión", async () => {
|
||||
const sinCreacion = hist.filter((_, k) => k !== 240 && k !== 230);
|
||||
try { await T.estadoSalida(nodoHist(sinCreacion, 25), DIR, EA44.txid, 0, 20, undefined, OPC); return false; }
|
||||
catch (e) { return e.codigo === "inconcluso" && /más antiguas que la salida/.test(e.message); }
|
||||
});
|
||||
ok("11. coste real con el recuento: «tiene 300 transacciones; … hasta 12 consultas»", () => T.costeHistorial(300) === "esta dirección tiene 300 transacciones; encontrar quién gastó la salida puede costar hasta 12 consultas", () => T.costeHistorial && T.costeHistorial(300));
|
||||
ok("11. el coste antes de comprobar usa el recuento conocido", () => { const c = T.costeComprobacion(2, [30, null]); return c.min === 4 && c.max === (2 + 2) + (2 + 8); }, () => T.costeComprobacion && T.costeComprobacion(2, [30, null]));
|
||||
ok("11. y avisa si el historial pasa del tope", () => /seguir buscando/.test(T.costeComprobacion(1, [300]).texto));
|
||||
await okAsync("9. pagina con /txs/chain/{último}", async () => {
|
||||
const pag1 = Array.from({ length: 25 }, (_, i) => ({ txid: "c" + i, vin: [] }));
|
||||
const g = nodo({ [`${RAIZ}/txs`]: pag1, [`${RAIZ}/txs/chain/c24`]: [EA44, TX_A] });
|
||||
const r = await T.estadoSalida(g, undefined, TX_A.txid, 0, 8, SCRIPT_HAL);
|
||||
return r.estado === "gastada" && g.pedidas[1] === `${RAIZ}/txs/chain/c24`;
|
||||
return r.estado === "gastada" && g.pedidas[2] === `${RAIZ}/txs/chain/c24`;
|
||||
});
|
||||
await okAsync("9. un 404 del Mempool da una parada honesta (no_buscable), no «sin gastar»", async () => {
|
||||
try { await T.estadoSalida(async () => { throw new Error("el nodo respondió HTTP 404"); }, undefined, TX_A.txid, 0, 8, SCRIPT_HAL); return false; }
|
||||
|
||||
Reference in New Issue
Block a user