// SPDX-FileCopyrightText: © 2026 LEDGER SAS // SPDX-License-Identifier: Apache-2.0 import type { StellarContext } from '../../config' import { fetchBaseFee, broadcastTransaction, getLastBlock } from '../../network' import { NetworkCongestionLevel } from '../../types/model' import { broadcast } from '../broadcast' import { estimateFees } from '../estimateFees' import { lastBlock } from '../lastBlock' jest.mock('../../network', () => ({ fetchBaseFee: jest.fn(), broadcastTransaction: jest.fn(), getLastBlock: jest.fn(), })) const context: StellarContext = { config: async () => ({ name: 'Stellar', unit: { name: 'Lumen', code: 'XLM', magnitude: 7 }, explorer: { url: 'https://horizon.example.com' }, status: { type: 'active' }, }), logger: jest.fn(), } describe('network wrapper helpers', () => { beforeEach(() => { jest.clearAllMocks() }) it('broadcast delegates to broadcastTransaction', async () => { jest.mocked(broadcastTransaction).mockResolvedValue('tx-hash') await expect(broadcast(context, 'signed-xdr')).resolves.toBe('tx-hash') expect(broadcastTransaction).toHaveBeenCalledWith(context, 'signed-xdr') }) it('estimateFees converts recommended fee to bigint', async () => { jest.mocked(fetchBaseFee).mockResolvedValue({ recommendedFee: 100, baseFee: 100, networkCongestionLevel: NetworkCongestionLevel.LOW, }) await expect(estimateFees(context)).resolves.toBe(100n) expect(fetchBaseFee).toHaveBeenCalledTimes(1) }) it('lastBlock delegates to getLastBlock', async () => { const block = { height: 123, hash: 'block-hash', time: new Date('2026-01-01T00:00:00.000Z'), } jest.mocked(getLastBlock).mockResolvedValue(block) await expect(lastBlock(context)).resolves.toEqual(block) expect(getLastBlock).toHaveBeenCalledTimes(1) }) })