UNPKG

@bsv/wallet-toolbox

Version:

BRC100 conforming wallet, wallet storage and wallet signer components

109 lines 4.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Chaintracks_1 = require("../Chaintracks"); const HeightRange_1 = require("../util/HeightRange"); const utilityHelpers_1 = require("../../../../utility/utilityHelpers"); describe('Chaintracks bulk ingestor failure handling', () => { test('does not loop indefinitely when a bulk ingestor keeps returning incomplete live headers', async () => { const initialRanges = { bulk: new HeightRange_1.HeightRange(0, 100), live: new HeightRange_1.HeightRange(101, 110) }; const repeatedLiveHeader = { version: 1, previousHash: '0'.repeat(64), merkleRoot: '1'.repeat(64), time: 1, bits: 1, nonce: 1, height: 111, hash: '2'.repeat(64) }; let synchronizeCalls = 0; const bulkIngestor = { setStorage: async () => { }, shutdown: async () => { }, getPresentHeight: async () => 112, fetchHeaders: async () => [], storage: () => { throw new Error('unused'); }, synchronize: async (_presentHeight, _before, priorLiveHeaders) => { synchronizeCalls += 1; return { liveHeaders: [...priorLiveHeaders, repeatedLiveHeader], liveRange: HeightRange_1.HeightRange.from([...priorLiveHeaders, repeatedLiveHeader]), done: false, log: '' }; } }; const storage = { log: () => { }, getAvailableHeightRanges: async () => initialRanges }; const liveIngestor = { setStorage: async () => { }, startListening: async () => { }, getHeaderByHash: async () => undefined, shutdown: async () => { } }; const chaintracks = new Chaintracks_1.Chaintracks({ chain: 'main', storage: storage, bulkIngestors: [bulkIngestor], liveIngestors: [liveIngestor], addLiveRecursionLimit: 36, readonly: false, logging: () => { } }); const syncPromise = chaintracks.syncBulkStorageNoLock(112, initialRanges); const timeoutPromise = (0, utilityHelpers_1.wait)(250).then(() => { throw new Error('syncBulkStorageNoLock did not return in time'); }); await expect(Promise.race([syncPromise, timeoutPromise])).resolves.toBeUndefined(); expect(synchronizeCalls).toBe(2); expect(chaintracks.liveHeaders.length).toBe(2); }); test('treats post-startup bulk sync errors as transient and returns without setting startupError', async () => { const initialRanges = { bulk: new HeightRange_1.HeightRange(0, 200), live: new HeightRange_1.HeightRange(201, 220) }; const bulkIngestor = { setStorage: async () => { }, shutdown: async () => { }, getPresentHeight: async () => 221, fetchHeaders: async () => [], storage: () => { throw new Error('unused'); }, synchronize: async () => { throw new Error('temporary upstream failure'); } }; const storage = { log: () => { }, getAvailableHeightRanges: async () => initialRanges }; const liveIngestor = { setStorage: async () => { }, startListening: async () => { }, getHeaderByHash: async () => undefined, shutdown: async () => { } }; const chaintracks = new Chaintracks_1.Chaintracks({ chain: 'main', storage: storage, bulkIngestors: [bulkIngestor], liveIngestors: [liveIngestor], addLiveRecursionLimit: 36, readonly: false, logging: () => { } }); chaintracks.available = true; await expect(chaintracks.syncBulkStorageNoLock(221, initialRanges)).resolves.toBeUndefined(); expect(chaintracks.startupError).toBeNull(); }); }); //# sourceMappingURL=bulkIngestorFailures.test.js.map