// SPDX-FileCopyrightText: © 2026 LEDGER SAS // SPDX-License-Identifier: Apache-2.0 import type { StellarContext } from '../../config' import BigNumber from 'bignumber.js' import { fetchAccount } from '../../network' import { getBalance } from '../getBalance' jest.mock('../../network', () => ({ fetchAccount: 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('getBalance', () => { it('returns native balance when no assets are present', async () => { jest.mocked(fetchAccount).mockResolvedValue({ blockHeight: 0, balance: BigNumber(100000000), spendableBalance: BigNumber(99999990), assets: [], }) const result = await getBalance(context, 'test-address') expect(result).toEqual([ { value: BigInt(100000000), asset: { type: 'native' }, locked: BigInt(10), }, ]) }) it('returns native and asset balances when assets are present', async () => { jest.mocked(fetchAccount).mockResolvedValue({ blockHeight: 0, balance: BigNumber(100000000), spendableBalance: BigNumber(99999990), assets: [ { asset_type: 'credit_alphanum4', asset_code: 'USDC', asset_issuer: 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN', balance: '50.1234567', limit: '', buying_liabilities: '0', selling_liabilities: '0', last_modified_ledger: 0, is_authorized: true, is_authorized_to_maintain_liabilities: true, is_clawback_enabled: false, }, ], }) const result = await getBalance(context, 'test-address') expect(result).toEqual([ { value: BigInt(100000000), asset: { type: 'native' }, locked: BigInt(10), }, { value: BigInt(501234567), asset: { type: 'credit_alphanum4', assetReference: 'USDC', assetOwner: 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN', }, }, ]) expect(fetchAccount).toHaveBeenCalledWith( { name: 'Stellar', unit: { name: 'Lumen', code: 'XLM', magnitude: 7 }, explorer: { url: 'https://horizon.example.com' }, status: { type: 'active' }, }, 'test-address' ) }) it('returns native and liquidity pool share balances', async () => { jest.mocked(fetchAccount).mockResolvedValue({ blockHeight: 0, balance: BigNumber(100000000), spendableBalance: BigNumber(99999990), assets: [ { asset_type: 'liquidity_pool_shares', liquidity_pool_id: 'a4109df8ebcfcdb2e7b5343df2fddb48e09bf1fde63ee0b7df56c9e3b22bc491', balance: '10.0000000', limit: '100.0000000', last_modified_ledger: 0, is_authorized: false, is_authorized_to_maintain_liabilities: false, is_clawback_enabled: false, }, ], }) const result = await getBalance(context, 'test-address') expect(result).toEqual([ { value: BigInt(100000000), asset: { type: 'native' }, locked: BigInt(10), }, { value: BigInt(100000000), asset: { type: 'liquidity_pool_shares', assetReference: 'a4109df8ebcfcdb2e7b5343df2fddb48e09bf1fde63ee0b7df56c9e3b22bc491', }, }, ]) }) })