@ledgerhq/coin-stellar 6.26.0 → 6.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.oxlintrc.json +7 -0
- package/CHANGELOG.md +6 -0
- package/LICENSE +194 -0
- package/knip.json +12 -0
- package/lib/api/index.d.ts +5 -5
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +12 -10
- package/lib/api/index.js.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +2 -0
- package/lib/config.js.map +1 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +3 -1
- package/lib/constants.js.map +1 -1
- package/lib/logic/broadcast.d.ts.map +1 -1
- package/lib/logic/broadcast.js +2 -0
- package/lib/logic/broadcast.js.map +1 -1
- package/lib/logic/combine.d.ts +1 -1
- package/lib/logic/combine.d.ts.map +1 -1
- package/lib/logic/combine.js +2 -0
- package/lib/logic/combine.js.map +1 -1
- package/lib/logic/common.d.ts +1 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js +4 -2
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +10 -8
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +2 -0
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +4 -2
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +39 -34
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getBlockInfo.d.ts +1 -1
- package/lib/logic/getBlockInfo.d.ts.map +1 -1
- package/lib/logic/getBlockInfo.js +2 -0
- package/lib/logic/getBlockInfo.js.map +1 -1
- package/lib/logic/index.d.ts +12 -12
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +2 -0
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/lastBlock.d.ts +1 -1
- package/lib/logic/lastBlock.d.ts.map +1 -1
- package/lib/logic/lastBlock.js +2 -0
- package/lib/logic/lastBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +6 -4
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/sdkWrapper.d.ts +1 -1
- package/lib/logic/sdkWrapper.d.ts.map +1 -1
- package/lib/logic/sdkWrapper.js +2 -0
- package/lib/logic/sdkWrapper.js.map +1 -1
- package/lib/logic/utils.d.ts.map +1 -1
- package/lib/logic/utils.js +4 -2
- package/lib/logic/utils.js.map +1 -1
- package/lib/logic/validateAddress.d.ts +1 -1
- package/lib/logic/validateAddress.d.ts.map +1 -1
- package/lib/logic/validateAddress.js +2 -0
- package/lib/logic/validateAddress.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +2 -2
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js +21 -19
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic/validateMemo.d.ts +1 -1
- package/lib/logic/validateMemo.d.ts.map +1 -1
- package/lib/logic/validateMemo.js +7 -5
- package/lib/logic/validateMemo.js.map +1 -1
- package/lib/network/horizon.d.ts +6 -7
- package/lib/network/horizon.d.ts.map +1 -1
- package/lib/network/horizon.js +71 -68
- package/lib/network/horizon.js.map +1 -1
- package/lib/network/horizonLedgerErrors.d.ts.map +1 -1
- package/lib/network/horizonLedgerErrors.js +5 -3
- package/lib/network/horizonLedgerErrors.js.map +1 -1
- package/lib/network/index.d.ts +1 -1
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js +2 -0
- package/lib/network/index.js.map +1 -1
- package/lib/network/serialization.d.ts +6 -4
- package/lib/network/serialization.d.ts.map +1 -1
- package/lib/network/serialization.js +95 -91
- package/lib/network/serialization.js.map +1 -1
- package/lib/polyfill.d.ts.map +1 -1
- package/lib/polyfill.js +6 -4
- package/lib/polyfill.js.map +1 -1
- package/lib/supportedFeatures.d.ts +1 -1
- package/lib/supportedFeatures.d.ts.map +1 -1
- package/lib/supportedFeatures.js +3 -1
- package/lib/supportedFeatures.js.map +1 -1
- package/lib/types/errors.d.ts.map +1 -1
- package/lib/types/errors.js +14 -12
- package/lib/types/errors.js.map +1 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +2 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/model.d.ts +6 -6
- package/lib/types/model.d.ts.map +1 -1
- package/lib/types/model.js +7 -5
- package/lib/types/model.js.map +1 -1
- package/lib-es/api/index.d.ts +5 -5
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +20 -18
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/config.d.ts +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +3 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +3 -1
- package/lib-es/constants.js.map +1 -1
- package/lib-es/logic/broadcast.d.ts.map +1 -1
- package/lib-es/logic/broadcast.js +3 -1
- package/lib-es/logic/broadcast.js.map +1 -1
- package/lib-es/logic/combine.d.ts +1 -1
- package/lib-es/logic/combine.d.ts.map +1 -1
- package/lib-es/logic/combine.js +3 -1
- package/lib-es/logic/combine.js.map +1 -1
- package/lib-es/logic/common.d.ts +1 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +5 -3
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +15 -13
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +3 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +5 -3
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +42 -37
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getBlockInfo.d.ts +1 -1
- package/lib-es/logic/getBlockInfo.d.ts.map +1 -1
- package/lib-es/logic/getBlockInfo.js +3 -1
- package/lib-es/logic/getBlockInfo.js.map +1 -1
- package/lib-es/logic/index.d.ts +12 -12
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +14 -12
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/lastBlock.d.ts +1 -1
- package/lib-es/logic/lastBlock.d.ts.map +1 -1
- package/lib-es/logic/lastBlock.js +3 -1
- package/lib-es/logic/lastBlock.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +7 -5
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/sdkWrapper.d.ts +1 -1
- package/lib-es/logic/sdkWrapper.d.ts.map +1 -1
- package/lib-es/logic/sdkWrapper.js +4 -2
- package/lib-es/logic/sdkWrapper.js.map +1 -1
- package/lib-es/logic/utils.d.ts.map +1 -1
- package/lib-es/logic/utils.js +6 -4
- package/lib-es/logic/utils.js.map +1 -1
- package/lib-es/logic/validateAddress.d.ts +1 -1
- package/lib-es/logic/validateAddress.d.ts.map +1 -1
- package/lib-es/logic/validateAddress.js +3 -1
- package/lib-es/logic/validateAddress.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +2 -2
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js +30 -28
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic/validateMemo.d.ts +1 -1
- package/lib-es/logic/validateMemo.d.ts.map +1 -1
- package/lib-es/logic/validateMemo.js +8 -6
- package/lib-es/logic/validateMemo.js.map +1 -1
- package/lib-es/network/horizon.d.ts +6 -7
- package/lib-es/network/horizon.d.ts.map +1 -1
- package/lib-es/network/horizon.js +80 -77
- package/lib-es/network/horizon.js.map +1 -1
- package/lib-es/network/horizonLedgerErrors.d.ts.map +1 -1
- package/lib-es/network/horizonLedgerErrors.js +7 -5
- package/lib-es/network/horizonLedgerErrors.js.map +1 -1
- package/lib-es/network/index.d.ts +1 -1
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js +3 -1
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/network/serialization.d.ts +6 -4
- package/lib-es/network/serialization.d.ts.map +1 -1
- package/lib-es/network/serialization.js +97 -95
- package/lib-es/network/serialization.js.map +1 -1
- package/lib-es/polyfill.d.ts.map +1 -1
- package/lib-es/polyfill.js +7 -5
- package/lib-es/polyfill.js.map +1 -1
- package/lib-es/supportedFeatures.d.ts +1 -1
- package/lib-es/supportedFeatures.d.ts.map +1 -1
- package/lib-es/supportedFeatures.js +3 -1
- package/lib-es/supportedFeatures.js.map +1 -1
- package/lib-es/types/errors.d.ts.map +1 -1
- package/lib-es/types/errors.js +15 -13
- package/lib-es/types/errors.js.map +1 -1
- package/lib-es/types/index.d.ts +2 -2
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js +4 -2
- package/lib-es/types/index.js.map +1 -1
- package/lib-es/types/model.d.ts +6 -6
- package/lib-es/types/model.d.ts.map +1 -1
- package/lib-es/types/model.js +7 -5
- package/lib-es/types/model.js.map +1 -1
- package/package.json +13 -16
- package/src/api/index.integ.test.ts +165 -162
- package/src/api/index.test.ts +106 -103
- package/src/api/index.ts +49 -46
- package/src/api/index_error.test.ts +48 -25
- package/src/config.ts +15 -12
- package/src/constants.ts +4 -1
- package/src/globals.d.ts +7 -5
- package/src/logic/broadcast.integ.test.ts +22 -19
- package/src/logic/broadcast.ts +5 -2
- package/src/logic/combine.test.ts +18 -15
- package/src/logic/combine.ts +8 -5
- package/src/logic/common.ts +9 -6
- package/src/logic/craftTransaction.test.ts +76 -75
- package/src/logic/craftTransaction.ts +46 -43
- package/src/logic/estimateFees.ts +6 -3
- package/src/logic/getBalance.test.ts +31 -28
- package/src/logic/getBalance.ts +13 -10
- package/src/logic/getBlock.integ.test.ts +40 -39
- package/src/logic/getBlock.test.ts +462 -415
- package/src/logic/getBlock.ts +142 -127
- package/src/logic/getBlockInfo.test.ts +72 -69
- package/src/logic/getBlockInfo.ts +15 -12
- package/src/logic/index.ts +15 -12
- package/src/logic/lastBlock.ts +6 -3
- package/src/logic/listOperations.ts +14 -11
- package/src/logic/listOperations.unit.test.ts +212 -209
- package/src/logic/networkWrappers.test.ts +32 -29
- package/src/logic/sdkWrapper.ts +19 -16
- package/src/logic/utils.ts +13 -10
- package/src/logic/validateAddress.test.ts +21 -18
- package/src/logic/validateAddress.ts +7 -4
- package/src/logic/validateIntent.test.ts +62 -59
- package/src/logic/validateIntent.ts +87 -84
- package/src/logic/validateMemo.test.ts +50 -47
- package/src/logic/validateMemo.ts +16 -13
- package/src/network/broadcastTransaction.test.ts +60 -60
- package/src/network/fetchLedgerOperations.unit.test.ts +155 -0
- package/src/network/horizon.integ.test.ts +45 -42
- package/src/network/horizon.test.ts +17 -14
- package/src/network/horizon.ts +279 -281
- package/src/network/horizon.unit.test.ts +238 -237
- package/src/network/horizonLedgerErrors.test.ts +81 -78
- package/src/network/horizonLedgerErrors.ts +22 -19
- package/src/network/index.ts +4 -1
- package/src/network/registerHorizonInterceptors.test.ts +163 -160
- package/src/network/serialization.ts +232 -227
- package/src/network/serialization.unit.test.ts +801 -798
- package/src/polyfill.ts +18 -15
- package/src/supportedFeatures.ts +6 -3
- package/src/types/errors.ts +33 -32
- package/src/types/index.ts +5 -2
- package/src/types/model.ts +55 -52
- package/tsconfig.json +1 -1
- package/.unimportedrc.json +0 -17
- package/LICENSE.txt +0 -21
- package/src/network/fetchLedgerOperations.nock.unit.test.ts +0 -156
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { CoinConfig } from '@ledgerhq/coin-module-framework/config'
|
|
5
|
+
import { Horizon, NotFoundError } from '@stellar/stellar-sdk'
|
|
6
|
+
import coinConfig, { type StellarCoinConfig } from '../config'
|
|
7
|
+
import { fetchAllLedgerOperations, fetchLedgerRecord } from './horizon'
|
|
8
|
+
|
|
9
|
+
const HORIZON = 'https://horizon-testnet.stellar.org'
|
|
10
|
+
|
|
11
|
+
let originalGetCoinConfig: CoinConfig<StellarCoinConfig>
|
|
12
|
+
|
|
13
|
+
/** Minimal Horizon payment op shape (embedded.records). */
|
|
14
|
+
const MINIMAL_HORIZON_PAYMENT_OP = {
|
|
15
|
+
_links: {
|
|
16
|
+
self: { href: '' },
|
|
17
|
+
transaction: { href: '' },
|
|
18
|
+
effects: { href: '' },
|
|
19
|
+
succeeds: { href: '' },
|
|
20
|
+
precedes: { href: '' },
|
|
21
|
+
},
|
|
22
|
+
id: '1',
|
|
23
|
+
paging_token: '1',
|
|
24
|
+
transaction_successful: true,
|
|
25
|
+
source_account: 'GB7FW6GRFEH63Q3BVRT65VMB26OKHQRG74QRFUMTL6D553UKDZCDM7U',
|
|
26
|
+
type: 'payment',
|
|
27
|
+
type_i: 1,
|
|
28
|
+
created_at: '2015-07-20T20:27:50Z',
|
|
29
|
+
transaction_hash: 'txh',
|
|
30
|
+
asset_type: 'native',
|
|
31
|
+
from: 'GB7FW6GRFEH63Q3BVRT65VMB26OKHQRG74QRFUMTL6D553UKDZCDM7U',
|
|
32
|
+
to: 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN',
|
|
33
|
+
amount: '1.0000000',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Minimal chainable stub of a Horizon call builder: every builder method returns
|
|
38
|
+
* the builder itself, and `call()` resolves (or rejects) with the configured value.
|
|
39
|
+
* Lets us drive `getServer().ledgers()...call()` / `.operations()...call()` without HTTP.
|
|
40
|
+
*/
|
|
41
|
+
function callBuilder(call: () => Promise<unknown>): unknown {
|
|
42
|
+
const builder: unknown = new Proxy(
|
|
43
|
+
{},
|
|
44
|
+
{
|
|
45
|
+
get(_target, prop) {
|
|
46
|
+
if (prop === 'call') return call
|
|
47
|
+
return () => builder
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
return builder
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function setExplorer(fetchLimit = 100): void {
|
|
55
|
+
coinConfig.setCoinConfig(
|
|
56
|
+
(): StellarCoinConfig =>
|
|
57
|
+
({
|
|
58
|
+
status: { type: 'active' },
|
|
59
|
+
explorer: { url: `${HORIZON}/`, fetchLimit },
|
|
60
|
+
}) as StellarCoinConfig
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function mockLedgers(call: () => Promise<unknown>): void {
|
|
65
|
+
jest.spyOn(Horizon.Server.prototype, 'ledgers').mockReturnValue(callBuilder(call) as never)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function mockOperations(call: () => Promise<unknown>): void {
|
|
69
|
+
jest.spyOn(Horizon.Server.prototype, 'operations').mockReturnValue(callBuilder(call) as never)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
describe('fetchLedgerRecord / fetchAllLedgerOperations', () => {
|
|
73
|
+
beforeAll(() => {
|
|
74
|
+
originalGetCoinConfig = coinConfig.getCoinConfig
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
afterAll(() => {
|
|
78
|
+
if (originalGetCoinConfig) {
|
|
79
|
+
coinConfig.setCoinConfig(originalGetCoinConfig)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
beforeEach(() => {
|
|
84
|
+
setExplorer(100)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
afterEach(() => {
|
|
88
|
+
jest.restoreAllMocks()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('fetchLedgerRecord maps 404 to not found error', async () => {
|
|
92
|
+
mockLedgers(() => Promise.reject(new NotFoundError('Not Found', {} as never)))
|
|
93
|
+
|
|
94
|
+
await expect(fetchLedgerRecord(424242)).rejects.toThrow('Stellar ledger 424242 not found')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('fetchAllLedgerOperations maps 404 to not found error', async () => {
|
|
98
|
+
mockOperations(() => Promise.reject(new NotFoundError('Not Found', {} as never)))
|
|
99
|
+
|
|
100
|
+
await expect(fetchAllLedgerOperations(424243)).rejects.toThrow(
|
|
101
|
+
'Stellar ledger 424243 not found'
|
|
102
|
+
)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('fetchLedgerRecord returns ledger on 200', async () => {
|
|
106
|
+
const ledgerBody = {
|
|
107
|
+
_links: { self: { href: '' }, transactions: { href: '' }, operations: { href: '' } },
|
|
108
|
+
id: 'abc',
|
|
109
|
+
paging_token: 'abc',
|
|
110
|
+
hash: '0000000000000000000000000000000000000000000000000000000000000000',
|
|
111
|
+
prev_hash: '',
|
|
112
|
+
sequence: 3,
|
|
113
|
+
successful_transaction_count: 0,
|
|
114
|
+
failed_transaction_count: 0,
|
|
115
|
+
operation_count: 0,
|
|
116
|
+
tx_set_operation_count: 0,
|
|
117
|
+
closed_at: '2015-07-20T20:27:50Z',
|
|
118
|
+
total_coins: '100000000000.0000000',
|
|
119
|
+
fee_pool: '0.0000000',
|
|
120
|
+
base_fee_in_stroops: 100,
|
|
121
|
+
base_reserve_in_stroops: 100000000,
|
|
122
|
+
max_tx_set_size: 50,
|
|
123
|
+
protocol_version: 1,
|
|
124
|
+
header_xdr: '',
|
|
125
|
+
}
|
|
126
|
+
mockLedgers(() => Promise.resolve(ledgerBody))
|
|
127
|
+
|
|
128
|
+
const rec = await fetchLedgerRecord(3)
|
|
129
|
+
expect(rec.sequence).toBe(3)
|
|
130
|
+
expect(rec.hash).toBe(ledgerBody.hash)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('fetchAllLedgerOperations returns embedded records on 200', async () => {
|
|
134
|
+
const page = {
|
|
135
|
+
records: [MINIMAL_HORIZON_PAYMENT_OP],
|
|
136
|
+
next: () => Promise.resolve({ records: [] }),
|
|
137
|
+
}
|
|
138
|
+
mockOperations(() => Promise.resolve(page))
|
|
139
|
+
|
|
140
|
+
const records = await fetchAllLedgerOperations(10)
|
|
141
|
+
expect(records).toHaveLength(1)
|
|
142
|
+
expect(records[0].type).toBe('payment')
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('fetchAllLedgerOperations paginates when page is full then stops on empty page', async () => {
|
|
146
|
+
setExplorer(1)
|
|
147
|
+
|
|
148
|
+
const page2 = { records: [], next: () => Promise.resolve({ records: [] }) }
|
|
149
|
+
const page1 = { records: [MINIMAL_HORIZON_PAYMENT_OP], next: () => Promise.resolve(page2) }
|
|
150
|
+
mockOperations(() => Promise.resolve(page1))
|
|
151
|
+
|
|
152
|
+
const records = await fetchAllLedgerOperations(11)
|
|
153
|
+
expect(records.length).toBe(1)
|
|
154
|
+
})
|
|
155
|
+
})
|
|
@@ -1,67 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import coinConfig, { StellarCoinConfig } from '../config'
|
|
5
|
+
import { fetchAllOperations, registerHorizonInterceptors } from './horizon'
|
|
6
|
+
|
|
7
|
+
describe('fetchAllOperations', () => {
|
|
5
8
|
beforeAll(() => {
|
|
6
9
|
coinConfig.setCoinConfig(
|
|
7
10
|
(): StellarCoinConfig => ({
|
|
8
|
-
status: { type:
|
|
11
|
+
status: { type: 'active' },
|
|
9
12
|
explorer: {
|
|
10
|
-
url:
|
|
13
|
+
url: 'https://stellar.coin.ledger.com',
|
|
11
14
|
fetchLimit: 10,
|
|
12
15
|
},
|
|
13
|
-
})
|
|
14
|
-
)
|
|
15
|
-
registerHorizonInterceptors()
|
|
16
|
-
})
|
|
16
|
+
})
|
|
17
|
+
)
|
|
18
|
+
registerHorizonInterceptors()
|
|
19
|
+
})
|
|
17
20
|
|
|
18
21
|
it(
|
|
19
|
-
|
|
22
|
+
'fetch operations with limitations, set order to desc',
|
|
20
23
|
async () => {
|
|
21
|
-
const addr =
|
|
22
|
-
const limit = 30
|
|
23
|
-
const ops = await fetchAllOperations(addr, addr,
|
|
24
|
-
expect(ops.length).toEqual(limit)
|
|
24
|
+
const addr = 'GCOCZ3ODGW3YH6PPGMLGT3MORS5YBTVJCSL46TC2NMU2KCXGL52XLEZB'
|
|
25
|
+
const limit = 30
|
|
26
|
+
const ops = await fetchAllOperations(addr, addr, 'desc', '241343231793946722', limit)
|
|
27
|
+
expect(ops.length).toEqual(limit)
|
|
25
28
|
expect(ops[0].id).toEqual(
|
|
26
|
-
`${addr}-00b0081a2c5c5e62cf5f5813691d33ab71a8b46b115d645bcd9df4e9c7941778-IN
|
|
27
|
-
)
|
|
29
|
+
`${addr}-00b0081a2c5c5e62cf5f5813691d33ab71a8b46b115d645bcd9df4e9c7941778-IN`
|
|
30
|
+
)
|
|
28
31
|
expect(ops[29].id).toEqual(
|
|
29
|
-
`${addr}-00b0081a2c5c5e62cf5f5813691d33ab71a8b46b115d645bcd9df4e9c7941778-IN
|
|
30
|
-
)
|
|
32
|
+
`${addr}-00b0081a2c5c5e62cf5f5813691d33ab71a8b46b115d645bcd9df4e9c7941778-IN`
|
|
33
|
+
)
|
|
31
34
|
},
|
|
32
|
-
10 * 1_000
|
|
33
|
-
)
|
|
35
|
+
10 * 1_000
|
|
36
|
+
)
|
|
34
37
|
|
|
35
38
|
it(
|
|
36
|
-
|
|
39
|
+
'fetch operations without limitations, set order to desc',
|
|
37
40
|
async () => {
|
|
38
|
-
const addr =
|
|
39
|
-
const ops = await fetchAllOperations(addr, addr,
|
|
40
|
-
expect(ops.length).toEqual(19)
|
|
41
|
+
const addr = 'GCOCZ3ODGW3YH6PPGMLGT3MORS5YBTVJCSL46TC2NMU2KCXGL52XLEZB'
|
|
42
|
+
const ops = await fetchAllOperations(addr, addr, 'desc', '241330913827401737')
|
|
43
|
+
expect(ops.length).toEqual(19)
|
|
41
44
|
expect(ops[0].id).toEqual(
|
|
42
|
-
`${addr}-7352d7e754c93b39213288a268efec78843ce8db6fa15f88308c7c852f6806c9-IN
|
|
43
|
-
)
|
|
45
|
+
`${addr}-7352d7e754c93b39213288a268efec78843ce8db6fa15f88308c7c852f6806c9-IN`
|
|
46
|
+
)
|
|
44
47
|
expect(ops[18].id).toEqual(
|
|
45
|
-
`${addr}-af8982997f1765ebbd41b36ab6927825f7083dc3ced07d1d086c1a3ca9c7e3e9-IN
|
|
46
|
-
)
|
|
48
|
+
`${addr}-af8982997f1765ebbd41b36ab6927825f7083dc3ced07d1d086c1a3ca9c7e3e9-IN`
|
|
49
|
+
)
|
|
47
50
|
},
|
|
48
|
-
10 * 1_000
|
|
49
|
-
)
|
|
51
|
+
10 * 1_000
|
|
52
|
+
)
|
|
50
53
|
|
|
51
54
|
it(
|
|
52
|
-
|
|
55
|
+
'fetch operations with limitations, set order to asc',
|
|
53
56
|
async () => {
|
|
54
|
-
const addr =
|
|
55
|
-
const limit = 20
|
|
56
|
-
const ops = await fetchAllOperations(addr, addr,
|
|
57
|
-
expect(ops.length).toEqual(limit)
|
|
57
|
+
const addr = 'GCOCZ3ODGW3YH6PPGMLGT3MORS5YBTVJCSL46TC2NMU2KCXGL52XLEZB'
|
|
58
|
+
const limit = 20
|
|
59
|
+
const ops = await fetchAllOperations(addr, addr, 'asc', '241343201729257475', limit)
|
|
60
|
+
expect(ops.length).toEqual(limit)
|
|
58
61
|
expect(ops[0].id).toEqual(
|
|
59
|
-
`${addr}-71b49018e0ad4f9c72132a89bb58f921158aed3023f7543bab176881ff0b5b14-IN
|
|
60
|
-
)
|
|
62
|
+
`${addr}-71b49018e0ad4f9c72132a89bb58f921158aed3023f7543bab176881ff0b5b14-IN`
|
|
63
|
+
)
|
|
61
64
|
expect(ops[19].id).toEqual(
|
|
62
|
-
`${addr}-71b49018e0ad4f9c72132a89bb58f921158aed3023f7543bab176881ff0b5b14-IN
|
|
63
|
-
)
|
|
65
|
+
`${addr}-71b49018e0ad4f9c72132a89bb58f921158aed3023f7543bab176881ff0b5b14-IN`
|
|
66
|
+
)
|
|
64
67
|
},
|
|
65
|
-
10 * 1_000
|
|
66
|
-
)
|
|
67
|
-
})
|
|
68
|
+
10 * 1_000
|
|
69
|
+
)
|
|
70
|
+
})
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import coinConfig from '../config'
|
|
5
|
+
import { useConfigHostAndProtocol } from './horizon'
|
|
6
|
+
|
|
7
|
+
describe('Horizon', () => {
|
|
5
8
|
beforeAll(() => {
|
|
6
9
|
coinConfig.setCoinConfig(
|
|
7
|
-
() => ({ explorer: { url:
|
|
8
|
-
)
|
|
9
|
-
})
|
|
10
|
+
() => ({ explorer: { url: 'https://stellar.coin.ledger.com' } }) as any
|
|
11
|
+
)
|
|
12
|
+
})
|
|
10
13
|
|
|
11
|
-
describe(
|
|
14
|
+
describe('useConfigHostAndProtocol', () => {
|
|
12
15
|
it.each([
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
])(
|
|
16
|
-
expect(useConfigHostAndProtocol(url)).toEqual(
|
|
17
|
-
})
|
|
18
|
-
})
|
|
19
|
-
})
|
|
16
|
+
['host', 'https://injected.com/1'],
|
|
17
|
+
['protocol', 'injected://stellar.coin.ledger.com/1'],
|
|
18
|
+
])('overwrites the %s of the URL with the original one', (_s, url) => {
|
|
19
|
+
expect(useConfigHostAndProtocol(url)).toEqual('https://stellar.coin.ledger.com/1')
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
})
|