16 lines
1.1 KiB
JavaScript
16 lines
1.1 KiB
JavaScript
// Record what ord answered about a rehearsal, with the lab's public chain (no keys), as a fixture the unit tests replay
|
|||
|
|
// without bitcoind or ord: tests/fixtures/regtest-rehearsal.json. Usage: node tools/regtest/record.mjs [lab.json] [from]
|
||
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
||
|
|
import { decodeLab } from '../../src/orgchain/store.js';
|
||
|
|
import { ordClient, ordEvents } from '../../src/indexer/ord.js';
|
||
|
|
|
||
|
|
const base = 'http://127.0.0.1:8088', from = Number(process.argv[3] ?? 120), ord = {};
|
||
|
|
const lab = decodeLab(readFileSync(process.argv[2] ?? 'tools/regtest/out/lab.json', 'utf8'));
|
||
|
|
const record = async (url, options) => {
|
||
|
|
const res = await fetch(url, options), body = await res.text();
|
||
|
|
ord[new URL(url).pathname] = { status: res.status, body };
|
||
|
|
return new Response(body, { status: res.status });
|
||
|
|
};
|
||
|
|
const events = await ordEvents(ordClient(base, record), { from });
|
||
|
|
writeFileSync('tests/fixtures/regtest-rehearsal.json', `${JSON.stringify({ from, ord, chain: lab.chain.snapshot() })}\n`);
|
||
|
|
console.log(`recorded ${Object.keys(ord).length} ord answers for ${events.length} events, and ${lab.chain.blocks.length} local blocks`);
|