// SPDX-FileCopyrightText: © 2026 LEDGER SAS // SPDX-License-Identifier: Apache-2.0 import type { StellarCoinConfig, StellarContext } from '../../config' import { fetchAllOperations, registerHorizonInterceptors } from '../horizon' const mainnetConfig: StellarCoinConfig = { status: { type: 'active' }, name: 'Stellar', unit: { name: 'Lumen', code: 'XLM', magnitude: 7 }, explorer: { url: 'https://stellar.coin.ledger.com', fetchLimit: 10 }, } const context: StellarContext = { config: async () => mainnetConfig, logger: jest.fn(), } const ADDRESS = 'GA2S6CABCO4OBFX7PQSK6WQ3ZSX3WYF52TVBXQFLJAEPKKRFUXVFJUSD' describe('fetchAllOperations', () => { beforeAll(() => { registerHorizonInterceptors(context) }) it.each(['asc', 'desc'] as const)( 'should order operation by %s when fetching operations', async (order: 'asc' | 'desc') => { const operations = await fetchAllOperations(mainnetConfig, ADDRESS, ADDRESS, order) expect(operations.length).toBeGreaterThan(0) operations.forEach((operation) => { expect(operation).toMatchObject({ id: expect.stringContaining(ADDRESS), }) }) for (let i = 0; i < operations.length - 1; i++) { if (order === 'asc') { expect(operations[i].tx.date.getTime()).toBeLessThanOrEqual( operations[i + 1].tx.date.getTime() ) } else { expect(operations[i].tx.date.getTime()).toBeGreaterThanOrEqual( operations[i + 1].tx.date.getTime() ) } } }, 20 * 1_000 ) it( 'should limit result by the parameter passed to fetch', async () => { const limit = 15 const operations = await fetchAllOperations(mainnetConfig, ADDRESS, ADDRESS, 'asc', '', limit) // Temporary fix, limit may not return the exact limit, will be cleaned with fetchAllOperations expect(operations.length).toBeGreaterThanOrEqual(limit - 5) expect(operations.length).toBeLessThanOrEqual(limit + 5) operations.forEach((operation) => { expect(operation).toMatchObject({ id: expect.stringContaining(ADDRESS), }) }) }, 10 * 1_000 ) })