v1.24.6: historial paginado con after_txid (Mempool sobre Fulcrum), tamaño de página real, «sin gastar» sin /utxo solo tras llegar a la creación
This commit is contained in:
+72
-17
@@ -43,6 +43,12 @@
|
||||
// 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.
|
||||
//
|
||||
// Visto en el nodo real con la v1.24.5 (Mempool sobre Fulcrum):
|
||||
// 12. /txs/chain da 404: ese Mempool pagina con /txs?after_txid=, de 10 en
|
||||
// 10, y no tiene /utxo. Se averigua el modo una vez por sesión; si no
|
||||
// hay /utxo, «sin gastar» solo vale tras llegar a la tx que creó la
|
||||
// salida. En modo Electrum los recuentos funded/spent no se usan.
|
||||
//
|
||||
// Uso: node tests/test11.js
|
||||
|
||||
const fs = require("fs");
|
||||
@@ -78,7 +84,7 @@ const T = new Function(preludio + src + `
|
||||
repartoSalida: ${def("repartoSalida")}, scripthashDe: ${def("scripthashDe")},
|
||||
estadoSalida: ${def("estadoSalida")}, resultadoVigilancia: ${def("resultadoVigilancia")},
|
||||
diffVigilancia: ${def("diffVigilancia")}, costeHistorial: ${def("costeHistorial")},
|
||||
costeComprobacion: ${def("costeComprobacion")}, esSalidaDeDatos: ${def("esSalidaDeDatos")} };`)();
|
||||
costeComprobacion: ${def("costeComprobacion")}, txoFiable: ${def("txoFiable")}, esSalidaDeDatos: ${def("esSalidaDeDatos")} };`)();
|
||||
|
||||
let pass = 0, fail = 0;
|
||||
function ok(nombre, f, extra) {
|
||||
@@ -211,9 +217,10 @@ const SCRIPT_HAL = TX_A.vout[0].scriptpubkey;
|
||||
const r = await T.estadoSalida(nodo({ [`${RAIZ}/txs`]: [TX_A], [`${RAIZ}/utxo`]: [{ txid: TX_A.txid, vout: 0, value: 1000000000 }] }), undefined, TX_A.txid, 0, 8, SCRIPT_HAL);
|
||||
return r.estado === "sin_gastar";
|
||||
});
|
||||
await okAsync("10. si la lista de UTXO falla → sin conclusión, no «sin gastar» con CERTEZA", async () => {
|
||||
try { await T.estadoSalida(nodo({ [`${RAIZ}/txs`]: [TX_A], [`${RAIZ}/utxo`]: new Error("tiempo agotado") }), undefined, TX_A.txid, 0, 8, SCRIPT_HAL); return false; }
|
||||
catch (e) { return e.codigo === "inconcluso"; }
|
||||
await okAsync("12. sin /utxo (404) pero llegando a la creación sin ver gasto → «sin gastar» por recorrido", async () => {
|
||||
const r = await T.estadoSalida(nodo({ [`${RAIZ}/txs`]: [TX_A] }), undefined, TX_A.txid, 0, 8, SCRIPT_HAL);
|
||||
const p = T.paradaSalida(TX_A, 0, { estado: r.estado, confirmadoUtxo: r.confirmadoUtxo });
|
||||
return r.estado === "sin_gastar" && r.confirmadoUtxo === false && p.certeza === "CERTEZA" && /recorriendo todo su historial/.test(p.texto);
|
||||
});
|
||||
await okAsync("10. vigilancia: «gastada, no localizada» cuenta como movida, no como «sigue sin moverse»", async () => {
|
||||
const n = T.resultadoVigilancia({ estado: "no_localizada", paginas: 9 }, 1);
|
||||
@@ -227,55 +234,103 @@ const SCRIPT_HAL = TX_A.vout[0].scriptpubkey;
|
||||
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) => {
|
||||
// Servidor estilo Esplora: 25 por página, /txs/chain/{último}, /utxo, y
|
||||
// /txs?after_txid= da 404 (o, con ignora=true, devuelve la 1.ª página).
|
||||
const nodoHist = (lista, tam, conTotal = true, ignora = false) => {
|
||||
const raiz = `/api/address/${DIR}`;
|
||||
const f = async u => {
|
||||
f.n++;
|
||||
f.n++; f.pedidas.push(u);
|
||||
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 === `${raiz}/txs` || (ignora && u.startsWith(`${raiz}/txs?after_txid=`))) 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;
|
||||
f.n = 0; f.pedidas = []; return f;
|
||||
};
|
||||
// Servidor estilo Mempool sobre Electrum/Fulcrum, como el del nodo real:
|
||||
// 10 por página, solo /txs?after_txid=, /txs/chain y /utxo dan 404, y las
|
||||
// estadísticas traen «electrum»: true con los recuentos funded/spent a 0.
|
||||
const nodoElectrum = (lista, dir) => {
|
||||
const raiz = `/api/address/${dir}`;
|
||||
const f = async u => {
|
||||
f.n++; f.pedidas.push(u);
|
||||
if (u === raiz) return { address: dir, electrum: true, chain_stats: { funded_txo_count: 0, funded_txo_sum: 1915018456, spent_txo_count: 0, spent_txo_sum: 0, tx_count: lista.length }, mempool_stats: { funded_txo_count: 0, funded_txo_sum: 0, spent_txo_count: 0, spent_txo_sum: 0, tx_count: 0 } };
|
||||
if (u === `${raiz}/txs`) return lista.slice(0, 10);
|
||||
const m = u.match(/\/txs\?after_txid=(.+)$/);
|
||||
if (u.startsWith(raiz) && m) { const k = lista.findIndex(t => t.txid === m[1]); return lista.slice(k + 1, k + 11); }
|
||||
throw new Error("el nodo respondió HTTP 404");
|
||||
};
|
||||
f.n = 0; f.pedidas = []; 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);
|
||||
const r = await T.estadoSalida(nodoHist(hist, 25), DIR, EA44.txid, 0, 12, undefined, { ...OPC, paginacion: {} });
|
||||
return r.estado === "gastada" && r.tx.txid === "gasto15k" && r.paginas === 10 && r.total === 300;
|
||||
});
|
||||
let pendiente;
|
||||
let pendiente; const memoEsplora = {};
|
||||
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);
|
||||
pendiente = await T.estadoSalida(g, DIR, EA44.txid, 0, 8, undefined, { ...OPC, paginacion: memoEsplora });
|
||||
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
|
||||
&& g.n === 10 && memoEsplora.modo === "chain"; // 1 recuento + 8 páginas + 1 prueba de after_txid (404), una vez por sesión
|
||||
});
|
||||
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 });
|
||||
const r = await T.estadoSalida(g, DIR, EA44.txid, 0, 8, undefined, { ...OPC, cursor: pendiente.cursor, paginacion: memoEsplora });
|
||||
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);
|
||||
const r = await T.estadoSalida(nodoHist(hist, 10, false), DIR, EA44.txid, 0, 30, undefined, { ...OPC, paginacion: {} });
|
||||
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; }
|
||||
try { await T.estadoSalida(nodoHist(sinCreacion, 25), DIR, EA44.txid, 0, 20, undefined, { ...OPC, paginacion: {} }); return false; }
|
||||
catch (e) { return e.codigo === "inconcluso" && /más antiguas que la salida/.test(e.message); }
|
||||
});
|
||||
await okAsync("12. Esplora que ignora after_txid (devuelve la 1.ª página): se pasa a /txs/chain", async () => {
|
||||
const memo = {}, g = nodoHist(hist, 25, true, true);
|
||||
const r = await T.estadoSalida(g, DIR, EA44.txid, 0, 12, undefined, { ...OPC, paginacion: memo });
|
||||
return r.estado === "gastada" && memo.modo === "chain" && g.pedidas.filter(u => u.includes("after_txid")).length === 1;
|
||||
});
|
||||
|
||||
// ── Mempool sobre Electrum, como el nodo real: 15kDhR… con 24 tx.
|
||||
const DIR_E = "15kDhRAcpgsugmh6mQsTcCHdvbsuYncEEV", A0 = 700000;
|
||||
const histE = Array.from({ length: 24 }, (_, k) => ({ txid: "e" + String(k).padStart(2, "0"), vin: [], vout: [], status: { confirmed: true, block_height: A0 - k } }));
|
||||
const conGasto = histE.map((t, k) => k === 14 ? { txid: "gastoE", vin: [{ txid: EA44.txid, vout: 0 }], vout: [], status: t.status } : k === 20 ? { ...EA44, status: t.status } : t);
|
||||
const OPC_E = { alturaCreacion: A0 - 20 };
|
||||
await okAsync("12. Electrum (10 por página, solo after_txid): el gasto en la página 2 se encuentra", async () => {
|
||||
const memo = {}, g = nodoElectrum(conGasto, DIR_E);
|
||||
const r = await T.estadoSalida(g, DIR_E, EA44.txid, 0, 8, undefined, { ...OPC_E, paginacion: memo });
|
||||
return r.estado === "gastada" && r.tx.txid === "gastoE" && r.paginas === 2 && r.tam === 10 && memo.modo === "after_txid"
|
||||
&& g.pedidas[2] === `/api/address/${DIR_E}/txs?after_txid=e09` && !g.pedidas.some(u => u.includes("/txs/chain"));
|
||||
});
|
||||
const sinGastoE = histE.map((t, k) => k === 20 ? { ...EA44, status: t.status } : t);
|
||||
await okAsync("12. Electrum sin gasto: con tope 2 no llega a la creación → «revisadas 2 de 3», nunca «sin gastar»", async () => {
|
||||
const r = await T.estadoSalida(nodoElectrum(sinGastoE, DIR_E), DIR_E, EA44.txid, 0, 2, undefined, { ...OPC_E, paginacion: {} });
|
||||
return r.estado === "incompleto" && r.totalPaginas === 3 && /revisadas 2 de 3/.test(r.texto);
|
||||
});
|
||||
await okAsync("12. Electrum sin gasto: al llegar a la creación (página 3) → «sin gastar» CERTEZA, aunque /utxo dé 404", async () => {
|
||||
const r = await T.estadoSalida(nodoElectrum(sinGastoE, DIR_E), DIR_E, EA44.txid, 0, 8, undefined, { ...OPC_E, paginacion: {} });
|
||||
return r.estado === "sin_gastar" && r.paginas === 3 && r.confirmadoUtxo === false;
|
||||
});
|
||||
await okAsync("12. Electrum: el coste se calcula con 10 por página (⌈24/10⌉ = 3)", async () => {
|
||||
try { await T.estadoSalida(async u => { if (u.endsWith(DIR_E)) return { electrum: true, chain_stats: { tx_count: 24, funded_txo_count: 0 } }; throw new Error("tiempo agotado"); }, DIR_E, EA44.txid, 0, 8, undefined, { paginacion: {} }); return false; }
|
||||
catch (e) { return e.total === 24 && e.tam === 10 && T.costeHistorial(e.total, e.tam) === "esta dirección tiene 24 transacciones; encontrar quién gastó la salida puede costar hasta 3 consultas"; }
|
||||
});
|
||||
ok("12. en modo Electrum los recuentos funded/spent no se usan", () => T.txoFiable({ electrum: true, chain_stats: { funded_txo_count: 5, funded_txo_sum: 1, tx_count: 24 } }) === false && T.txoFiable({ chain_stats: { funded_txo_count: 4, funded_txo_sum: 9, tx_count: 6 } }) === true);
|
||||
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[2] === `${RAIZ}/txs/chain/c24`;
|
||||
const r = await T.estadoSalida(g, undefined, TX_A.txid, 0, 8, SCRIPT_HAL, { paginacion: {} });
|
||||
return r.estado === "gastada" && g.pedidas.includes(`${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