@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
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { createMockEvmContext, mkExternalNode } from '../fixtures/context.fixtures'
|
|
5
|
+
import { createApi } from './index'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Non regression for GET /v1/zksync/account/{address}/operations?minHeight=0&order=asc&limit=1,
|
|
9
|
+
* which was timing out because 429 responses from the blockscout upstream were silently
|
|
10
|
+
* retried until the request timed out.
|
|
11
|
+
*
|
|
12
|
+
* `limit` must be passed: listOperations forces the explorer order to `desc` when it is
|
|
13
|
+
* undefined, so omitting it would query a different code path than the reported one.
|
|
14
|
+
*/
|
|
15
|
+
describe('ZkSync (blockscout explorer)', () => {
|
|
16
|
+
const ADDRESS = '0x060afdc8d583e134eebb50826695632f041c5153'
|
|
17
|
+
|
|
18
|
+
let module: ReturnType<typeof createApi>
|
|
19
|
+
|
|
20
|
+
beforeAll(() => {
|
|
21
|
+
module = createApi('zksync')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('listOperations completes without timing out', async () => {
|
|
25
|
+
const { items } = await module.listOperations(
|
|
26
|
+
createMockEvmContext({
|
|
27
|
+
chainId: 324,
|
|
28
|
+
node: mkExternalNode({ uri: 'https://mainnet.era.zksync.io', retries: 0 }),
|
|
29
|
+
explorer: { type: 'blockscout', uri: 'https://zksync.blockscout.com/api', retries: 0 },
|
|
30
|
+
}),
|
|
31
|
+
ADDRESS,
|
|
32
|
+
{ minHeight: 0, order: 'asc', limit: 1 }
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
expect(Array.isArray(items)).toBe(true)
|
|
36
|
+
expect(items.length).toBeLessThanOrEqual(1)
|
|
37
|
+
})
|
|
38
|
+
})
|
package/src/config.ts
CHANGED
|
@@ -52,11 +52,15 @@ export type EvmConfig = {
|
|
|
52
52
|
*/
|
|
53
53
|
maxLimit?: number | undefined
|
|
54
54
|
uri: string
|
|
55
|
+
/** Number of retries for explorer API calls. Defaults to 8 if not set. Set to 0 for no retries. */
|
|
56
|
+
retries?: number
|
|
55
57
|
}
|
|
56
58
|
| {
|
|
57
59
|
type: 'ledger'
|
|
58
60
|
explorerId: string
|
|
59
61
|
batchSize?: number | undefined
|
|
62
|
+
/** Number of retries for explorer API calls. Defaults to 2 if not set. Set to 0 for no retries. */
|
|
63
|
+
retries?: number
|
|
60
64
|
}
|
|
61
65
|
| {
|
|
62
66
|
type: 'none'
|
package/src/errors.ts
CHANGED
|
@@ -44,6 +44,16 @@ export class InvalidExplorerResponse extends Error {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/** Rate limit error (HTTP 429) from an upstream API — explorer or RPC node. */
|
|
48
|
+
export class RateLimitError extends Error {
|
|
49
|
+
override name = 'RateLimitError'
|
|
50
|
+
readonly statusCode = 429
|
|
51
|
+
constructor(message?: string, fields?: Record<string, unknown>) {
|
|
52
|
+
super(message || 'Upstream rate limit exceeded (429), please retry later')
|
|
53
|
+
if (fields) Object.assign(this, fields)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
47
57
|
// Node
|
|
48
58
|
export class UnknownNode extends Error {
|
|
49
59
|
override name = 'UnknownNode'
|
package/src/logic.test.ts
CHANGED
|
@@ -9,7 +9,12 @@ jest.mock('./network/node/index', () => ({
|
|
|
9
9
|
}))
|
|
10
10
|
|
|
11
11
|
import { getCoinConfig } from './config'
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
createMockEvmCoinConfig,
|
|
14
|
+
createMockEvmConfigInfo,
|
|
15
|
+
mkExternalNode,
|
|
16
|
+
mkLedgerNode,
|
|
17
|
+
} from './fixtures/context.fixtures'
|
|
13
18
|
import { getAdditionalLayer2Fees } from './logic'
|
|
14
19
|
import { getNodeApi } from './network/node/index'
|
|
15
20
|
import { mockNodeApi } from './network/node/node.fixtures'
|
|
@@ -25,68 +30,48 @@ const {
|
|
|
25
30
|
jest.mock('./config')
|
|
26
31
|
const mockGetConfig = jest.mocked(getCoinConfig)
|
|
27
32
|
|
|
28
|
-
mockGetConfig.mockImplementation((currencyId
|
|
33
|
+
mockGetConfig.mockImplementation((currencyId) => {
|
|
29
34
|
switch (currencyId) {
|
|
30
|
-
case 'ethereum':
|
|
31
|
-
return {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
node: { type: 'ledger', explorerId: 'bsc' },
|
|
71
|
-
},
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
case 'anything': {
|
|
75
|
-
return {
|
|
76
|
-
info: {
|
|
77
|
-
node: { type: 'external', explorerId: 'anything' },
|
|
78
|
-
explorer: { type: 'etherscan', uri: 'anything' },
|
|
79
|
-
},
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
case 'somethingelse': {
|
|
83
|
-
return {
|
|
84
|
-
info: {
|
|
85
|
-
node: { type: 'ledger', explorerId: 'somethingelse' },
|
|
86
|
-
explorer: { type: 'blockscout', uri: 'somethingelse' },
|
|
87
|
-
},
|
|
88
|
-
}
|
|
89
|
-
}
|
|
35
|
+
case 'ethereum':
|
|
36
|
+
return createMockEvmCoinConfig({
|
|
37
|
+
chainId: 1,
|
|
38
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
39
|
+
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
40
|
+
})
|
|
41
|
+
case 'matic':
|
|
42
|
+
return createMockEvmCoinConfig({
|
|
43
|
+
chainId: 137,
|
|
44
|
+
node: mkLedgerNode({ explorerId: 'matic' }),
|
|
45
|
+
explorer: { type: 'ledger', explorerId: 'matic' },
|
|
46
|
+
})
|
|
47
|
+
case 'optimism':
|
|
48
|
+
return createMockEvmCoinConfig({ chainId: 10, node: mkExternalNode({ uri: 'optimism_uri' }) })
|
|
49
|
+
case 'scroll':
|
|
50
|
+
return createMockEvmCoinConfig({
|
|
51
|
+
chainId: 534352,
|
|
52
|
+
node: mkExternalNode({ uri: 'scroll_uri' }),
|
|
53
|
+
})
|
|
54
|
+
case 'polygon':
|
|
55
|
+
return createMockEvmCoinConfig({
|
|
56
|
+
chainId: 137,
|
|
57
|
+
node: mkLedgerNode({ explorerId: 'polygon' }),
|
|
58
|
+
})
|
|
59
|
+
case 'bsc':
|
|
60
|
+
return createMockEvmCoinConfig({ chainId: 56, node: mkLedgerNode({ explorerId: 'bsc' }) })
|
|
61
|
+
case 'anything':
|
|
62
|
+
return createMockEvmCoinConfig({
|
|
63
|
+
chainId: 1,
|
|
64
|
+
node: mkExternalNode({ uri: 'anything' }),
|
|
65
|
+
explorer: { type: 'etherscan', uri: 'anything' },
|
|
66
|
+
})
|
|
67
|
+
case 'somethingelse':
|
|
68
|
+
return createMockEvmCoinConfig({
|
|
69
|
+
chainId: 1,
|
|
70
|
+
node: mkLedgerNode({ explorerId: 'somethingelse' }),
|
|
71
|
+
explorer: { type: 'blockscout', uri: 'somethingelse' },
|
|
72
|
+
})
|
|
73
|
+
default:
|
|
74
|
+
throw new Error(`unexpected currencyId: ${currencyId}`)
|
|
90
75
|
}
|
|
91
76
|
})
|
|
92
77
|
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { PagingState } from '../../adapters'
|
|
5
|
+
import type { NftStandard } from '../../config'
|
|
5
6
|
import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
7
|
+
import type { AxiosRequestConfig } from 'axios'
|
|
6
8
|
import { AssertionError, fail } from 'assert'
|
|
7
9
|
import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
8
10
|
import axios from 'axios'
|
|
@@ -16,7 +18,12 @@ import {
|
|
|
16
18
|
serializePagingToken,
|
|
17
19
|
} from '../../adapters'
|
|
18
20
|
import { getCoinConfig } from '../../config'
|
|
19
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
EtherscanAPIError,
|
|
23
|
+
EtherscanLikeExplorerUsedIncorrectly,
|
|
24
|
+
RateLimitError,
|
|
25
|
+
} from '../../errors'
|
|
26
|
+
import { createMockEvmCoinConfig, mkExternalNode } from '../../fixtures/context.fixtures'
|
|
20
27
|
import {
|
|
21
28
|
etherscanCoinOperations,
|
|
22
29
|
etherscanERC1155Operations,
|
|
@@ -66,21 +73,14 @@ const paginationState = (result: ETHERSCAN_API.EndpointResult) => ({
|
|
|
66
73
|
|
|
67
74
|
describe('EVM Family', () => {
|
|
68
75
|
beforeEach(() => {
|
|
69
|
-
mockGetConfig.mockImplementation(()
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
type: 'external',
|
|
78
|
-
uri: 'mock',
|
|
79
|
-
},
|
|
80
|
-
supportedTokens: ['erc721', 'erc1155'],
|
|
81
|
-
},
|
|
82
|
-
}
|
|
83
|
-
})
|
|
76
|
+
mockGetConfig.mockImplementation(() =>
|
|
77
|
+
createMockEvmCoinConfig({
|
|
78
|
+
chainId: 1,
|
|
79
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
80
|
+
explorer: { type: 'etherscan', uri: 'mock' },
|
|
81
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
afterAll(() => {
|
|
@@ -145,6 +145,33 @@ describe('EVM Family', () => {
|
|
|
145
145
|
// it should fail 2 times and succeed on the next try
|
|
146
146
|
expect(spy).toHaveBeenCalledTimes(3)
|
|
147
147
|
})
|
|
148
|
+
|
|
149
|
+
it('should surface a 429 HTTP response as RateLimitError without retrying', async () => {
|
|
150
|
+
const rateLimitError = Object.assign(new Error('Request failed with status code 429'), {
|
|
151
|
+
isAxiosError: true,
|
|
152
|
+
response: { status: 429 },
|
|
153
|
+
})
|
|
154
|
+
// axios is fully mocked — restore isAxiosError to its real behaviour for this test
|
|
155
|
+
jest
|
|
156
|
+
.spyOn(axios, 'isAxiosError')
|
|
157
|
+
.mockImplementation(
|
|
158
|
+
(e: unknown): boolean => typeof e === 'object' && e !== null && 'isAxiosError' in e
|
|
159
|
+
)
|
|
160
|
+
const spy = jest.spyOn(axios, 'request').mockRejectedValue(rateLimitError)
|
|
161
|
+
|
|
162
|
+
await expect(
|
|
163
|
+
ETHERSCAN_API.fetchWithRetries({}, ETHERSCAN_API.DEFAULT_RETRIES_API)
|
|
164
|
+
).rejects.toBeInstanceOf(RateLimitError)
|
|
165
|
+
// must not retry — a rate-limit error is not transient
|
|
166
|
+
expect(spy).toHaveBeenCalledTimes(1)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('should respect retries: 0 from explorer config and not retry on failure', async () => {
|
|
170
|
+
const spy = jest.spyOn(axios, 'request').mockRejectedValue(new Error('upstream error'))
|
|
171
|
+
|
|
172
|
+
await expect(ETHERSCAN_API.fetchWithRetries({}, 0)).rejects.toThrow('upstream error')
|
|
173
|
+
expect(spy).toHaveBeenCalledTimes(1)
|
|
174
|
+
})
|
|
148
175
|
})
|
|
149
176
|
|
|
150
177
|
describe.each([
|
|
@@ -188,17 +215,9 @@ describe('EVM Family', () => {
|
|
|
188
215
|
})
|
|
189
216
|
|
|
190
217
|
it('should throw an error if the currency is misconfigured', async () => {
|
|
191
|
-
mockGetConfig.mockImplementationOnce(()
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
info: {
|
|
195
|
-
node: {
|
|
196
|
-
type: 'external',
|
|
197
|
-
uri: 'mock',
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
}
|
|
201
|
-
})
|
|
218
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
219
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
220
|
+
)
|
|
202
221
|
|
|
203
222
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
204
223
|
data: {
|
|
@@ -413,17 +432,9 @@ describe('EVM Family', () => {
|
|
|
413
432
|
})
|
|
414
433
|
|
|
415
434
|
it('should throw if the currency is misconfigured', async () => {
|
|
416
|
-
mockGetConfig.mockImplementationOnce(()
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
info: {
|
|
420
|
-
node: {
|
|
421
|
-
type: 'external',
|
|
422
|
-
uri: 'mock',
|
|
423
|
-
},
|
|
424
|
-
},
|
|
425
|
-
}
|
|
426
|
-
})
|
|
435
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
436
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
437
|
+
)
|
|
427
438
|
|
|
428
439
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
429
440
|
data: {
|
|
@@ -644,15 +655,16 @@ describe('EVM Family', () => {
|
|
|
644
655
|
// The contract used by all entries in etherscanTokenOperations.
|
|
645
656
|
const FIXTURE_CONTRACT = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
|
|
646
657
|
|
|
647
|
-
const withConfig = (info:
|
|
648
|
-
mockGetConfig.mockImplementation(()
|
|
649
|
-
|
|
658
|
+
const withConfig = (info: { nativeContracts?: string[] }) =>
|
|
659
|
+
mockGetConfig.mockImplementation(() =>
|
|
660
|
+
createMockEvmCoinConfig({
|
|
661
|
+
chainId: 1,
|
|
662
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
650
663
|
explorer: { type: 'etherscan', uri: 'mock' },
|
|
651
|
-
node: { type: 'external', uri: 'mock' },
|
|
652
664
|
supportedTokens: ['erc721', 'erc1155'],
|
|
653
665
|
...info,
|
|
654
|
-
}
|
|
655
|
-
|
|
666
|
+
})
|
|
667
|
+
)
|
|
656
668
|
|
|
657
669
|
it('drops ERC20 ops whose contract is listed in nativeContracts', async () => {
|
|
658
670
|
withConfig({ nativeContracts: [FIXTURE_CONTRACT] })
|
|
@@ -731,17 +743,9 @@ describe('EVM Family', () => {
|
|
|
731
743
|
})
|
|
732
744
|
|
|
733
745
|
it('should return an empty array if the currency is misconfigured', async () => {
|
|
734
|
-
mockGetConfig.mockImplementationOnce(()
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
info: {
|
|
738
|
-
node: {
|
|
739
|
-
type: 'external',
|
|
740
|
-
uri: 'mock',
|
|
741
|
-
},
|
|
742
|
-
},
|
|
743
|
-
}
|
|
744
|
-
})
|
|
746
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
747
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
748
|
+
)
|
|
745
749
|
|
|
746
750
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
747
751
|
data: {
|
|
@@ -963,17 +967,9 @@ describe('EVM Family', () => {
|
|
|
963
967
|
})
|
|
964
968
|
|
|
965
969
|
it('should return an empty array if the currency is misconfigured', async () => {
|
|
966
|
-
mockGetConfig.mockImplementationOnce(()
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
info: {
|
|
970
|
-
node: {
|
|
971
|
-
type: 'external',
|
|
972
|
-
uri: 'mock',
|
|
973
|
-
},
|
|
974
|
-
},
|
|
975
|
-
}
|
|
976
|
-
})
|
|
970
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
971
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
972
|
+
)
|
|
977
973
|
|
|
978
974
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
979
975
|
data: {
|
|
@@ -1328,17 +1324,9 @@ describe('EVM Family', () => {
|
|
|
1328
1324
|
})
|
|
1329
1325
|
|
|
1330
1326
|
it('should throw if the currency is misconfigured', async () => {
|
|
1331
|
-
mockGetConfig.mockImplementationOnce(()
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
info: {
|
|
1335
|
-
node: {
|
|
1336
|
-
type: 'external',
|
|
1337
|
-
uri: 'mock',
|
|
1338
|
-
},
|
|
1339
|
-
},
|
|
1340
|
-
}
|
|
1341
|
-
})
|
|
1327
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
1328
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
1329
|
+
)
|
|
1342
1330
|
|
|
1343
1331
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
1344
1332
|
data: {
|
|
@@ -1625,13 +1613,14 @@ describe('EVM Family', () => {
|
|
|
1625
1613
|
]
|
|
1626
1614
|
|
|
1627
1615
|
it('calls etherscan API with correct URL and params for etherscan explorer type', async () => {
|
|
1628
|
-
mockGetConfig.mockImplementation(()
|
|
1629
|
-
|
|
1616
|
+
mockGetConfig.mockImplementation(() =>
|
|
1617
|
+
createMockEvmCoinConfig({
|
|
1618
|
+
chainId: 1,
|
|
1619
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1630
1620
|
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1631
|
-
node: { type: 'external', uri: 'mock' },
|
|
1632
1621
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1622
|
+
})
|
|
1623
|
+
)
|
|
1635
1624
|
const axiosSpy = jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1636
1625
|
data: { status: '1', message: 'OK', result: internalTxResult },
|
|
1637
1626
|
})
|
|
@@ -1659,13 +1648,14 @@ describe('EVM Family', () => {
|
|
|
1659
1648
|
})
|
|
1660
1649
|
|
|
1661
1650
|
it('calls API with correct params for blockscout explorer type', async () => {
|
|
1662
|
-
mockGetConfig.mockImplementation(()
|
|
1663
|
-
|
|
1651
|
+
mockGetConfig.mockImplementation(() =>
|
|
1652
|
+
createMockEvmCoinConfig({
|
|
1653
|
+
chainId: 1,
|
|
1654
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1664
1655
|
explorer: { type: 'blockscout', uri: 'https://blockscout.com/api' },
|
|
1665
|
-
node: { type: 'external', uri: 'mock' },
|
|
1666
1656
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1657
|
+
})
|
|
1658
|
+
)
|
|
1669
1659
|
const axiosSpy = jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1670
1660
|
data: { status: '1', message: 'OK', result: internalTxResult },
|
|
1671
1661
|
})
|
|
@@ -1693,13 +1683,14 @@ describe('EVM Family', () => {
|
|
|
1693
1683
|
['ledger', { type: 'ledger', explorerId: 'eth' }],
|
|
1694
1684
|
['none', { type: 'none' }],
|
|
1695
1685
|
] as const)('returns empty array for %s explorer type', async (_, explorer) => {
|
|
1696
|
-
mockGetConfig.mockImplementation(()
|
|
1697
|
-
|
|
1686
|
+
mockGetConfig.mockImplementation(() =>
|
|
1687
|
+
createMockEvmCoinConfig({
|
|
1688
|
+
chainId: 1,
|
|
1689
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1698
1690
|
explorer,
|
|
1699
|
-
node: { type: 'external', uri: 'mock' },
|
|
1700
1691
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1692
|
+
})
|
|
1693
|
+
)
|
|
1703
1694
|
|
|
1704
1695
|
const result = await ETHERSCAN_API.getInternalTransactionsByBlock(
|
|
1705
1696
|
getCoinConfig(currencyId).info,
|
|
@@ -1711,13 +1702,14 @@ describe('EVM Family', () => {
|
|
|
1711
1702
|
})
|
|
1712
1703
|
|
|
1713
1704
|
it('returns empty array when API returns non-array result', async () => {
|
|
1714
|
-
mockGetConfig.mockImplementation(()
|
|
1715
|
-
|
|
1705
|
+
mockGetConfig.mockImplementation(() =>
|
|
1706
|
+
createMockEvmCoinConfig({
|
|
1707
|
+
chainId: 1,
|
|
1708
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1716
1709
|
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1717
|
-
node: { type: 'external', uri: 'mock' },
|
|
1718
1710
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1711
|
+
})
|
|
1712
|
+
)
|
|
1721
1713
|
jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1722
1714
|
data: { status: '1', message: 'OK', result: 'No transactions found' },
|
|
1723
1715
|
})
|
|
@@ -1731,13 +1723,14 @@ describe('EVM Family', () => {
|
|
|
1731
1723
|
})
|
|
1732
1724
|
|
|
1733
1725
|
it('throws when API returns blockscout-style no internal transactions response', async () => {
|
|
1734
|
-
mockGetConfig.mockImplementation(()
|
|
1735
|
-
|
|
1726
|
+
mockGetConfig.mockImplementation(() =>
|
|
1727
|
+
createMockEvmCoinConfig({
|
|
1728
|
+
chainId: 1,
|
|
1729
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1736
1730
|
explorer: { type: 'blockscout', uri: 'https://blockscout.com/api' },
|
|
1737
|
-
node: { type: 'external', uri: 'mock' },
|
|
1738
1731
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1732
|
+
})
|
|
1733
|
+
)
|
|
1741
1734
|
jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1742
1735
|
data: {
|
|
1743
1736
|
status: '0',
|
|
@@ -1752,13 +1745,14 @@ describe('EVM Family', () => {
|
|
|
1752
1745
|
})
|
|
1753
1746
|
|
|
1754
1747
|
it('loops over pagination until all internal txs are drained', async () => {
|
|
1755
|
-
mockGetConfig.mockImplementation(()
|
|
1756
|
-
|
|
1748
|
+
mockGetConfig.mockImplementation(() =>
|
|
1749
|
+
createMockEvmCoinConfig({
|
|
1750
|
+
chainId: 1,
|
|
1751
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1757
1752
|
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1758
|
-
node: { type: 'external', uri: 'mock' },
|
|
1759
1753
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1754
|
+
})
|
|
1755
|
+
)
|
|
1762
1756
|
|
|
1763
1757
|
const PAGE_SIZE = 10000
|
|
1764
1758
|
const fullPage = Array.from({ length: PAGE_SIZE }, (_, i) => ({
|
|
@@ -1807,13 +1801,14 @@ describe('EVM Family', () => {
|
|
|
1807
1801
|
})
|
|
1808
1802
|
|
|
1809
1803
|
it('propagates errors from explorer API call', async () => {
|
|
1810
|
-
mockGetConfig.mockImplementation(()
|
|
1811
|
-
|
|
1804
|
+
mockGetConfig.mockImplementation(() =>
|
|
1805
|
+
createMockEvmCoinConfig({
|
|
1806
|
+
chainId: 1,
|
|
1807
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1812
1808
|
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1813
|
-
node: { type: 'external', uri: 'mock' },
|
|
1814
1809
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1810
|
+
})
|
|
1811
|
+
)
|
|
1817
1812
|
jest.mocked(axios.request).mockReset()
|
|
1818
1813
|
jest.mocked(axios.request).mockRejectedValue(new Error('network error'))
|
|
1819
1814
|
|
|
@@ -1825,20 +1820,13 @@ describe('EVM Family', () => {
|
|
|
1825
1820
|
|
|
1826
1821
|
describe('getNftOperations without nft', () => {
|
|
1827
1822
|
beforeEach(() => {
|
|
1828
|
-
mockGetConfig.mockImplementation(()
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
node: {
|
|
1836
|
-
type: 'external',
|
|
1837
|
-
uri: 'mock',
|
|
1838
|
-
},
|
|
1839
|
-
},
|
|
1840
|
-
}
|
|
1841
|
-
})
|
|
1823
|
+
mockGetConfig.mockImplementation(() =>
|
|
1824
|
+
createMockEvmCoinConfig({
|
|
1825
|
+
chainId: 1,
|
|
1826
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1827
|
+
explorer: { type: 'etherscan', uri: 'mock' },
|
|
1828
|
+
})
|
|
1829
|
+
)
|
|
1842
1830
|
})
|
|
1843
1831
|
|
|
1844
1832
|
it('should not return NFT operation', async () => {
|
|
@@ -1859,14 +1847,15 @@ describe('EVM Family', () => {
|
|
|
1859
1847
|
})
|
|
1860
1848
|
|
|
1861
1849
|
describe('getNftOperations supportedTokens atomicity', () => {
|
|
1862
|
-
const withSupportedTokens = (supportedTokens:
|
|
1863
|
-
mockGetConfig.mockImplementation(()
|
|
1864
|
-
|
|
1850
|
+
const withSupportedTokens = (supportedTokens: NftStandard[]) => {
|
|
1851
|
+
mockGetConfig.mockImplementation(() =>
|
|
1852
|
+
createMockEvmCoinConfig({
|
|
1853
|
+
chainId: 1,
|
|
1854
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1865
1855
|
explorer: { type: 'etherscan', uri: 'mock' },
|
|
1866
|
-
node: { type: 'external', uri: 'mock' },
|
|
1867
1856
|
supportedTokens,
|
|
1868
|
-
}
|
|
1869
|
-
|
|
1857
|
+
})
|
|
1858
|
+
)
|
|
1870
1859
|
}
|
|
1871
1860
|
|
|
1872
1861
|
// ERC721 ops are fetched from the `tokennfttx` endpoint, ERC1155 ops from `token1155tx`.
|
|
@@ -1931,6 +1920,7 @@ describe('EVM Family', () => {
|
|
|
1931
1920
|
// only non-NFT standards (e.g. a future "erc20") must NOT activate NFT fetching. Activation is
|
|
1932
1921
|
// driven by explicit NFT-standard membership, not by the array being non-empty.
|
|
1933
1922
|
it('does not activate NFTs for a non-NFT standard such as erc20', async () => {
|
|
1923
|
+
// @ts-expect-error intentionally testing runtime behavior with an unsupported token standard
|
|
1934
1924
|
withSupportedTokens(['erc20'])
|
|
1935
1925
|
const { assetTypes, fetchedErc721, fetchedErc1155 } = await fetchNfts()
|
|
1936
1926
|
expect(assetTypes).toEqual(new Set())
|
|
@@ -1944,6 +1934,42 @@ describe('EVM Family', () => {
|
|
|
1944
1934
|
jest.clearAllMocks()
|
|
1945
1935
|
})
|
|
1946
1936
|
|
|
1937
|
+
// getOperations wraps everything its outer catch sees into InvalidExplorerResponse. A rate
|
|
1938
|
+
// limit must escape that wrapping, otherwise the caller loses the 429 status.
|
|
1939
|
+
it('propagates a RateLimitError instead of wrapping it in InvalidExplorerResponse', async () => {
|
|
1940
|
+
mockGetConfig.mockImplementation(() =>
|
|
1941
|
+
createMockEvmCoinConfig({
|
|
1942
|
+
chainId: 1,
|
|
1943
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1944
|
+
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io', retries: 0 },
|
|
1945
|
+
})
|
|
1946
|
+
)
|
|
1947
|
+
const rateLimitError = Object.assign(new Error('Request failed with status code 429'), {
|
|
1948
|
+
isAxiosError: true,
|
|
1949
|
+
response: { status: 429 },
|
|
1950
|
+
})
|
|
1951
|
+
// axios is fully mocked - restore isAxiosError to its real behaviour for this test
|
|
1952
|
+
jest
|
|
1953
|
+
.spyOn(axios, 'isAxiosError')
|
|
1954
|
+
.mockImplementation(
|
|
1955
|
+
(e: unknown): boolean => typeof e === 'object' && e !== null && 'isAxiosError' in e
|
|
1956
|
+
)
|
|
1957
|
+
jest.spyOn(axios, 'request').mockRejectedValue(rateLimitError)
|
|
1958
|
+
|
|
1959
|
+
await expect(
|
|
1960
|
+
ETHERSCAN_API.getOperations.force(
|
|
1961
|
+
getCoinConfig(currencyId).info,
|
|
1962
|
+
currencyId,
|
|
1963
|
+
address,
|
|
1964
|
+
0,
|
|
1965
|
+
undefined,
|
|
1966
|
+
undefined,
|
|
1967
|
+
1,
|
|
1968
|
+
'asc'
|
|
1969
|
+
)
|
|
1970
|
+
).rejects.toBeInstanceOf(RateLimitError)
|
|
1971
|
+
})
|
|
1972
|
+
|
|
1947
1973
|
// Helpers to create mock Etherscan responses with specific block heights for each operation type
|
|
1948
1974
|
const createMockCoinTxResponse = (blockNumbers: number[]) =>
|
|
1949
1975
|
blockNumbers.map((blockNumber, i) => ({
|
|
@@ -2004,8 +2030,8 @@ describe('EVM Family', () => {
|
|
|
2004
2030
|
const createBlockchainMock = (allOps: BlockchainOp[], limit: number, order: 'asc' | 'desc') => {
|
|
2005
2031
|
const pageCounts: Record<string, number> = {}
|
|
2006
2032
|
|
|
2007
|
-
return async (config:
|
|
2008
|
-
const url: string = config.url
|
|
2033
|
+
return async (config: AxiosRequestConfig) => {
|
|
2034
|
+
const url: string = config.url ?? ''
|
|
2009
2035
|
const params = config.params
|
|
2010
2036
|
const startBlock = params.startblock ?? 0
|
|
2011
2037
|
const endBlock = params.endblock ?? Infinity
|