@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
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Unit tests for registerHorizonInterceptors.
|
|
3
6
|
*
|
|
@@ -7,267 +10,267 @@
|
|
|
7
10
|
* within the isolated module registry (stellar-sdk is re-resolved but cached for
|
|
8
11
|
* all requires inside the same isolateModules block)
|
|
9
12
|
*/
|
|
10
|
-
import type { StellarCoinConfig } from
|
|
13
|
+
import type { StellarCoinConfig } from '../config'
|
|
11
14
|
|
|
12
15
|
// ---------------------------------------------------------------------------
|
|
13
16
|
// Helpers
|
|
14
17
|
// ---------------------------------------------------------------------------
|
|
15
18
|
|
|
16
|
-
type IsolatedHorizon = typeof import(
|
|
17
|
-
type IsolatedHorizonModule = typeof import(
|
|
18
|
-
type IsolatedConfigModule = typeof import(
|
|
19
|
+
type IsolatedHorizon = typeof import('@stellar/stellar-sdk')
|
|
20
|
+
type IsolatedHorizonModule = typeof import('./horizon')
|
|
21
|
+
type IsolatedConfigModule = typeof import('../config')
|
|
19
22
|
|
|
20
23
|
function isolatedRequire(): {
|
|
21
|
-
Horizon: IsolatedHorizon[
|
|
22
|
-
registerHorizonInterceptors: IsolatedHorizonModule[
|
|
23
|
-
coinConfig: IsolatedConfigModule[
|
|
24
|
+
Horizon: IsolatedHorizon['Horizon']
|
|
25
|
+
registerHorizonInterceptors: IsolatedHorizonModule['registerHorizonInterceptors']
|
|
26
|
+
coinConfig: IsolatedConfigModule['default']
|
|
24
27
|
} {
|
|
25
28
|
// `require` here runs inside the jest.isolateModules callback supplied by each test
|
|
26
29
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
27
|
-
const { Horizon } = require(
|
|
28
|
-
const { registerHorizonInterceptors } = require(
|
|
29
|
-
const coinConfig = (require(
|
|
30
|
+
const { Horizon } = require('@stellar/stellar-sdk') as IsolatedHorizon
|
|
31
|
+
const { registerHorizonInterceptors } = require('./horizon') as IsolatedHorizonModule
|
|
32
|
+
const coinConfig = (require('../config') as IsolatedConfigModule).default
|
|
30
33
|
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
31
|
-
return { Horizon, registerHorizonInterceptors, coinConfig }
|
|
34
|
+
return { Horizon, registerHorizonInterceptors, coinConfig }
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
/** Returns the last element of an array without relying on Array.prototype.at (es2022). */
|
|
35
38
|
function last<T>(arr: T[]): T | undefined {
|
|
36
|
-
return arr[arr.length - 1]
|
|
39
|
+
return arr[arr.length - 1]
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
/** Builds a minimal HttpClientResponse-compatible mock object. */
|
|
40
43
|
function makeResponse(overrides: { status?: number; config?: object; data?: unknown } = {}) {
|
|
41
44
|
return {
|
|
42
45
|
status: 200,
|
|
43
|
-
statusText:
|
|
46
|
+
statusText: 'OK',
|
|
44
47
|
headers: {},
|
|
45
48
|
config: {},
|
|
46
49
|
data: {},
|
|
47
50
|
...overrides,
|
|
48
|
-
}
|
|
51
|
+
}
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
function makeConfig(overrides: Partial<StellarCoinConfig> = {}): StellarCoinConfig {
|
|
52
55
|
return {
|
|
53
|
-
status: { type:
|
|
54
|
-
explorer: { url:
|
|
56
|
+
status: { type: 'active' },
|
|
57
|
+
explorer: { url: 'https://horizon.test.invalid' },
|
|
55
58
|
...overrides,
|
|
56
|
-
}
|
|
59
|
+
}
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
// ---------------------------------------------------------------------------
|
|
60
63
|
// Tests
|
|
61
64
|
// ---------------------------------------------------------------------------
|
|
62
65
|
|
|
63
|
-
describe(
|
|
64
|
-
describe(
|
|
65
|
-
it(
|
|
66
|
+
describe('registerHorizonInterceptors', () => {
|
|
67
|
+
describe('idempotency', () => {
|
|
68
|
+
it('registers each interceptor exactly once even when called multiple times', () => {
|
|
66
69
|
jest.isolateModules(() => {
|
|
67
|
-
const { Horizon, registerHorizonInterceptors } = isolatedRequire()
|
|
70
|
+
const { Horizon, registerHorizonInterceptors } = isolatedRequire()
|
|
68
71
|
|
|
69
|
-
const reqSpy = jest.spyOn(Horizon.AxiosClient.interceptors.request,
|
|
70
|
-
const resSpy = jest.spyOn(Horizon.AxiosClient.interceptors.response,
|
|
72
|
+
const reqSpy = jest.spyOn(Horizon.AxiosClient.interceptors.request, 'use')
|
|
73
|
+
const resSpy = jest.spyOn(Horizon.AxiosClient.interceptors.response, 'use')
|
|
71
74
|
|
|
72
|
-
registerHorizonInterceptors()
|
|
73
|
-
registerHorizonInterceptors()
|
|
74
|
-
registerHorizonInterceptors()
|
|
75
|
+
registerHorizonInterceptors()
|
|
76
|
+
registerHorizonInterceptors()
|
|
77
|
+
registerHorizonInterceptors()
|
|
75
78
|
|
|
76
|
-
expect(reqSpy).toHaveBeenCalledTimes(1)
|
|
77
|
-
expect(resSpy).toHaveBeenCalledTimes(1)
|
|
79
|
+
expect(reqSpy).toHaveBeenCalledTimes(1)
|
|
80
|
+
expect(resSpy).toHaveBeenCalledTimes(1)
|
|
78
81
|
|
|
79
|
-
reqSpy.mockRestore()
|
|
80
|
-
resSpy.mockRestore()
|
|
81
|
-
})
|
|
82
|
-
})
|
|
82
|
+
reqSpy.mockRestore()
|
|
83
|
+
resSpy.mockRestore()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
83
86
|
|
|
84
|
-
it(
|
|
87
|
+
it('does not throw when called multiple times', () => {
|
|
85
88
|
jest.isolateModules(() => {
|
|
86
|
-
const { registerHorizonInterceptors } = isolatedRequire()
|
|
89
|
+
const { registerHorizonInterceptors } = isolatedRequire()
|
|
87
90
|
expect(() => {
|
|
88
|
-
registerHorizonInterceptors()
|
|
89
|
-
registerHorizonInterceptors()
|
|
90
|
-
}).not.toThrow()
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
describe(
|
|
96
|
-
it(
|
|
91
|
+
registerHorizonInterceptors()
|
|
92
|
+
registerHorizonInterceptors()
|
|
93
|
+
}).not.toThrow()
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
describe('resilience when coinConfig is not initialised', () => {
|
|
99
|
+
it('registerHorizonInterceptors itself does not throw without coinConfig', () => {
|
|
97
100
|
jest.isolateModules(() => {
|
|
98
|
-
const { registerHorizonInterceptors } = isolatedRequire()
|
|
99
|
-
expect(() => registerHorizonInterceptors()).not.toThrow()
|
|
100
|
-
})
|
|
101
|
-
})
|
|
101
|
+
const { registerHorizonInterceptors } = isolatedRequire()
|
|
102
|
+
expect(() => registerHorizonInterceptors()).not.toThrow()
|
|
103
|
+
})
|
|
104
|
+
})
|
|
102
105
|
|
|
103
|
-
it(
|
|
106
|
+
it('request interceptor returns config unchanged and does not throw', () => {
|
|
104
107
|
jest.isolateModules(() => {
|
|
105
|
-
const { Horizon, registerHorizonInterceptors } = isolatedRequire()
|
|
106
|
-
registerHorizonInterceptors()
|
|
108
|
+
const { Horizon, registerHorizonInterceptors } = isolatedRequire()
|
|
109
|
+
registerHorizonInterceptors()
|
|
107
110
|
|
|
108
|
-
const handler = last(Horizon.AxiosClient.interceptors.request.handlers)
|
|
109
|
-
expect(handler).toEqual(expect.objectContaining({ fulfilled: expect.any(Function) }))
|
|
111
|
+
const handler = last(Horizon.AxiosClient.interceptors.request.handlers)
|
|
112
|
+
expect(handler).toEqual(expect.objectContaining({ fulfilled: expect.any(Function) }))
|
|
110
113
|
|
|
111
114
|
const mockConfig = {
|
|
112
|
-
url:
|
|
113
|
-
method:
|
|
114
|
-
baseURL:
|
|
115
|
-
}
|
|
116
|
-
expect(() => handler!.fulfilled(mockConfig)).not.toThrow()
|
|
117
|
-
expect(handler!.fulfilled(mockConfig)).toBe(mockConfig)
|
|
118
|
-
})
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it(
|
|
115
|
+
url: '/accounts/G123',
|
|
116
|
+
method: 'GET',
|
|
117
|
+
baseURL: 'https://horizon.test.invalid',
|
|
118
|
+
}
|
|
119
|
+
expect(() => handler!.fulfilled(mockConfig)).not.toThrow()
|
|
120
|
+
expect(handler!.fulfilled(mockConfig)).toBe(mockConfig)
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('response interceptor returns response unchanged and does not throw', () => {
|
|
122
125
|
jest.isolateModules(() => {
|
|
123
|
-
const { Horizon, registerHorizonInterceptors } = isolatedRequire()
|
|
124
|
-
registerHorizonInterceptors()
|
|
126
|
+
const { Horizon, registerHorizonInterceptors } = isolatedRequire()
|
|
127
|
+
registerHorizonInterceptors()
|
|
125
128
|
|
|
126
|
-
const handler = last(Horizon.AxiosClient.interceptors.response.handlers)
|
|
127
|
-
expect(handler).toEqual(expect.objectContaining({ fulfilled: expect.any(Function) }))
|
|
129
|
+
const handler = last(Horizon.AxiosClient.interceptors.response.handlers)
|
|
130
|
+
expect(handler).toEqual(expect.objectContaining({ fulfilled: expect.any(Function) }))
|
|
128
131
|
|
|
129
|
-
const mockResponse = makeResponse()
|
|
130
|
-
expect(() => handler!.fulfilled(mockResponse)).not.toThrow()
|
|
131
|
-
expect(handler!.fulfilled(mockResponse)).toBe(mockResponse)
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
})
|
|
132
|
+
const mockResponse = makeResponse()
|
|
133
|
+
expect(() => handler!.fulfilled(mockResponse)).not.toThrow()
|
|
134
|
+
expect(handler!.fulfilled(mockResponse)).toBe(mockResponse)
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
})
|
|
135
138
|
|
|
136
|
-
describe(
|
|
137
|
-
it(
|
|
139
|
+
describe('URL rewriting (always active, independent of logging)', () => {
|
|
140
|
+
it('rewrites _links.next.href to use the configured host', () => {
|
|
138
141
|
jest.isolateModules(() => {
|
|
139
|
-
const { Horizon, registerHorizonInterceptors, coinConfig } = isolatedRequire()
|
|
140
|
-
coinConfig.setCoinConfig(() => makeConfig())
|
|
141
|
-
registerHorizonInterceptors()
|
|
142
|
+
const { Horizon, registerHorizonInterceptors, coinConfig } = isolatedRequire()
|
|
143
|
+
coinConfig.setCoinConfig(() => makeConfig())
|
|
144
|
+
registerHorizonInterceptors()
|
|
142
145
|
|
|
143
|
-
const handler = last(Horizon.AxiosClient.interceptors.response.handlers)
|
|
146
|
+
const handler = last(Horizon.AxiosClient.interceptors.response.handlers)
|
|
144
147
|
|
|
145
148
|
const data = {
|
|
146
149
|
_links: {
|
|
147
|
-
next: { href:
|
|
150
|
+
next: { href: 'https://some-internal-node.stellar.org/operations?cursor=123' },
|
|
148
151
|
},
|
|
149
|
-
}
|
|
152
|
+
}
|
|
150
153
|
|
|
151
|
-
handler!.fulfilled(makeResponse({ data }))
|
|
154
|
+
handler!.fulfilled(makeResponse({ data }))
|
|
152
155
|
|
|
153
|
-
expect(data._links.next.href).toBe(
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
+
expect(data._links.next.href).toBe('https://horizon.test.invalid/operations?cursor=123')
|
|
157
|
+
})
|
|
158
|
+
})
|
|
156
159
|
|
|
157
|
-
it(
|
|
160
|
+
it('rewrites _embedded.records[].transaction._links.ledger.href to use the configured host', () => {
|
|
158
161
|
jest.isolateModules(() => {
|
|
159
|
-
const { Horizon, registerHorizonInterceptors, coinConfig } = isolatedRequire()
|
|
160
|
-
coinConfig.setCoinConfig(() => makeConfig())
|
|
161
|
-
registerHorizonInterceptors()
|
|
162
|
+
const { Horizon, registerHorizonInterceptors, coinConfig } = isolatedRequire()
|
|
163
|
+
coinConfig.setCoinConfig(() => makeConfig())
|
|
164
|
+
registerHorizonInterceptors()
|
|
162
165
|
|
|
163
|
-
const handler = last(Horizon.AxiosClient.interceptors.response.handlers)
|
|
166
|
+
const handler = last(Horizon.AxiosClient.interceptors.response.handlers)
|
|
164
167
|
|
|
165
168
|
const data = {
|
|
166
169
|
_embedded: {
|
|
167
170
|
records: [
|
|
168
171
|
{
|
|
169
172
|
transaction: {
|
|
170
|
-
_links: { ledger: { href:
|
|
173
|
+
_links: { ledger: { href: 'https://some-internal-node.stellar.org/ledgers/55' } },
|
|
171
174
|
},
|
|
172
175
|
},
|
|
173
176
|
{
|
|
174
177
|
transaction: {
|
|
175
|
-
_links: { ledger: { href:
|
|
178
|
+
_links: { ledger: { href: 'https://some-internal-node.stellar.org/ledgers/56' } },
|
|
176
179
|
},
|
|
177
180
|
},
|
|
178
181
|
],
|
|
179
182
|
},
|
|
180
|
-
}
|
|
183
|
+
}
|
|
181
184
|
|
|
182
|
-
handler!.fulfilled(makeResponse({ data }))
|
|
185
|
+
handler!.fulfilled(makeResponse({ data }))
|
|
183
186
|
|
|
184
187
|
expect(data._embedded.records[0].transaction._links.ledger.href).toBe(
|
|
185
|
-
|
|
186
|
-
)
|
|
188
|
+
'https://horizon.test.invalid/ledgers/55'
|
|
189
|
+
)
|
|
187
190
|
expect(data._embedded.records[1].transaction._links.ledger.href).toBe(
|
|
188
|
-
|
|
189
|
-
)
|
|
190
|
-
})
|
|
191
|
-
})
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
describe(
|
|
195
|
-
it(
|
|
191
|
+
'https://horizon.test.invalid/ledgers/56'
|
|
192
|
+
)
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
describe('network logging (gated on enableNetworkLogs)', () => {
|
|
198
|
+
it('emits network log for requests when enableNetworkLogs is true', () => {
|
|
196
199
|
jest.isolateModules(() => {
|
|
197
|
-
const logMock = jest.fn()
|
|
198
|
-
jest.mock(
|
|
200
|
+
const logMock = jest.fn()
|
|
201
|
+
jest.mock('@ledgerhq/logs', () => ({ log: logMock }))
|
|
199
202
|
|
|
200
|
-
const { Horizon, registerHorizonInterceptors, coinConfig } = isolatedRequire()
|
|
201
|
-
coinConfig.setCoinConfig(() => makeConfig({ enableNetworkLogs: true }))
|
|
202
|
-
registerHorizonInterceptors()
|
|
203
|
+
const { Horizon, registerHorizonInterceptors, coinConfig } = isolatedRequire()
|
|
204
|
+
coinConfig.setCoinConfig(() => makeConfig({ enableNetworkLogs: true }))
|
|
205
|
+
registerHorizonInterceptors()
|
|
203
206
|
|
|
204
|
-
const handler = last(Horizon.AxiosClient.interceptors.request.handlers)
|
|
207
|
+
const handler = last(Horizon.AxiosClient.interceptors.request.handlers)
|
|
205
208
|
handler!.fulfilled({
|
|
206
|
-
url:
|
|
207
|
-
method:
|
|
208
|
-
baseURL:
|
|
209
|
-
})
|
|
209
|
+
url: '/accounts/G123',
|
|
210
|
+
method: 'GET',
|
|
211
|
+
baseURL: 'https://horizon.test.invalid',
|
|
212
|
+
})
|
|
210
213
|
|
|
211
214
|
expect(logMock).toHaveBeenCalledWith(
|
|
212
|
-
|
|
213
|
-
expect.stringContaining(
|
|
214
|
-
expect.anything()
|
|
215
|
-
)
|
|
216
|
-
})
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
it(
|
|
215
|
+
'network',
|
|
216
|
+
expect.stringContaining('/accounts/G123'),
|
|
217
|
+
expect.anything()
|
|
218
|
+
)
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('emits network-success log for responses with elapsed time when enableNetworkLogs is true', () => {
|
|
220
223
|
jest.isolateModules(() => {
|
|
221
|
-
const logMock = jest.fn()
|
|
222
|
-
jest.mock(
|
|
224
|
+
const logMock = jest.fn()
|
|
225
|
+
jest.mock('@ledgerhq/logs', () => ({ log: logMock }))
|
|
223
226
|
|
|
224
|
-
const { Horizon, registerHorizonInterceptors, coinConfig } = isolatedRequire()
|
|
225
|
-
coinConfig.setCoinConfig(() => makeConfig({ enableNetworkLogs: true }))
|
|
226
|
-
registerHorizonInterceptors()
|
|
227
|
+
const { Horizon, registerHorizonInterceptors, coinConfig } = isolatedRequire()
|
|
228
|
+
coinConfig.setCoinConfig(() => makeConfig({ enableNetworkLogs: true }))
|
|
229
|
+
registerHorizonInterceptors()
|
|
227
230
|
|
|
228
|
-
const reqHandler = last(Horizon.AxiosClient.interceptors.request.handlers)
|
|
229
|
-
const resHandler = last(Horizon.AxiosClient.interceptors.response.handlers)
|
|
231
|
+
const reqHandler = last(Horizon.AxiosClient.interceptors.request.handlers)
|
|
232
|
+
const resHandler = last(Horizon.AxiosClient.interceptors.response.handlers)
|
|
230
233
|
|
|
231
234
|
const config = {
|
|
232
|
-
url:
|
|
233
|
-
method:
|
|
234
|
-
baseURL:
|
|
235
|
-
}
|
|
236
|
-
reqHandler!.fulfilled(config)
|
|
235
|
+
url: '/accounts/G123',
|
|
236
|
+
method: 'GET',
|
|
237
|
+
baseURL: 'https://horizon.test.invalid',
|
|
238
|
+
}
|
|
239
|
+
reqHandler!.fulfilled(config)
|
|
237
240
|
|
|
238
|
-
const mockResponse = makeResponse({ status: 200, config })
|
|
239
|
-
resHandler!.fulfilled(mockResponse)
|
|
241
|
+
const mockResponse = makeResponse({ status: 200, config })
|
|
242
|
+
resHandler!.fulfilled(mockResponse)
|
|
240
243
|
|
|
241
244
|
expect(logMock).toHaveBeenCalledWith(
|
|
242
|
-
|
|
245
|
+
'network-success',
|
|
243
246
|
expect.stringMatching(/200 GET.*\/accounts\/G123.*\d+ms/),
|
|
244
|
-
expect.anything()
|
|
245
|
-
)
|
|
246
|
-
})
|
|
247
|
-
})
|
|
247
|
+
expect.anything()
|
|
248
|
+
)
|
|
249
|
+
})
|
|
250
|
+
})
|
|
248
251
|
|
|
249
|
-
it(
|
|
252
|
+
it('does not emit any log when enableNetworkLogs is false', () => {
|
|
250
253
|
jest.isolateModules(() => {
|
|
251
|
-
const logMock = jest.fn()
|
|
252
|
-
jest.mock(
|
|
254
|
+
const logMock = jest.fn()
|
|
255
|
+
jest.mock('@ledgerhq/logs', () => ({ log: logMock }))
|
|
253
256
|
|
|
254
|
-
const { Horizon, registerHorizonInterceptors, coinConfig } = isolatedRequire()
|
|
255
|
-
coinConfig.setCoinConfig(() => makeConfig({ enableNetworkLogs: false }))
|
|
256
|
-
registerHorizonInterceptors()
|
|
257
|
+
const { Horizon, registerHorizonInterceptors, coinConfig } = isolatedRequire()
|
|
258
|
+
coinConfig.setCoinConfig(() => makeConfig({ enableNetworkLogs: false }))
|
|
259
|
+
registerHorizonInterceptors()
|
|
257
260
|
|
|
258
|
-
const reqHandler = last(Horizon.AxiosClient.interceptors.request.handlers)
|
|
259
|
-
const resHandler = last(Horizon.AxiosClient.interceptors.response.handlers)
|
|
261
|
+
const reqHandler = last(Horizon.AxiosClient.interceptors.request.handlers)
|
|
262
|
+
const resHandler = last(Horizon.AxiosClient.interceptors.response.handlers)
|
|
260
263
|
|
|
261
264
|
const config = {
|
|
262
|
-
url:
|
|
263
|
-
method:
|
|
264
|
-
baseURL:
|
|
265
|
-
}
|
|
266
|
-
reqHandler!.fulfilled(config)
|
|
267
|
-
resHandler!.fulfilled(makeResponse({ config }))
|
|
268
|
-
|
|
269
|
-
expect(logMock).not.toHaveBeenCalled()
|
|
270
|
-
})
|
|
271
|
-
})
|
|
272
|
-
})
|
|
273
|
-
})
|
|
265
|
+
url: '/accounts/G123',
|
|
266
|
+
method: 'GET',
|
|
267
|
+
baseURL: 'https://horizon.test.invalid',
|
|
268
|
+
}
|
|
269
|
+
reqHandler!.fulfilled(config)
|
|
270
|
+
resHandler!.fulfilled(makeResponse({ config }))
|
|
271
|
+
|
|
272
|
+
expect(logMock).not.toHaveBeenCalled()
|
|
273
|
+
})
|
|
274
|
+
})
|
|
275
|
+
})
|
|
276
|
+
})
|