@ledgerhq/coin-evm 5.3.2 → 5.3.4
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 +2 -2
- package/CHANGELOG.md +13 -0
- package/package.json +2 -2
- package/src/adapters/blockOperations.test.ts +27 -29
- package/src/api/index.flare.integ.test.ts +1 -13
- package/src/api/index.integ.test.ts +86 -97
- package/src/fixtures/context.fixtures.ts +79 -1
- package/src/fixtures/ethers.fixtures.ts +26 -0
- package/src/logic/broadcast.integ.test.ts +6 -18
- package/src/logic/broadcast.test.ts +19 -31
- package/src/logic/broadcastSource.test.ts +6 -7
- package/src/logic/common.test.ts +120 -112
- package/src/logic/craftTransaction.test.ts +161 -199
- package/src/logic/craftTransactionData.test.ts +6 -6
- package/src/logic/estimateFees.test.ts +19 -15
- package/src/logic/getBalance.test.ts +15 -14
- package/src/logic/getBlock.test.ts +372 -382
- package/src/logic/getBlockInfo.test.ts +6 -6
- package/src/logic/getNextSequence.test.ts +5 -5
- package/src/logic/getStakes.test.ts +34 -34
- package/src/logic/internalTransactionsFetcher.test.ts +23 -19
- package/src/logic/lastBlock.test.ts +29 -21
- package/src/logic/listOperations.test.ts +43 -40
- package/src/logic/validateIntent.test.ts +151 -101
- package/src/logic.test.ts +59 -79
- package/src/network/explorer/etherscan.test.ts +95 -136
- package/src/network/explorer/index.test.ts +51 -21
- package/src/network/explorer/ledger.test.ts +51 -44
- package/src/network/gasTracker/index.test.ts +14 -8
- package/src/network/gasTracker/ledger.test.ts +43 -61
- package/src/network/node/index.memoization.test.ts +25 -31
- package/src/network/node/index.test.ts +14 -25
- package/src/network/node/ledger.test.ts +45 -60
- package/src/network/node/node.fixtures.ts +0 -2
- package/src/network/node/rpc.test.ts +204 -219
- package/src/staking/encoder.test.ts +13 -21
- package/src/staking/logic.test.ts +20 -14
- package/src/staking/operations/index.test.ts +28 -28
- package/src/staking/prepareIntents.test.ts +26 -20
- package/src/staking/redelegations.test.ts +27 -18
- package/src/staking/rewards.test.ts +23 -15
- package/src/staking/rewardsFromReceipt.test.ts +19 -20
- package/src/staking/transactionData.test.ts +22 -22
- package/src/staking/validators/monad.test.ts +65 -24
- package/src/staking/validators/somnia.test.ts +21 -13
- package/src/staking/validators/zero_gravity.test.ts +118 -48
- package/src/staking/validators.integ.test.ts +13 -25
- package/src/api/index.fantom.integ.test.ts +0 -103
|
@@ -8,6 +8,11 @@ import axios from 'axios'
|
|
|
8
8
|
import eip55 from 'eip55'
|
|
9
9
|
import { DEFAULT_LEDGER_EXPLORER_URI, getCoinConfig } from '../../config'
|
|
10
10
|
import { LedgerExplorerUsedIncorrectly } from '../../errors'
|
|
11
|
+
import {
|
|
12
|
+
createMockEvmCoinConfig,
|
|
13
|
+
mkExternalNode,
|
|
14
|
+
mkLedgerNode,
|
|
15
|
+
} from '../../fixtures/context.fixtures'
|
|
11
16
|
import {
|
|
12
17
|
coinOperation1,
|
|
13
18
|
coinOperation2,
|
|
@@ -18,7 +23,7 @@ import * as LEDGER_API from './ledger'
|
|
|
18
23
|
|
|
19
24
|
jest.mock('axios')
|
|
20
25
|
jest.mock('@ledgerhq/coin-module-framework/promises')
|
|
21
|
-
|
|
26
|
+
jest.mocked(delay).mockImplementation(
|
|
22
27
|
() => new Promise((resolve) => setTimeout(resolve, 1)) // mocking the delay supposed to happen after each try
|
|
23
28
|
)
|
|
24
29
|
|
|
@@ -28,17 +33,14 @@ const mockGetConfig = jest.mocked(getCoinConfig)
|
|
|
28
33
|
describe('EVM Family', () => {
|
|
29
34
|
describe('network/explorer/ledger.ts', () => {
|
|
30
35
|
beforeEach(() => {
|
|
31
|
-
mockGetConfig.mockImplementation(()
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
})
|
|
36
|
+
mockGetConfig.mockImplementation(() =>
|
|
37
|
+
createMockEvmCoinConfig({
|
|
38
|
+
chainId: 1,
|
|
39
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
40
|
+
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
41
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
42
|
+
})
|
|
43
|
+
)
|
|
42
44
|
})
|
|
43
45
|
|
|
44
46
|
afterEach(() => {
|
|
@@ -55,7 +57,12 @@ describe('EVM Family', () => {
|
|
|
55
57
|
}
|
|
56
58
|
return { data: { data: [] } }
|
|
57
59
|
})
|
|
58
|
-
const response = await LEDGER_API.fetchPaginatedOpsWithRetries(
|
|
60
|
+
const response = await LEDGER_API.fetchPaginatedOpsWithRetries(
|
|
61
|
+
{ explorerId: 'test', address: '0x', fromBlock: 0, batchSize: 10 },
|
|
62
|
+
null,
|
|
63
|
+
[],
|
|
64
|
+
retries
|
|
65
|
+
)
|
|
59
66
|
|
|
60
67
|
expect(response).toEqual([])
|
|
61
68
|
// it should fail 2 times and succeed on the next try
|
|
@@ -74,7 +81,10 @@ describe('EVM Family', () => {
|
|
|
74
81
|
return { data: { data: [] } }
|
|
75
82
|
})
|
|
76
83
|
try {
|
|
77
|
-
await LEDGER_API.fetchPaginatedOpsWithRetries(
|
|
84
|
+
await LEDGER_API.fetchPaginatedOpsWithRetries(
|
|
85
|
+
{ explorerId: 'test', address: '0x', fromBlock: 0, batchSize: 10 },
|
|
86
|
+
null
|
|
87
|
+
)
|
|
78
88
|
fail('Promise should have been rejected')
|
|
79
89
|
} catch (e) {
|
|
80
90
|
if (e instanceof AssertionError) {
|
|
@@ -113,7 +123,10 @@ describe('EVM Family', () => {
|
|
|
113
123
|
}
|
|
114
124
|
})
|
|
115
125
|
|
|
116
|
-
const response = await LEDGER_API.fetchPaginatedOpsWithRetries(
|
|
126
|
+
const response = await LEDGER_API.fetchPaginatedOpsWithRetries(
|
|
127
|
+
{ explorerId: 'test', address: '0x', fromBlock: 0, batchSize: 10 },
|
|
128
|
+
null
|
|
129
|
+
)
|
|
117
130
|
|
|
118
131
|
expect(response).toEqual([coinOperation1, coinOperation2, coinOperation3])
|
|
119
132
|
})
|
|
@@ -168,16 +181,9 @@ describe('EVM Family', () => {
|
|
|
168
181
|
})
|
|
169
182
|
|
|
170
183
|
it('should throw if the explorer is misconfigured', async () => {
|
|
171
|
-
mockGetConfig.mockImplementationOnce(()
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
node: {
|
|
175
|
-
type: 'wrongtype',
|
|
176
|
-
uri: 'anything',
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
}
|
|
180
|
-
})
|
|
184
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
185
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'anything' }) })
|
|
186
|
+
)
|
|
181
187
|
|
|
182
188
|
try {
|
|
183
189
|
await LEDGER_API.getOperations(
|
|
@@ -437,16 +443,13 @@ describe('EVM Family', () => {
|
|
|
437
443
|
|
|
438
444
|
describe('getOperations without nft', () => {
|
|
439
445
|
beforeEach(() => {
|
|
440
|
-
mockGetConfig.mockImplementation(()
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
},
|
|
448
|
-
}
|
|
449
|
-
})
|
|
446
|
+
mockGetConfig.mockImplementation(() =>
|
|
447
|
+
createMockEvmCoinConfig({
|
|
448
|
+
chainId: 1,
|
|
449
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
450
|
+
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
451
|
+
})
|
|
452
|
+
)
|
|
450
453
|
})
|
|
451
454
|
|
|
452
455
|
it('should not return NFT opperation', async () => {
|
|
@@ -480,12 +483,14 @@ describe('EVM Family', () => {
|
|
|
480
483
|
})
|
|
481
484
|
|
|
482
485
|
const mockConfigWithTokens = (supportedTokens: NftStandard[]) =>
|
|
483
|
-
mockGetConfig.mockImplementation(()
|
|
484
|
-
|
|
486
|
+
mockGetConfig.mockImplementation(() =>
|
|
487
|
+
createMockEvmCoinConfig({
|
|
488
|
+
chainId: 1,
|
|
489
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
485
490
|
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
486
491
|
supportedTokens,
|
|
487
|
-
}
|
|
488
|
-
|
|
492
|
+
})
|
|
493
|
+
)
|
|
489
494
|
|
|
490
495
|
const fetchNftAssetTypes = async () => {
|
|
491
496
|
const response = await LEDGER_API.getOperations(
|
|
@@ -525,14 +530,16 @@ describe('EVM Family', () => {
|
|
|
525
530
|
// coinOperation1.transfer_events[0].contract — the only ERC20 event in the fixtures.
|
|
526
531
|
const FIXTURE_CONTRACT = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
|
|
527
532
|
|
|
528
|
-
const withConfig = (info:
|
|
529
|
-
mockGetConfig.mockImplementation(()
|
|
530
|
-
|
|
533
|
+
const withConfig = (info: { nativeContracts?: string[] }) =>
|
|
534
|
+
mockGetConfig.mockImplementation(() =>
|
|
535
|
+
createMockEvmCoinConfig({
|
|
536
|
+
chainId: 1,
|
|
537
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
531
538
|
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
532
539
|
supportedTokens: ['erc721', 'erc1155'],
|
|
533
540
|
...info,
|
|
534
|
-
}
|
|
535
|
-
|
|
541
|
+
})
|
|
542
|
+
)
|
|
536
543
|
|
|
537
544
|
it('drops ERC20 transfer events whose contract is listed in nativeContracts', async () => {
|
|
538
545
|
withConfig({ nativeContracts: [FIXTURE_CONTRACT] })
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import {
|
|
5
|
+
createMockEvmConfigInfo,
|
|
6
|
+
mkLedgerGasTracker,
|
|
7
|
+
mkLedgerNode,
|
|
8
|
+
} from '../../fixtures/context.fixtures'
|
|
5
9
|
import { getGasOptions as ledgerGetGasOptions } from './ledger'
|
|
6
10
|
import { getGasTracker } from './index'
|
|
7
11
|
|
|
8
|
-
const configWithGasTracker = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
const configWithGasTracker = createMockEvmConfigInfo({
|
|
13
|
+
chainId: 1,
|
|
14
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
15
|
+
gasTracker: mkLedgerGasTracker({ explorerId: 'eth' }),
|
|
16
|
+
})
|
|
12
17
|
|
|
13
|
-
const configWithoutGasTracker = {
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
const configWithoutGasTracker = createMockEvmConfigInfo({
|
|
19
|
+
chainId: 1,
|
|
20
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
21
|
+
})
|
|
16
22
|
|
|
17
23
|
describe('EVM Family', () => {
|
|
18
24
|
describe('network/gasTracker/index.ts', () => {
|
|
@@ -1,40 +1,41 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { EvmConfigInfo } from '../../config'
|
|
5
4
|
import type { GasOptions } from '../../types'
|
|
6
5
|
import { AssertionError } from 'assert'
|
|
7
6
|
import network from '@ledgerhq/live-network/network'
|
|
7
|
+
import { AxiosHeaders } from 'axios'
|
|
8
8
|
import BigNumber from 'bignumber.js'
|
|
9
|
+
|
|
10
|
+
function makeNetworkResponse<T>(data: T) {
|
|
11
|
+
const headers = new AxiosHeaders()
|
|
12
|
+
return Promise.resolve({ data, status: 200, statusText: 'OK', headers, config: { headers } })
|
|
13
|
+
}
|
|
9
14
|
import { LedgerGasTrackerUsedIncorrectly, NoGasTrackerFound } from '../../errors'
|
|
15
|
+
import {
|
|
16
|
+
createMockEvmConfigInfo,
|
|
17
|
+
mkExternalNode,
|
|
18
|
+
mkLedgerGasTracker,
|
|
19
|
+
mkLedgerNode,
|
|
20
|
+
} from '../../fixtures/context.fixtures'
|
|
10
21
|
import { getGasOptions } from './ledger'
|
|
11
22
|
|
|
12
23
|
jest.mock('@ledgerhq/live-network/network')
|
|
13
24
|
const mockedNetwork = jest.mocked(network)
|
|
14
25
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} as unknown as EvmConfigInfo
|
|
26
|
+
const ledgerGasTrackerConfig = createMockEvmConfigInfo({
|
|
27
|
+
chainId: 1,
|
|
28
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
29
|
+
gasTracker: mkLedgerGasTracker({ explorerId: 'eth' }),
|
|
30
|
+
eip1559BaseFeeMultiplier: 2,
|
|
31
|
+
})
|
|
22
32
|
|
|
23
33
|
describe('EVM Family', () => {
|
|
24
34
|
describe('network/gasTracker/index.ts', () => {
|
|
25
35
|
beforeEach(() => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
low: '1',
|
|
30
|
-
medium: '2',
|
|
31
|
-
high: '3',
|
|
32
|
-
next_base: '4',
|
|
33
|
-
},
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
mockedNetwork.mockReturnValueOnce(gastrackerBarometerMock)
|
|
36
|
+
mockedNetwork.mockReturnValueOnce(
|
|
37
|
+
makeNetworkResponse({ low: '1', medium: '2', high: '3', next_base: '4' })
|
|
38
|
+
)
|
|
38
39
|
})
|
|
39
40
|
|
|
40
41
|
describe('ledger', () => {
|
|
@@ -75,18 +76,9 @@ describe('EVM Family', () => {
|
|
|
75
76
|
it('should return integer values when eip1559BaseFeeMultiplier is a float', async () => {
|
|
76
77
|
mockedNetwork.mockReset()
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
low: '1',
|
|
82
|
-
medium: '2',
|
|
83
|
-
high: '3',
|
|
84
|
-
next_base: '3',
|
|
85
|
-
},
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
mockedNetwork.mockReturnValueOnce(gastrackerBarometerMock)
|
|
79
|
+
mockedNetwork.mockReturnValueOnce(
|
|
80
|
+
makeNetworkResponse({ low: '1', medium: '2', high: '3', next_base: '3' })
|
|
81
|
+
)
|
|
90
82
|
|
|
91
83
|
const gasOptions: GasOptions = await getGasOptions({
|
|
92
84
|
currencyId: 'ethereum',
|
|
@@ -106,18 +98,9 @@ describe('EVM Family', () => {
|
|
|
106
98
|
it('should return interger values when API return floats', async () => {
|
|
107
99
|
mockedNetwork.mockReset()
|
|
108
100
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
low: '1.5',
|
|
113
|
-
medium: '2.4',
|
|
114
|
-
high: '3.7',
|
|
115
|
-
next_base: '3.8',
|
|
116
|
-
},
|
|
117
|
-
})
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
mockedNetwork.mockReturnValueOnce(gastrackerBarometerMock)
|
|
101
|
+
mockedNetwork.mockReturnValueOnce(
|
|
102
|
+
makeNetworkResponse({ low: '1.5', medium: '2.4', high: '3.7', next_base: '3.8' })
|
|
103
|
+
)
|
|
121
104
|
|
|
122
105
|
const gasOptions: GasOptions = await getGasOptions({
|
|
123
106
|
currencyId: 'ethereum',
|
|
@@ -139,7 +122,7 @@ describe('EVM Family', () => {
|
|
|
139
122
|
it('should use overrideGasTracker', async () => {
|
|
140
123
|
await getGasOptions({
|
|
141
124
|
currencyId: 'ethereum',
|
|
142
|
-
config: {
|
|
125
|
+
config: createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
|
|
143
126
|
options: {
|
|
144
127
|
useEIP1559: true,
|
|
145
128
|
overrideGasTracker: { type: 'ledger', explorerId: 'eth_sepolia' },
|
|
@@ -190,7 +173,11 @@ describe('EVM Family', () => {
|
|
|
190
173
|
it('should return legacy gas options when EIP-1559 not supported by gas tracker', async () => {
|
|
191
174
|
const gasOptions: GasOptions = await getGasOptions({
|
|
192
175
|
currencyId: 'ethereum_classic',
|
|
193
|
-
config: {
|
|
176
|
+
config: createMockEvmConfigInfo({
|
|
177
|
+
chainId: 1,
|
|
178
|
+
node: mkExternalNode(),
|
|
179
|
+
gasTracker: mkLedgerGasTracker({ explorerId: 'etc' }),
|
|
180
|
+
}),
|
|
194
181
|
options: { useEIP1559: true },
|
|
195
182
|
})
|
|
196
183
|
|
|
@@ -221,18 +208,9 @@ describe('EVM Family', () => {
|
|
|
221
208
|
it('should return interger values when API return floats', async () => {
|
|
222
209
|
mockedNetwork.mockReset()
|
|
223
210
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
low: '1.5',
|
|
228
|
-
medium: '2.4',
|
|
229
|
-
high: '3.7',
|
|
230
|
-
next_base: '3.8',
|
|
231
|
-
},
|
|
232
|
-
})
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
mockedNetwork.mockReturnValueOnce(gastrackerBarometerMock)
|
|
211
|
+
mockedNetwork.mockReturnValueOnce(
|
|
212
|
+
makeNetworkResponse({ low: '1.5', medium: '2.4', high: '3.7', next_base: '3.8' })
|
|
213
|
+
)
|
|
236
214
|
|
|
237
215
|
const gasOptions: GasOptions = await getGasOptions({
|
|
238
216
|
currencyId: 'ethereum',
|
|
@@ -252,7 +230,7 @@ describe('EVM Family', () => {
|
|
|
252
230
|
it('should use overrideGasTracker', async () => {
|
|
253
231
|
await getGasOptions({
|
|
254
232
|
currencyId: 'ethereum',
|
|
255
|
-
config: {
|
|
233
|
+
config: createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
|
|
256
234
|
options: {
|
|
257
235
|
useEIP1559: false,
|
|
258
236
|
overrideGasTracker: { type: 'ledger', explorerId: 'eth_sepolia' },
|
|
@@ -270,7 +248,7 @@ describe('EVM Family', () => {
|
|
|
270
248
|
try {
|
|
271
249
|
await getGasOptions({
|
|
272
250
|
currencyId: 'ethereum',
|
|
273
|
-
config: {
|
|
251
|
+
config: createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
|
|
274
252
|
})
|
|
275
253
|
fail('Promise should have been rejected')
|
|
276
254
|
} catch (e) {
|
|
@@ -285,7 +263,11 @@ describe('EVM Family', () => {
|
|
|
285
263
|
try {
|
|
286
264
|
await getGasOptions({
|
|
287
265
|
currencyId: 'ethereum',
|
|
288
|
-
config: {
|
|
266
|
+
config: createMockEvmConfigInfo({
|
|
267
|
+
chainId: 1,
|
|
268
|
+
node: mkExternalNode(),
|
|
269
|
+
gasTracker: mkLedgerGasTracker({ explorerId: 'anything' }),
|
|
270
|
+
}),
|
|
289
271
|
})
|
|
290
272
|
fail('Promise should have been rejected')
|
|
291
273
|
} catch (e) {
|
|
@@ -1,57 +1,51 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { createMockEvmConfigInfo, mkExternalNode } from '../../fixtures/context.fixtures'
|
|
5
5
|
import { getNodeApi } from './index'
|
|
6
6
|
|
|
7
|
-
const externalNodeConfig = (): EvmConfigInfo =>
|
|
8
|
-
({ node: { type: 'external', uri: 'working' } }) as unknown as EvmConfigInfo
|
|
9
|
-
|
|
10
7
|
describe('getNodeApi memoization', () => {
|
|
11
8
|
it('should return the same NodeApi instance for same currency and retries (memoization)', () => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
expect(node1).toBe(node2)
|
|
9
|
+
const config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
10
|
+
expect(getNodeApi(config, 'ethereum')).toBe(getNodeApi(config, 'ethereum'))
|
|
16
11
|
})
|
|
17
12
|
|
|
18
13
|
it('should return cached NodeApi on subsequent calls (createNodeApi called once)', () => {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const third = getNodeApi(externalNodeConfig(), 'cached_value_test')
|
|
14
|
+
const config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
15
|
+
const cachedInstance = getNodeApi(config, 'cached_value_test')
|
|
22
16
|
|
|
23
|
-
expect(
|
|
24
|
-
expect(
|
|
17
|
+
expect(getNodeApi(config, 'cached_value_test')).toBe(cachedInstance)
|
|
18
|
+
expect(getNodeApi(config, 'cached_value_test')).toBe(cachedInstance)
|
|
25
19
|
})
|
|
26
20
|
|
|
27
|
-
function generateConfig(node: { type: string; uri: string; retries: number }): EvmConfigInfo {
|
|
28
|
-
return { node } as unknown as EvmConfigInfo
|
|
29
|
-
}
|
|
30
21
|
it('should return different NodeApi instances for different retries', () => {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const node2 = getNodeApi(
|
|
22
|
+
const node1 = getNodeApi(
|
|
23
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'u', retries: 2 }) }),
|
|
24
|
+
'ethereum'
|
|
25
|
+
)
|
|
26
|
+
const node2 = getNodeApi(
|
|
27
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'u', retries: 5 }) }),
|
|
28
|
+
'ethereum'
|
|
29
|
+
)
|
|
36
30
|
expect(node1).not.toBe(node2)
|
|
37
31
|
})
|
|
38
32
|
|
|
39
33
|
it('should return different NodeApi instances for different uris', () => {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const node2 = getNodeApi(
|
|
34
|
+
const node1 = getNodeApi(
|
|
35
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'u1' }) }),
|
|
36
|
+
'ethereum'
|
|
37
|
+
)
|
|
38
|
+
const node2 = getNodeApi(
|
|
39
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'u2' }) }),
|
|
40
|
+
'ethereum'
|
|
41
|
+
)
|
|
45
42
|
|
|
46
43
|
expect(node1).not.toBe(node2)
|
|
47
44
|
})
|
|
48
45
|
|
|
49
46
|
it('should return different NodeApi instances for different currencies', () => {
|
|
50
|
-
const conf =
|
|
51
|
-
|
|
52
|
-
const node1 = getNodeApi(conf, 'ethereum1')
|
|
53
|
-
const node2 = getNodeApi(conf, 'ethereum2')
|
|
47
|
+
const conf = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'u1' }) })
|
|
54
48
|
|
|
55
|
-
expect(
|
|
49
|
+
expect(getNodeApi(conf, 'ethereum1')).not.toBe(getNodeApi(conf, 'ethereum2'))
|
|
56
50
|
})
|
|
57
51
|
})
|
|
@@ -1,36 +1,27 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { AssertionError, fail } from 'assert'
|
|
5
4
|
import { UnknownNode } from '../../errors'
|
|
5
|
+
import {
|
|
6
|
+
createMockEvmConfigInfo,
|
|
7
|
+
mkExternalNode,
|
|
8
|
+
mkLedgerNode,
|
|
9
|
+
} from '../../fixtures/context.fixtures'
|
|
6
10
|
import { getNodeApi } from './index'
|
|
7
11
|
|
|
8
12
|
describe('EVM Family', () => {
|
|
9
13
|
describe('network/node/index.ts', () => {
|
|
10
14
|
describe('getNodeApi', () => {
|
|
11
|
-
it('should throw when requesting a non existing node type',
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
node: { type: 'anything', uri: 'notworking' },
|
|
16
|
-
} as any,
|
|
17
|
-
{ id: 'not-existing' } as any
|
|
18
|
-
)
|
|
19
|
-
fail('Promise should have been rejected')
|
|
20
|
-
} catch (e) {
|
|
21
|
-
if (e instanceof AssertionError) {
|
|
22
|
-
throw e
|
|
23
|
-
}
|
|
24
|
-
expect(e).toBeInstanceOf(UnknownNode)
|
|
25
|
-
}
|
|
15
|
+
it('should throw when requesting a non existing node type', () => {
|
|
16
|
+
const config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
17
|
+
Object.assign(config, { node: { type: 'anything', uri: 'notworking' } })
|
|
18
|
+
expect(() => getNodeApi(config, 'not-existing')).toThrow(UnknownNode)
|
|
26
19
|
})
|
|
27
20
|
|
|
28
|
-
it('should return the rpc api',
|
|
21
|
+
it('should return the rpc api', () => {
|
|
29
22
|
const node = getNodeApi(
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
} as any,
|
|
33
|
-
{ id: 'external' } as any
|
|
23
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'working' }) }),
|
|
24
|
+
'external'
|
|
34
25
|
)
|
|
35
26
|
|
|
36
27
|
expect(node).toEqual(
|
|
@@ -50,10 +41,8 @@ describe('EVM Family', () => {
|
|
|
50
41
|
|
|
51
42
|
it('should return the ledger api', () => {
|
|
52
43
|
const node = getNodeApi(
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
} as any,
|
|
56
|
-
{ id: 'ledger-supported' } as any
|
|
44
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkLedgerNode({ explorerId: 'eth' }) }),
|
|
45
|
+
'ledger-supported'
|
|
57
46
|
)
|
|
58
47
|
|
|
59
48
|
expect(node).toEqual(
|