// SPDX-FileCopyrightText: © 2026 LEDGER SAS // SPDX-License-Identifier: Apache-2.0 import type { StellarContext } from '../../config' import type { DeepPartialReturn } from '@ledgerhq/coin-module-framework/test/utils' import { Horizon } from '@stellar/stellar-sdk' import { createApi } from '..' describe('Stellar Api', () => { const api = createApi() const context: StellarContext = { config: async () => ({ name: 'Stellar', unit: { name: 'Lumen', code: 'XLM', magnitude: 7 }, explorer: { url: 'https://horizon-testnet.stellar.org/' }, status: { type: 'active' }, }), logger: () => undefined, } const ADDRESS = 'GBAUZBDXMVV7HII4JWBGFMLVKVJ6OLQAKOCGXM5E2FM4TAZB6C7JO2L7' afterEach(() => { jest.restoreAllMocks() }) describe('listOperations propagates 429 errors to caller', () => { it('throws LedgerAPI4xx on rate limit', async () => { // Horizon surfaces a 429 as a NetworkError whose message is the "Too Many Requests" // status text, which fetchOperations maps to the rate-limit-specific LedgerAPI4xx. jest.spyOn(Horizon.Server.prototype, 'operations') jest .mocked>( Horizon.Server.prototype.operations ) .mockReturnValue({ forAccount: jest.fn().mockReturnThis(), limit: jest.fn().mockReturnThis(), order: jest.fn().mockReturnThis(), cursor: jest.fn().mockReturnThis(), includeFailed: jest.fn().mockReturnThis(), join: jest.fn().mockReturnValue({ call: jest.fn().mockRejectedValue(new Error('Too Many Requests')), }), }) await expect( api.listOperations(context, ADDRESS, { minHeight: 0, order: 'asc' }) ).rejects.toMatchObject({ name: 'LedgerAPI4xx', status: 429 }) }) }) })