// bun test tools/ark-offline-init.test.js — the Ark server gone: with the // server's last published info in hand the manager still opens (coins read, // exits can start); without it, init fails as before. import { test, expect, mock } from 'bun:test'; import * as proto from '../src/ark/proto.js'; mock.module('../src/ark/proto.js', () => ({ ...proto, getArkInfo: async () => { throw new Error('fetch failed'); }, handshake: async () => { throw new Error('fetch failed'); }, })); const { ArkManager } = await import('../src/ark/manager.js'); const serverPubkey = '02' + 'ab'.repeat(32); const hint = { serverPubkey, vtxoExpiryDelta: 8640, vtxoExitDelta: 144, refreshFees: { baseFeeSat: 300, ppmExpiryTable: [] }, offboardFees: { baseFeeSat: 0, fixedAdditionalVb: 0, ppmExpiryTable: [] }, lnSendFees: {}, lnReceiveFees: {} }; const mk = (infoHint) => new ArkManager({ account: null, storage: { load: () => ({ v: 1, serverPubkey, vtxos: [], actions: [], movements: [], scheduled: [] }), save() {} }, arkUrl: 'http://x', esploraUrl: 'http://y', network: 'mainnet', infoHint }); test('with cached info the manager opens offline', async () => { const m = await mk(hint).init(); expect(m.offline).toBe(true); expect(m.info.refreshFees.baseFeeSat).toBe(300); expect(Buffer.from(m.serverPub).toString('hex')).toBe(serverPubkey); }); test('without cached info the old failure stands', async () => { await expect(mk(null).init()).rejects.toThrow('fetch failed'); });