20 lines
1.3 KiB
JavaScript
20 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// Captures the API responses of a running pool into tests/fixtures/ (the field contract test reads them).
|
|
// node pool/tools/capture-fixtures.mjs [http://127.0.0.1:30480] [0xaddress]
|
|
import { writeFileSync } from 'node:fs';
|
|
import { join, dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
const base = process.argv[2] || 'http://127.0.0.1:30480';
|
|
const addr = process.argv[3] || '0x' + '11'.repeat(20);
|
|
const out = join(dirname(fileURLToPath(import.meta.url)), '..', 'tests', 'fixtures');
|
|
const get = async (p) => (await fetch(base + p)).json();
|
|
const stats = await get('/api/stats');
|
|
if (!stats.pool.last_block) throw new Error('no block yet: the stats fixture needs last_block');
|
|
writeFileSync(join(out, 'stats.json'), JSON.stringify(stats, null, 1));
|
|
writeFileSync(join(out, 'miner.json'), JSON.stringify(await get('/api/miners/' + addr), null, 1));
|
|
const pay = await get('/api/payments?limit=5');
|
|
if (!pay.payments.length) throw new Error('no payment yet');
|
|
writeFileSync(join(out, 'payments.json'), JSON.stringify(pay, null, 1));
|
|
writeFileSync(join(out, 'pool-stats.json'), JSON.stringify(await get('/api/pool-stats'), null, 1));
|
|
writeFileSync(join(out, 'blocks.json'), JSON.stringify(await get('/api/blocks?limit=5'), null, 1));
|
|
console.log('fixtures written to', out);
|