@ledgerhq/coin-evm 5.3.3 → 5.3.6
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 +1 -1
- package/CHANGELOG.md +18 -0
- package/lib/config.d.ts +4 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/errors.d.ts +6 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +12 -1
- package/lib/errors.js.map +1 -1
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js +15 -19
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js +6 -4
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/withRetries.d.ts.map +1 -1
- package/lib/network/withRetries.js +13 -0
- package/lib/network/withRetries.js.map +1 -1
- package/lib/utils.d.ts +0 -2
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +0 -30
- package/lib/utils.js.map +1 -1
- package/lib-es/config.d.ts +4 -0
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/errors.d.ts +6 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +10 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js +16 -20
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js +7 -5
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/withRetries.d.ts.map +1 -1
- package/lib-es/network/withRetries.js +10 -0
- package/lib-es/network/withRetries.js.map +1 -1
- package/lib-es/utils.d.ts +0 -2
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +0 -28
- package/lib-es/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/api/index.integ.test.ts +0 -8
- package/src/api/index.zksync.integ.test.ts +38 -0
- package/src/config.ts +4 -0
- package/src/errors.ts +10 -0
- package/src/logic.test.ts +47 -62
- package/src/network/explorer/etherscan.test.ts +160 -134
- package/src/network/explorer/etherscan.ts +37 -27
- package/src/network/explorer/ledger.test.ts +60 -53
- package/src/network/explorer/ledger.ts +27 -22
- package/src/network/gasTracker/ledger.test.ts +18 -48
- package/src/network/node/rpc.test.ts +76 -66
- package/src/network/withRetries.test.ts +63 -0
- package/src/network/withRetries.ts +12 -0
- package/src/utils.test.ts +0 -86
- package/src/utils.ts +0 -41
- package/src/api/index.fantom.integ.test.ts +0 -103
|
@@ -28,10 +28,10 @@ import {
|
|
|
28
28
|
import {
|
|
29
29
|
EtherscanAPIError,
|
|
30
30
|
EtherscanLikeExplorerUsedIncorrectly,
|
|
31
|
+
RateLimitError,
|
|
31
32
|
InvalidExplorerResponse,
|
|
32
33
|
} from '../../errors'
|
|
33
34
|
import { enrichRewardOperationsValue } from '../../staking/rewardsFromReceipt'
|
|
34
|
-
import { nftDisabled } from '../../utils'
|
|
35
35
|
import { withApi } from '../node/rpc.common'
|
|
36
36
|
import { isExternalNodeConfig } from '../node/types'
|
|
37
37
|
import { isEtherscanLikeExplorerConfig } from './types'
|
|
@@ -119,6 +119,9 @@ export async function fetchWithRetries<T>(
|
|
|
119
119
|
|
|
120
120
|
return data.result
|
|
121
121
|
} catch (e) {
|
|
122
|
+
if (axios.isAxiosError(e) && e.response?.status === 429) {
|
|
123
|
+
throw new RateLimitError()
|
|
124
|
+
}
|
|
122
125
|
if (retries) {
|
|
123
126
|
// wait the API timeout before trying again
|
|
124
127
|
await delay(ETHERSCAN_TIMEOUT)
|
|
@@ -277,11 +280,10 @@ export const getCoinOperations = async (params: FetchOperationsParams): Promise<
|
|
|
277
280
|
? `${explorer.uri}/accounts/list_of_txs_by_address/${params.address}`
|
|
278
281
|
: `${explorer.uri}?module=account&action=txlist&address=${params.address}`
|
|
279
282
|
|
|
280
|
-
const raw = await fetchWithRetries<EtherscanOperation[] | null | string>(
|
|
281
|
-
method: 'GET',
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
})
|
|
283
|
+
const raw = await fetchWithRetries<EtherscanOperation[] | null | string>(
|
|
284
|
+
{ method: 'GET', url, params: paginationParams(params) },
|
|
285
|
+
explorer.retries ?? DEFAULT_RETRIES_API
|
|
286
|
+
)
|
|
285
287
|
const ops = Array.isArray(raw) ? raw : []
|
|
286
288
|
|
|
287
289
|
const operations = ops.flatMap((tx) =>
|
|
@@ -306,6 +308,9 @@ export const getCoinOperations = async (params: FetchOperationsParams): Promise<
|
|
|
306
308
|
node
|
|
307
309
|
)
|
|
308
310
|
} catch (e) {
|
|
311
|
+
// Enrichment is best-effort, but a rate limit must not be downgraded into a successful
|
|
312
|
+
// response reporting 0-value rewards.
|
|
313
|
+
if (e instanceof RateLimitError) throw e
|
|
309
314
|
log('EVM getOperations', 'reward amount enrichment failed', e)
|
|
310
315
|
}
|
|
311
316
|
}
|
|
@@ -337,11 +342,10 @@ export const getTokenOperations = async (
|
|
|
337
342
|
? `${explorer.uri}/accounts/list_of_erc20_transfer_events_by_address/${params.address}`
|
|
338
343
|
: `${explorer.uri}?module=account&action=tokentx&address=${params.address}`
|
|
339
344
|
|
|
340
|
-
const raw = await fetchWithRetries<EtherscanERC20Event[] | null | string>(
|
|
341
|
-
method: 'GET',
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
})
|
|
345
|
+
const raw = await fetchWithRetries<EtherscanERC20Event[] | null | string>(
|
|
346
|
+
{ method: 'GET', url, params: paginationParams(params) },
|
|
347
|
+
explorer.retries ?? DEFAULT_RETRIES_API
|
|
348
|
+
)
|
|
345
349
|
const ops = Array.isArray(raw) ? raw : []
|
|
346
350
|
|
|
347
351
|
// Drop ERC20 Transfer events on contracts that mirror the native asset
|
|
@@ -392,11 +396,10 @@ export const getERC721Operations = async (
|
|
|
392
396
|
? `${explorer.uri}/accounts/list_of_erc721_transfer_events_by_address/${params.address}`
|
|
393
397
|
: `${explorer.uri}?module=account&action=tokennfttx&address=${params.address}`
|
|
394
398
|
|
|
395
|
-
const raw = await fetchWithRetries<EtherscanERC721Event[] | null | string>(
|
|
396
|
-
method: 'GET',
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
})
|
|
399
|
+
const raw = await fetchWithRetries<EtherscanERC721Event[] | null | string>(
|
|
400
|
+
{ method: 'GET', url, params: paginationParams(params) },
|
|
401
|
+
explorer.retries ?? DEFAULT_RETRIES_API
|
|
402
|
+
)
|
|
400
403
|
const ops = Array.isArray(raw) ? raw : []
|
|
401
404
|
|
|
402
405
|
// Why this thing ?
|
|
@@ -440,11 +443,14 @@ export const getERC1155Operations = async (
|
|
|
440
443
|
return EMPTY_RESULT
|
|
441
444
|
}
|
|
442
445
|
|
|
443
|
-
const raw = await fetchWithRetries<EtherscanERC1155Event[] | null | string>(
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
446
|
+
const raw = await fetchWithRetries<EtherscanERC1155Event[] | null | string>(
|
|
447
|
+
{
|
|
448
|
+
method: 'GET',
|
|
449
|
+
url: `${explorer.uri}?module=account&action=token1155tx&address=${params.address}`,
|
|
450
|
+
params: paginationParams(params),
|
|
451
|
+
},
|
|
452
|
+
explorer.retries ?? DEFAULT_RETRIES_API
|
|
453
|
+
)
|
|
448
454
|
const ops = Array.isArray(raw) ? raw : []
|
|
449
455
|
|
|
450
456
|
// Why this thing ?
|
|
@@ -529,11 +535,14 @@ export const getInternalOperations = async (
|
|
|
529
535
|
}
|
|
530
536
|
|
|
531
537
|
// Some explorers (e.g. Monad Testnet) return null instead of [] for empty results.
|
|
532
|
-
const ops = await fetchWithRetries<EtherscanInternalTransaction[] | null>(
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
538
|
+
const ops = await fetchWithRetries<EtherscanInternalTransaction[] | null>(
|
|
539
|
+
{
|
|
540
|
+
method: 'GET',
|
|
541
|
+
url: `${explorer.uri}?module=account&action=txlistinternal&address=${params.address}`,
|
|
542
|
+
params: paginationParams(params),
|
|
543
|
+
},
|
|
544
|
+
explorer.retries ?? DEFAULT_RETRIES_API
|
|
545
|
+
).then((ops) => (ops ?? []).map(fixTxHash))
|
|
537
546
|
|
|
538
547
|
// Why this thing ?
|
|
539
548
|
// Multiple internal transactions can be executed from
|
|
@@ -814,7 +823,7 @@ export const getOperations = makeLRUCache<
|
|
|
814
823
|
const nfts = await callEndpoint(
|
|
815
824
|
getNftOperations,
|
|
816
825
|
tokens.effectiveBoundBlock,
|
|
817
|
-
nftUnsupported ||
|
|
826
|
+
nftUnsupported || pagingState?.nftIsDone
|
|
818
827
|
)
|
|
819
828
|
|
|
820
829
|
const effectiveBoundBlock = nfts.effectiveBoundBlock
|
|
@@ -852,6 +861,7 @@ export const getOperations = makeLRUCache<
|
|
|
852
861
|
}),
|
|
853
862
|
}
|
|
854
863
|
} catch (err) {
|
|
864
|
+
if (err instanceof RateLimitError) throw err
|
|
855
865
|
log('EVM getOperations', 'Error while fetching data from Etherscan like API', err)
|
|
856
866
|
const message =
|
|
857
867
|
typeof err === 'string'
|
|
@@ -7,7 +7,12 @@ import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
|
7
7
|
import axios from 'axios'
|
|
8
8
|
import eip55 from 'eip55'
|
|
9
9
|
import { DEFAULT_LEDGER_EXPLORER_URI, getCoinConfig } from '../../config'
|
|
10
|
-
import { LedgerExplorerUsedIncorrectly } from '../../errors'
|
|
10
|
+
import { LedgerExplorerUsedIncorrectly, RateLimitError } from '../../errors'
|
|
11
|
+
import {
|
|
12
|
+
createMockEvmCoinConfig,
|
|
13
|
+
mkExternalNode,
|
|
14
|
+
mkLedgerNode,
|
|
15
|
+
} from '../../fixtures/context.fixtures'
|
|
11
16
|
import {
|
|
12
17
|
coinOperation1,
|
|
13
18
|
coinOperation2,
|
|
@@ -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(() => {
|
|
@@ -92,6 +94,29 @@ describe('EVM Family', () => {
|
|
|
92
94
|
}
|
|
93
95
|
})
|
|
94
96
|
|
|
97
|
+
it('should surface a 429 as a RateLimitError without retrying', async () => {
|
|
98
|
+
const rateLimitError = Object.assign(new Error('Request failed with status code 429'), {
|
|
99
|
+
isAxiosError: true,
|
|
100
|
+
response: { status: 429 },
|
|
101
|
+
})
|
|
102
|
+
// axios is fully mocked - restore isAxiosError to its real behaviour for this test
|
|
103
|
+
jest
|
|
104
|
+
.spyOn(axios, 'isAxiosError')
|
|
105
|
+
.mockImplementation(
|
|
106
|
+
(e: unknown): boolean => typeof e === 'object' && e !== null && 'isAxiosError' in e
|
|
107
|
+
)
|
|
108
|
+
const spy = jest.spyOn(axios, 'request').mockRejectedValue(rateLimitError)
|
|
109
|
+
|
|
110
|
+
await expect(
|
|
111
|
+
LEDGER_API.fetchPaginatedOpsWithRetries(
|
|
112
|
+
{ explorerId: 'test', address: '0x', fromBlock: 0, batchSize: 10 },
|
|
113
|
+
null
|
|
114
|
+
)
|
|
115
|
+
).rejects.toBeInstanceOf(RateLimitError)
|
|
116
|
+
// a rate limit is not transient: it must not consume the retry budget
|
|
117
|
+
expect(spy).toHaveBeenCalledTimes(1)
|
|
118
|
+
})
|
|
119
|
+
|
|
95
120
|
it('should recursively fetch paginated data', async () => {
|
|
96
121
|
jest.spyOn(axios, 'request').mockImplementation(async ({ params }) => {
|
|
97
122
|
switch (params.token) {
|
|
@@ -174,21 +199,10 @@ describe('EVM Family', () => {
|
|
|
174
199
|
})
|
|
175
200
|
|
|
176
201
|
describe('getOperations', () => {
|
|
177
|
-
beforeEach(() => {
|
|
178
|
-
process.env.NFT_CURRENCIES = JSON.stringify([])
|
|
179
|
-
})
|
|
180
|
-
|
|
181
202
|
it('should throw if the explorer is misconfigured', async () => {
|
|
182
|
-
mockGetConfig.mockImplementationOnce(()
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
node: {
|
|
186
|
-
type: 'wrongtype',
|
|
187
|
-
uri: 'anything',
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
}
|
|
191
|
-
})
|
|
203
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
204
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'anything' }) })
|
|
205
|
+
)
|
|
192
206
|
|
|
193
207
|
try {
|
|
194
208
|
await LEDGER_API.getOperations(
|
|
@@ -237,8 +251,6 @@ describe('EVM Family', () => {
|
|
|
237
251
|
})
|
|
238
252
|
|
|
239
253
|
it('should return the different operation types', async () => {
|
|
240
|
-
process.env.NFT_CURRENCIES = JSON.stringify(['ethereum'])
|
|
241
|
-
|
|
242
254
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
243
255
|
data: { data: [coinOperation1, coinOperation2, coinOperation3, coinOperation4] },
|
|
244
256
|
}))
|
|
@@ -448,16 +460,13 @@ describe('EVM Family', () => {
|
|
|
448
460
|
|
|
449
461
|
describe('getOperations without nft', () => {
|
|
450
462
|
beforeEach(() => {
|
|
451
|
-
mockGetConfig.mockImplementation(()
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
},
|
|
459
|
-
}
|
|
460
|
-
})
|
|
463
|
+
mockGetConfig.mockImplementation(() =>
|
|
464
|
+
createMockEvmCoinConfig({
|
|
465
|
+
chainId: 1,
|
|
466
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
467
|
+
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
468
|
+
})
|
|
469
|
+
)
|
|
461
470
|
})
|
|
462
471
|
|
|
463
472
|
it('should not return NFT opperation', async () => {
|
|
@@ -482,21 +491,17 @@ describe('EVM Family', () => {
|
|
|
482
491
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
483
492
|
data: { data: [coinOperation1, coinOperation2, coinOperation3, coinOperation4] },
|
|
484
493
|
}))
|
|
485
|
-
|
|
486
|
-
process.env.NFT_CURRENCIES = JSON.stringify(['ethereum'])
|
|
487
|
-
})
|
|
488
|
-
|
|
489
|
-
afterAll(() => {
|
|
490
|
-
process.env.NFT_CURRENCIES = JSON.stringify([])
|
|
491
494
|
})
|
|
492
495
|
|
|
493
496
|
const mockConfigWithTokens = (supportedTokens: NftStandard[]) =>
|
|
494
|
-
mockGetConfig.mockImplementation(()
|
|
495
|
-
|
|
497
|
+
mockGetConfig.mockImplementation(() =>
|
|
498
|
+
createMockEvmCoinConfig({
|
|
499
|
+
chainId: 1,
|
|
500
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
496
501
|
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
497
502
|
supportedTokens,
|
|
498
|
-
}
|
|
499
|
-
|
|
503
|
+
})
|
|
504
|
+
)
|
|
500
505
|
|
|
501
506
|
const fetchNftAssetTypes = async () => {
|
|
502
507
|
const response = await LEDGER_API.getOperations(
|
|
@@ -536,14 +541,16 @@ describe('EVM Family', () => {
|
|
|
536
541
|
// coinOperation1.transfer_events[0].contract — the only ERC20 event in the fixtures.
|
|
537
542
|
const FIXTURE_CONTRACT = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
|
|
538
543
|
|
|
539
|
-
const withConfig = (info:
|
|
540
|
-
mockGetConfig.mockImplementation(()
|
|
541
|
-
|
|
544
|
+
const withConfig = (info: { nativeContracts?: string[] }) =>
|
|
545
|
+
mockGetConfig.mockImplementation(() =>
|
|
546
|
+
createMockEvmCoinConfig({
|
|
547
|
+
chainId: 1,
|
|
548
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
542
549
|
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
543
550
|
supportedTokens: ['erc721', 'erc1155'],
|
|
544
551
|
...info,
|
|
545
|
-
}
|
|
546
|
-
|
|
552
|
+
})
|
|
553
|
+
)
|
|
547
554
|
|
|
548
555
|
it('drops ERC20 transfer events whose contract is listed in nativeContracts', async () => {
|
|
549
556
|
withConfig({ nativeContracts: [FIXTURE_CONTRACT] })
|
|
@@ -14,8 +14,7 @@ import {
|
|
|
14
14
|
ledgerOperationToOperations,
|
|
15
15
|
} from '../../adapters/index'
|
|
16
16
|
import { DEFAULT_LEDGER_EXPLORER_URI } from '../../config'
|
|
17
|
-
import { LedgerExplorerUsedIncorrectly } from '../../errors'
|
|
18
|
-
import { nftEnabled } from '../../utils'
|
|
17
|
+
import { LedgerExplorerUsedIncorrectly, RateLimitError } from '../../errors'
|
|
19
18
|
import { isLedgerExplorerConfig, NO_TOKEN } from './types'
|
|
20
19
|
|
|
21
20
|
export const DEFAULT_BATCH_SIZE = 10_000
|
|
@@ -75,6 +74,9 @@ export async function fetchPaginatedOpsWithRetries(
|
|
|
75
74
|
(a, b) => new Date(b.block.time).getTime() - new Date(a.block.time).getTime()
|
|
76
75
|
)
|
|
77
76
|
} catch (e) {
|
|
77
|
+
if (axios.isAxiosError(e) && e.response?.status === 429) {
|
|
78
|
+
throw new RateLimitError()
|
|
79
|
+
}
|
|
78
80
|
if (retries) {
|
|
79
81
|
// wait the API timeout before trying again
|
|
80
82
|
await delay(LEDGER_TIMEOUT)
|
|
@@ -105,14 +107,19 @@ export const getOperations: ExplorerApi['getOperations'] = async (
|
|
|
105
107
|
)
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
const ledgerExplorerOps = await fetchPaginatedOpsWithRetries(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
const ledgerExplorerOps = await fetchPaginatedOpsWithRetries(
|
|
111
|
+
{
|
|
112
|
+
explorerUri: config.ledgerExplorerUri,
|
|
113
|
+
clientVersion: config.ledgerClientVersion,
|
|
114
|
+
explorerId: explorer.explorerId,
|
|
115
|
+
address,
|
|
116
|
+
fromBlock,
|
|
117
|
+
batchSize: explorer.batchSize ?? DEFAULT_BATCH_SIZE,
|
|
118
|
+
},
|
|
119
|
+
null,
|
|
120
|
+
[],
|
|
121
|
+
explorer.retries ?? DEFAULT_RETRIES_API
|
|
122
|
+
)
|
|
116
123
|
|
|
117
124
|
const lastCoinOperations: Array<Operation<MemoNotSupported>> = []
|
|
118
125
|
const lastTokenOperations: Array<Operation<MemoNotSupported>> = []
|
|
@@ -135,18 +142,16 @@ export const getOperations: ExplorerApi['getOperations'] = async (
|
|
|
135
142
|
const erc20Ops = erc20TransferEvents.flatMap((event, index) =>
|
|
136
143
|
ledgerERC20EventToOperations(address, coinOps[0], event, index)
|
|
137
144
|
)
|
|
138
|
-
const erc721Ops =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
)
|
|
149
|
-
: []
|
|
145
|
+
const erc721Ops = config.supportedTokens?.includes('erc721')
|
|
146
|
+
? ledgerOp.erc721_transfer_events.flatMap((event, index) =>
|
|
147
|
+
ledgerERC721EventToOperations(address, coinOps[0], event, index)
|
|
148
|
+
)
|
|
149
|
+
: []
|
|
150
|
+
const erc1155Ops = config.supportedTokens?.includes('erc1155')
|
|
151
|
+
? ledgerOp.erc1155_transfer_events.flatMap((event, index) =>
|
|
152
|
+
ledgerERC1155EventToOperations(address, coinOps[0], event, index)
|
|
153
|
+
)
|
|
154
|
+
: []
|
|
150
155
|
const internalOps = ledgerOp.actions.flatMap((action, index) =>
|
|
151
156
|
ledgerInternalTransactionToOperations(address, coinOps[0], action, index)
|
|
152
157
|
)
|
|
@@ -4,7 +4,13 @@
|
|
|
4
4
|
import type { GasOptions } from '../../types'
|
|
5
5
|
import { AssertionError } from 'assert'
|
|
6
6
|
import network from '@ledgerhq/live-network/network'
|
|
7
|
+
import { AxiosHeaders } from 'axios'
|
|
7
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
|
+
}
|
|
8
14
|
import { LedgerGasTrackerUsedIncorrectly, NoGasTrackerFound } from '../../errors'
|
|
9
15
|
import {
|
|
10
16
|
createMockEvmConfigInfo,
|
|
@@ -27,18 +33,9 @@ const ledgerGasTrackerConfig = createMockEvmConfigInfo({
|
|
|
27
33
|
describe('EVM Family', () => {
|
|
28
34
|
describe('network/gasTracker/index.ts', () => {
|
|
29
35
|
beforeEach(() => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
low: '1',
|
|
34
|
-
medium: '2',
|
|
35
|
-
high: '3',
|
|
36
|
-
next_base: '4',
|
|
37
|
-
},
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
mockedNetwork.mockReturnValueOnce(gastrackerBarometerMock)
|
|
36
|
+
mockedNetwork.mockReturnValueOnce(
|
|
37
|
+
makeNetworkResponse({ low: '1', medium: '2', high: '3', next_base: '4' })
|
|
38
|
+
)
|
|
42
39
|
})
|
|
43
40
|
|
|
44
41
|
describe('ledger', () => {
|
|
@@ -79,18 +76,9 @@ describe('EVM Family', () => {
|
|
|
79
76
|
it('should return integer values when eip1559BaseFeeMultiplier is a float', async () => {
|
|
80
77
|
mockedNetwork.mockReset()
|
|
81
78
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
low: '1',
|
|
86
|
-
medium: '2',
|
|
87
|
-
high: '3',
|
|
88
|
-
next_base: '3',
|
|
89
|
-
},
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
mockedNetwork.mockReturnValueOnce(gastrackerBarometerMock)
|
|
79
|
+
mockedNetwork.mockReturnValueOnce(
|
|
80
|
+
makeNetworkResponse({ low: '1', medium: '2', high: '3', next_base: '3' })
|
|
81
|
+
)
|
|
94
82
|
|
|
95
83
|
const gasOptions: GasOptions = await getGasOptions({
|
|
96
84
|
currencyId: 'ethereum',
|
|
@@ -110,18 +98,9 @@ describe('EVM Family', () => {
|
|
|
110
98
|
it('should return interger values when API return floats', async () => {
|
|
111
99
|
mockedNetwork.mockReset()
|
|
112
100
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
low: '1.5',
|
|
117
|
-
medium: '2.4',
|
|
118
|
-
high: '3.7',
|
|
119
|
-
next_base: '3.8',
|
|
120
|
-
},
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
mockedNetwork.mockReturnValueOnce(gastrackerBarometerMock)
|
|
101
|
+
mockedNetwork.mockReturnValueOnce(
|
|
102
|
+
makeNetworkResponse({ low: '1.5', medium: '2.4', high: '3.7', next_base: '3.8' })
|
|
103
|
+
)
|
|
125
104
|
|
|
126
105
|
const gasOptions: GasOptions = await getGasOptions({
|
|
127
106
|
currencyId: 'ethereum',
|
|
@@ -229,18 +208,9 @@ describe('EVM Family', () => {
|
|
|
229
208
|
it('should return interger values when API return floats', async () => {
|
|
230
209
|
mockedNetwork.mockReset()
|
|
231
210
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
low: '1.5',
|
|
236
|
-
medium: '2.4',
|
|
237
|
-
high: '3.7',
|
|
238
|
-
next_base: '3.8',
|
|
239
|
-
},
|
|
240
|
-
})
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
mockedNetwork.mockReturnValueOnce(gastrackerBarometerMock)
|
|
211
|
+
mockedNetwork.mockReturnValueOnce(
|
|
212
|
+
makeNetworkResponse({ low: '1.5', medium: '2.4', high: '3.7', next_base: '3.8' })
|
|
213
|
+
)
|
|
244
214
|
|
|
245
215
|
const gasOptions: GasOptions = await getGasOptions({
|
|
246
216
|
currencyId: 'ethereum',
|