@ledgerhq/coin-evm 5.3.3 → 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 +1 -1
- package/CHANGELOG.md +6 -0
- package/package.json +2 -2
- package/src/logic.test.ts +47 -62
- package/src/network/explorer/etherscan.test.ts +92 -133
- package/src/network/explorer/ledger.test.ts +36 -40
- package/src/network/gasTracker/ledger.test.ts +18 -48
- package/src/network/node/rpc.test.ts +76 -66
- package/src/api/index.fantom.integ.test.ts +0 -103
package/.oxlintrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @ledgerhq/coin-evm
|
|
2
2
|
|
|
3
|
+
## 5.3.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#902](https://github.com/LedgerHQ/coin-modules/pull/902) [`b4e0f42`](https://github.com/LedgerHQ/coin-modules/commit/b4e0f42febb9ce3b4f170a8facdeae1ec5052513) Thanks [@jnicoulaud-ledger](https://github.com/jnicoulaud-ledger)! - chore: drop fantom network (shut down)
|
|
8
|
+
|
|
3
9
|
## 5.3.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-evm",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.4",
|
|
4
4
|
"description": "Ledger EVM Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"eip55": "^2.1.1",
|
|
52
52
|
"ethers": "6.15.0",
|
|
53
53
|
"react-native-get-random-values": "^1.8.0",
|
|
54
|
-
"@ledgerhq/coin-module-framework": "^9.
|
|
54
|
+
"@ledgerhq/coin-module-framework": "^9.1.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@ledgerhq/live-network": "^3.0.0",
|
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'
|
|
@@ -17,6 +19,7 @@ import {
|
|
|
17
19
|
} from '../../adapters'
|
|
18
20
|
import { getCoinConfig } from '../../config'
|
|
19
21
|
import { EtherscanAPIError, EtherscanLikeExplorerUsedIncorrectly } from '../../errors'
|
|
22
|
+
import { createMockEvmCoinConfig, mkExternalNode } from '../../fixtures/context.fixtures'
|
|
20
23
|
import {
|
|
21
24
|
etherscanCoinOperations,
|
|
22
25
|
etherscanERC1155Operations,
|
|
@@ -66,21 +69,14 @@ const paginationState = (result: ETHERSCAN_API.EndpointResult) => ({
|
|
|
66
69
|
|
|
67
70
|
describe('EVM Family', () => {
|
|
68
71
|
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
|
-
})
|
|
72
|
+
mockGetConfig.mockImplementation(() =>
|
|
73
|
+
createMockEvmCoinConfig({
|
|
74
|
+
chainId: 1,
|
|
75
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
76
|
+
explorer: { type: 'etherscan', uri: 'mock' },
|
|
77
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
78
|
+
})
|
|
79
|
+
)
|
|
84
80
|
})
|
|
85
81
|
|
|
86
82
|
afterAll(() => {
|
|
@@ -188,17 +184,9 @@ describe('EVM Family', () => {
|
|
|
188
184
|
})
|
|
189
185
|
|
|
190
186
|
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
|
-
})
|
|
187
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
188
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
189
|
+
)
|
|
202
190
|
|
|
203
191
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
204
192
|
data: {
|
|
@@ -413,17 +401,9 @@ describe('EVM Family', () => {
|
|
|
413
401
|
})
|
|
414
402
|
|
|
415
403
|
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
|
-
})
|
|
404
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
405
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
406
|
+
)
|
|
427
407
|
|
|
428
408
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
429
409
|
data: {
|
|
@@ -644,15 +624,16 @@ describe('EVM Family', () => {
|
|
|
644
624
|
// The contract used by all entries in etherscanTokenOperations.
|
|
645
625
|
const FIXTURE_CONTRACT = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
|
|
646
626
|
|
|
647
|
-
const withConfig = (info:
|
|
648
|
-
mockGetConfig.mockImplementation(()
|
|
649
|
-
|
|
627
|
+
const withConfig = (info: { nativeContracts?: string[] }) =>
|
|
628
|
+
mockGetConfig.mockImplementation(() =>
|
|
629
|
+
createMockEvmCoinConfig({
|
|
630
|
+
chainId: 1,
|
|
631
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
650
632
|
explorer: { type: 'etherscan', uri: 'mock' },
|
|
651
|
-
node: { type: 'external', uri: 'mock' },
|
|
652
633
|
supportedTokens: ['erc721', 'erc1155'],
|
|
653
634
|
...info,
|
|
654
|
-
}
|
|
655
|
-
|
|
635
|
+
})
|
|
636
|
+
)
|
|
656
637
|
|
|
657
638
|
it('drops ERC20 ops whose contract is listed in nativeContracts', async () => {
|
|
658
639
|
withConfig({ nativeContracts: [FIXTURE_CONTRACT] })
|
|
@@ -731,17 +712,9 @@ describe('EVM Family', () => {
|
|
|
731
712
|
})
|
|
732
713
|
|
|
733
714
|
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
|
-
})
|
|
715
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
716
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
717
|
+
)
|
|
745
718
|
|
|
746
719
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
747
720
|
data: {
|
|
@@ -963,17 +936,9 @@ describe('EVM Family', () => {
|
|
|
963
936
|
})
|
|
964
937
|
|
|
965
938
|
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
|
-
})
|
|
939
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
940
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
941
|
+
)
|
|
977
942
|
|
|
978
943
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
979
944
|
data: {
|
|
@@ -1328,17 +1293,9 @@ describe('EVM Family', () => {
|
|
|
1328
1293
|
})
|
|
1329
1294
|
|
|
1330
1295
|
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
|
-
})
|
|
1296
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
1297
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
1298
|
+
)
|
|
1342
1299
|
|
|
1343
1300
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
1344
1301
|
data: {
|
|
@@ -1625,13 +1582,14 @@ describe('EVM Family', () => {
|
|
|
1625
1582
|
]
|
|
1626
1583
|
|
|
1627
1584
|
it('calls etherscan API with correct URL and params for etherscan explorer type', async () => {
|
|
1628
|
-
mockGetConfig.mockImplementation(()
|
|
1629
|
-
|
|
1585
|
+
mockGetConfig.mockImplementation(() =>
|
|
1586
|
+
createMockEvmCoinConfig({
|
|
1587
|
+
chainId: 1,
|
|
1588
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1630
1589
|
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1631
|
-
node: { type: 'external', uri: 'mock' },
|
|
1632
1590
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1591
|
+
})
|
|
1592
|
+
)
|
|
1635
1593
|
const axiosSpy = jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1636
1594
|
data: { status: '1', message: 'OK', result: internalTxResult },
|
|
1637
1595
|
})
|
|
@@ -1659,13 +1617,14 @@ describe('EVM Family', () => {
|
|
|
1659
1617
|
})
|
|
1660
1618
|
|
|
1661
1619
|
it('calls API with correct params for blockscout explorer type', async () => {
|
|
1662
|
-
mockGetConfig.mockImplementation(()
|
|
1663
|
-
|
|
1620
|
+
mockGetConfig.mockImplementation(() =>
|
|
1621
|
+
createMockEvmCoinConfig({
|
|
1622
|
+
chainId: 1,
|
|
1623
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1664
1624
|
explorer: { type: 'blockscout', uri: 'https://blockscout.com/api' },
|
|
1665
|
-
node: { type: 'external', uri: 'mock' },
|
|
1666
1625
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1626
|
+
})
|
|
1627
|
+
)
|
|
1669
1628
|
const axiosSpy = jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1670
1629
|
data: { status: '1', message: 'OK', result: internalTxResult },
|
|
1671
1630
|
})
|
|
@@ -1693,13 +1652,14 @@ describe('EVM Family', () => {
|
|
|
1693
1652
|
['ledger', { type: 'ledger', explorerId: 'eth' }],
|
|
1694
1653
|
['none', { type: 'none' }],
|
|
1695
1654
|
] as const)('returns empty array for %s explorer type', async (_, explorer) => {
|
|
1696
|
-
mockGetConfig.mockImplementation(()
|
|
1697
|
-
|
|
1655
|
+
mockGetConfig.mockImplementation(() =>
|
|
1656
|
+
createMockEvmCoinConfig({
|
|
1657
|
+
chainId: 1,
|
|
1658
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1698
1659
|
explorer,
|
|
1699
|
-
node: { type: 'external', uri: 'mock' },
|
|
1700
1660
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1661
|
+
})
|
|
1662
|
+
)
|
|
1703
1663
|
|
|
1704
1664
|
const result = await ETHERSCAN_API.getInternalTransactionsByBlock(
|
|
1705
1665
|
getCoinConfig(currencyId).info,
|
|
@@ -1711,13 +1671,14 @@ describe('EVM Family', () => {
|
|
|
1711
1671
|
})
|
|
1712
1672
|
|
|
1713
1673
|
it('returns empty array when API returns non-array result', async () => {
|
|
1714
|
-
mockGetConfig.mockImplementation(()
|
|
1715
|
-
|
|
1674
|
+
mockGetConfig.mockImplementation(() =>
|
|
1675
|
+
createMockEvmCoinConfig({
|
|
1676
|
+
chainId: 1,
|
|
1677
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1716
1678
|
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1717
|
-
node: { type: 'external', uri: 'mock' },
|
|
1718
1679
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1680
|
+
})
|
|
1681
|
+
)
|
|
1721
1682
|
jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1722
1683
|
data: { status: '1', message: 'OK', result: 'No transactions found' },
|
|
1723
1684
|
})
|
|
@@ -1731,13 +1692,14 @@ describe('EVM Family', () => {
|
|
|
1731
1692
|
})
|
|
1732
1693
|
|
|
1733
1694
|
it('throws when API returns blockscout-style no internal transactions response', async () => {
|
|
1734
|
-
mockGetConfig.mockImplementation(()
|
|
1735
|
-
|
|
1695
|
+
mockGetConfig.mockImplementation(() =>
|
|
1696
|
+
createMockEvmCoinConfig({
|
|
1697
|
+
chainId: 1,
|
|
1698
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1736
1699
|
explorer: { type: 'blockscout', uri: 'https://blockscout.com/api' },
|
|
1737
|
-
node: { type: 'external', uri: 'mock' },
|
|
1738
1700
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1701
|
+
})
|
|
1702
|
+
)
|
|
1741
1703
|
jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1742
1704
|
data: {
|
|
1743
1705
|
status: '0',
|
|
@@ -1752,13 +1714,14 @@ describe('EVM Family', () => {
|
|
|
1752
1714
|
})
|
|
1753
1715
|
|
|
1754
1716
|
it('loops over pagination until all internal txs are drained', async () => {
|
|
1755
|
-
mockGetConfig.mockImplementation(()
|
|
1756
|
-
|
|
1717
|
+
mockGetConfig.mockImplementation(() =>
|
|
1718
|
+
createMockEvmCoinConfig({
|
|
1719
|
+
chainId: 1,
|
|
1720
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1757
1721
|
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1758
|
-
node: { type: 'external', uri: 'mock' },
|
|
1759
1722
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1723
|
+
})
|
|
1724
|
+
)
|
|
1762
1725
|
|
|
1763
1726
|
const PAGE_SIZE = 10000
|
|
1764
1727
|
const fullPage = Array.from({ length: PAGE_SIZE }, (_, i) => ({
|
|
@@ -1807,13 +1770,14 @@ describe('EVM Family', () => {
|
|
|
1807
1770
|
})
|
|
1808
1771
|
|
|
1809
1772
|
it('propagates errors from explorer API call', async () => {
|
|
1810
|
-
mockGetConfig.mockImplementation(()
|
|
1811
|
-
|
|
1773
|
+
mockGetConfig.mockImplementation(() =>
|
|
1774
|
+
createMockEvmCoinConfig({
|
|
1775
|
+
chainId: 1,
|
|
1776
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1812
1777
|
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1813
|
-
node: { type: 'external', uri: 'mock' },
|
|
1814
1778
|
supportedTokens: ['erc721', 'erc1155'],
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1779
|
+
})
|
|
1780
|
+
)
|
|
1817
1781
|
jest.mocked(axios.request).mockReset()
|
|
1818
1782
|
jest.mocked(axios.request).mockRejectedValue(new Error('network error'))
|
|
1819
1783
|
|
|
@@ -1825,20 +1789,13 @@ describe('EVM Family', () => {
|
|
|
1825
1789
|
|
|
1826
1790
|
describe('getNftOperations without nft', () => {
|
|
1827
1791
|
beforeEach(() => {
|
|
1828
|
-
mockGetConfig.mockImplementation(()
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
node: {
|
|
1836
|
-
type: 'external',
|
|
1837
|
-
uri: 'mock',
|
|
1838
|
-
},
|
|
1839
|
-
},
|
|
1840
|
-
}
|
|
1841
|
-
})
|
|
1792
|
+
mockGetConfig.mockImplementation(() =>
|
|
1793
|
+
createMockEvmCoinConfig({
|
|
1794
|
+
chainId: 1,
|
|
1795
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1796
|
+
explorer: { type: 'etherscan', uri: 'mock' },
|
|
1797
|
+
})
|
|
1798
|
+
)
|
|
1842
1799
|
})
|
|
1843
1800
|
|
|
1844
1801
|
it('should not return NFT operation', async () => {
|
|
@@ -1859,14 +1816,15 @@ describe('EVM Family', () => {
|
|
|
1859
1816
|
})
|
|
1860
1817
|
|
|
1861
1818
|
describe('getNftOperations supportedTokens atomicity', () => {
|
|
1862
|
-
const withSupportedTokens = (supportedTokens:
|
|
1863
|
-
mockGetConfig.mockImplementation(()
|
|
1864
|
-
|
|
1819
|
+
const withSupportedTokens = (supportedTokens: NftStandard[]) => {
|
|
1820
|
+
mockGetConfig.mockImplementation(() =>
|
|
1821
|
+
createMockEvmCoinConfig({
|
|
1822
|
+
chainId: 1,
|
|
1823
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1865
1824
|
explorer: { type: 'etherscan', uri: 'mock' },
|
|
1866
|
-
node: { type: 'external', uri: 'mock' },
|
|
1867
1825
|
supportedTokens,
|
|
1868
|
-
}
|
|
1869
|
-
|
|
1826
|
+
})
|
|
1827
|
+
)
|
|
1870
1828
|
}
|
|
1871
1829
|
|
|
1872
1830
|
// ERC721 ops are fetched from the `tokennfttx` endpoint, ERC1155 ops from `token1155tx`.
|
|
@@ -1931,6 +1889,7 @@ describe('EVM Family', () => {
|
|
|
1931
1889
|
// only non-NFT standards (e.g. a future "erc20") must NOT activate NFT fetching. Activation is
|
|
1932
1890
|
// driven by explicit NFT-standard membership, not by the array being non-empty.
|
|
1933
1891
|
it('does not activate NFTs for a non-NFT standard such as erc20', async () => {
|
|
1892
|
+
// @ts-expect-error intentionally testing runtime behavior with an unsupported token standard
|
|
1934
1893
|
withSupportedTokens(['erc20'])
|
|
1935
1894
|
const { assetTypes, fetchedErc721, fetchedErc1155 } = await fetchNfts()
|
|
1936
1895
|
expect(assetTypes).toEqual(new Set())
|
|
@@ -2004,8 +1963,8 @@ describe('EVM Family', () => {
|
|
|
2004
1963
|
const createBlockchainMock = (allOps: BlockchainOp[], limit: number, order: 'asc' | 'desc') => {
|
|
2005
1964
|
const pageCounts: Record<string, number> = {}
|
|
2006
1965
|
|
|
2007
|
-
return async (config:
|
|
2008
|
-
const url: string = config.url
|
|
1966
|
+
return async (config: AxiosRequestConfig) => {
|
|
1967
|
+
const url: string = config.url ?? ''
|
|
2009
1968
|
const params = config.params
|
|
2010
1969
|
const startBlock = params.startblock ?? 0
|
|
2011
1970
|
const endBlock = params.endblock ?? Infinity
|
|
@@ -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,
|
|
@@ -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(() => {
|
|
@@ -179,16 +181,9 @@ describe('EVM Family', () => {
|
|
|
179
181
|
})
|
|
180
182
|
|
|
181
183
|
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
|
-
})
|
|
184
|
+
mockGetConfig.mockImplementationOnce(() =>
|
|
185
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'anything' }) })
|
|
186
|
+
)
|
|
192
187
|
|
|
193
188
|
try {
|
|
194
189
|
await LEDGER_API.getOperations(
|
|
@@ -448,16 +443,13 @@ describe('EVM Family', () => {
|
|
|
448
443
|
|
|
449
444
|
describe('getOperations without nft', () => {
|
|
450
445
|
beforeEach(() => {
|
|
451
|
-
mockGetConfig.mockImplementation(()
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
},
|
|
459
|
-
}
|
|
460
|
-
})
|
|
446
|
+
mockGetConfig.mockImplementation(() =>
|
|
447
|
+
createMockEvmCoinConfig({
|
|
448
|
+
chainId: 1,
|
|
449
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
450
|
+
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
451
|
+
})
|
|
452
|
+
)
|
|
461
453
|
})
|
|
462
454
|
|
|
463
455
|
it('should not return NFT opperation', async () => {
|
|
@@ -491,12 +483,14 @@ describe('EVM Family', () => {
|
|
|
491
483
|
})
|
|
492
484
|
|
|
493
485
|
const mockConfigWithTokens = (supportedTokens: NftStandard[]) =>
|
|
494
|
-
mockGetConfig.mockImplementation(()
|
|
495
|
-
|
|
486
|
+
mockGetConfig.mockImplementation(() =>
|
|
487
|
+
createMockEvmCoinConfig({
|
|
488
|
+
chainId: 1,
|
|
489
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
496
490
|
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
497
491
|
supportedTokens,
|
|
498
|
-
}
|
|
499
|
-
|
|
492
|
+
})
|
|
493
|
+
)
|
|
500
494
|
|
|
501
495
|
const fetchNftAssetTypes = async () => {
|
|
502
496
|
const response = await LEDGER_API.getOperations(
|
|
@@ -536,14 +530,16 @@ describe('EVM Family', () => {
|
|
|
536
530
|
// coinOperation1.transfer_events[0].contract — the only ERC20 event in the fixtures.
|
|
537
531
|
const FIXTURE_CONTRACT = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
|
|
538
532
|
|
|
539
|
-
const withConfig = (info:
|
|
540
|
-
mockGetConfig.mockImplementation(()
|
|
541
|
-
|
|
533
|
+
const withConfig = (info: { nativeContracts?: string[] }) =>
|
|
534
|
+
mockGetConfig.mockImplementation(() =>
|
|
535
|
+
createMockEvmCoinConfig({
|
|
536
|
+
chainId: 1,
|
|
537
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
542
538
|
explorer: { type: 'ledger', explorerId: 'eth' },
|
|
543
539
|
supportedTokens: ['erc721', 'erc1155'],
|
|
544
540
|
...info,
|
|
545
|
-
}
|
|
546
|
-
|
|
541
|
+
})
|
|
542
|
+
)
|
|
547
543
|
|
|
548
544
|
it('drops ERC20 transfer events whose contract is listed in nativeContracts', async () => {
|
|
549
545
|
withConfig({ nativeContracts: [FIXTURE_CONTRACT] })
|
|
@@ -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',
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { PerformActionRequest } from 'ethers'
|
|
4
5
|
import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
5
6
|
import BigNumber from 'bignumber.js'
|
|
6
7
|
import { FeeData, FetchRequest, JsonRpcProvider, Network, Transaction } from 'ethers'
|
|
7
8
|
import { getCoinConfig } from '../../config'
|
|
8
9
|
import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors'
|
|
9
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
createMockEvmCoinConfig,
|
|
12
|
+
createMockEvmConfigInfo,
|
|
13
|
+
mkExternalNode,
|
|
14
|
+
} from '../../fixtures/context.fixtures'
|
|
10
15
|
import {
|
|
11
16
|
mkBlock,
|
|
12
17
|
mkTransactionReceipt,
|
|
@@ -60,16 +65,9 @@ describe('EVM Family', () => {
|
|
|
60
65
|
jest.resetAllMocks()
|
|
61
66
|
jest.spyOn(JsonRpcProvider.prototype, '_detectNetwork').mockResolvedValue(Network.from(1))
|
|
62
67
|
|
|
63
|
-
mockGetConfig.mockImplementation(()
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
node: {
|
|
67
|
-
type: 'external',
|
|
68
|
-
uri: 'my-rpc.com',
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
}
|
|
72
|
-
})
|
|
68
|
+
mockGetConfig.mockImplementation(() =>
|
|
69
|
+
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'my-rpc.com' }) })
|
|
70
|
+
)
|
|
73
71
|
|
|
74
72
|
jest
|
|
75
73
|
.spyOn(JsonRpcProvider.prototype, 'getFeeData')
|
|
@@ -134,7 +132,7 @@ describe('EVM Family', () => {
|
|
|
134
132
|
|
|
135
133
|
jest
|
|
136
134
|
.spyOn(JsonRpcProvider.prototype, 'broadcastTransaction')
|
|
137
|
-
.mockImplementation(async (signedTx: string)
|
|
135
|
+
.mockImplementation(async (signedTx: string) => {
|
|
138
136
|
if (
|
|
139
137
|
signedTx ===
|
|
140
138
|
'0x02f873012d85010c388d0085077715912682520894c2907efcce4011c491bbeda8a0fa63ba7aab596c87038d7ea4c6800080c001a0bbffe7ba303ab03f697d64672c4a288ae863df8a62ffc67ba72872ce8c227f6fa01261e7c9f06af13631f03fad9b88d3c48931d353b6b41b4072fddcca5ec41628'
|
|
@@ -150,9 +148,9 @@ describe('EVM Family', () => {
|
|
|
150
148
|
throw new Error('any error')
|
|
151
149
|
}
|
|
152
150
|
|
|
153
|
-
return {
|
|
151
|
+
return mkTransactionResponse({
|
|
154
152
|
hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
|
|
155
|
-
}
|
|
153
|
+
})
|
|
156
154
|
})
|
|
157
155
|
})
|
|
158
156
|
|
|
@@ -688,12 +686,14 @@ describe('EVM Family', () => {
|
|
|
688
686
|
|
|
689
687
|
describe('getGasEstimation', () => {
|
|
690
688
|
it('should return the expected payload', async () => {
|
|
691
|
-
jest
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
689
|
+
jest
|
|
690
|
+
.spyOn(JsonRpcProvider.prototype, '_perform')
|
|
691
|
+
.mockImplementation(async (req: PerformActionRequest) => {
|
|
692
|
+
if (req.method === 'estimateGas') {
|
|
693
|
+
return 5n
|
|
694
|
+
}
|
|
695
|
+
return null
|
|
696
|
+
})
|
|
697
697
|
expect(
|
|
698
698
|
await nodeApi.getGasEstimation(currencyId, address, {
|
|
699
699
|
recipient: '0x0000000000000000000000000000000000000000',
|
|
@@ -704,12 +704,14 @@ describe('EVM Family', () => {
|
|
|
704
704
|
})
|
|
705
705
|
|
|
706
706
|
it('should throw a GasEstimationError in case of error', async () => {
|
|
707
|
-
jest
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
707
|
+
jest
|
|
708
|
+
.spyOn(JsonRpcProvider.prototype, '_perform')
|
|
709
|
+
.mockImplementation(async (req: PerformActionRequest) => {
|
|
710
|
+
if (req.method === 'estimateGas') {
|
|
711
|
+
throw new Error('fail')
|
|
712
|
+
}
|
|
713
|
+
return null
|
|
714
|
+
})
|
|
713
715
|
|
|
714
716
|
await expect(
|
|
715
717
|
nodeApi.getGasEstimation(currencyId, address, {
|
|
@@ -886,12 +888,13 @@ describe('EVM Family', () => {
|
|
|
886
888
|
])(
|
|
887
889
|
'forwards feeHistoryRewardPercentile %i to eth_feeHistory',
|
|
888
890
|
async (configured, expected) => {
|
|
889
|
-
mockGetConfig.mockImplementation(()
|
|
890
|
-
|
|
891
|
-
|
|
891
|
+
mockGetConfig.mockImplementation(() =>
|
|
892
|
+
createMockEvmCoinConfig({
|
|
893
|
+
chainId: 1,
|
|
894
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
892
895
|
feeHistoryRewardPercentile: configured,
|
|
893
|
-
}
|
|
894
|
-
|
|
896
|
+
})
|
|
897
|
+
)
|
|
895
898
|
const sendSpy = stubFeeHistory()
|
|
896
899
|
|
|
897
900
|
await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, eip1559Tx)
|
|
@@ -901,13 +904,14 @@ describe('EVM Family', () => {
|
|
|
901
904
|
)
|
|
902
905
|
|
|
903
906
|
it('combines feeHistoryBlockCount and feeHistoryRewardPercentile when both configured', async () => {
|
|
904
|
-
mockGetConfig.mockImplementation(()
|
|
905
|
-
|
|
906
|
-
|
|
907
|
+
mockGetConfig.mockImplementation(() =>
|
|
908
|
+
createMockEvmCoinConfig({
|
|
909
|
+
chainId: 1,
|
|
910
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
907
911
|
feeHistoryBlockCount: 20,
|
|
908
912
|
feeHistoryRewardPercentile: 75,
|
|
909
|
-
}
|
|
910
|
-
|
|
913
|
+
})
|
|
914
|
+
)
|
|
911
915
|
const sendSpy = stubFeeHistory()
|
|
912
916
|
|
|
913
917
|
await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, eip1559Tx)
|
|
@@ -924,12 +928,13 @@ describe('EVM Family', () => {
|
|
|
924
928
|
])(
|
|
925
929
|
'forwards block count %i to eth_feeHistory as %s (hex-encoded)',
|
|
926
930
|
async (blockCount, expectedHex) => {
|
|
927
|
-
mockGetConfig.mockImplementation(()
|
|
928
|
-
|
|
929
|
-
|
|
931
|
+
mockGetConfig.mockImplementation(() =>
|
|
932
|
+
createMockEvmCoinConfig({
|
|
933
|
+
chainId: 1,
|
|
934
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
930
935
|
feeHistoryBlockCount: blockCount,
|
|
931
|
-
}
|
|
932
|
-
|
|
936
|
+
})
|
|
937
|
+
)
|
|
933
938
|
const sendSpy = stubFeeHistory()
|
|
934
939
|
|
|
935
940
|
await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, eip1559Tx)
|
|
@@ -939,12 +944,13 @@ describe('EVM Family', () => {
|
|
|
939
944
|
)
|
|
940
945
|
|
|
941
946
|
it('is not used on the legacy path (eth_feeHistory is never called)', async () => {
|
|
942
|
-
mockGetConfig.mockImplementation(()
|
|
943
|
-
|
|
944
|
-
|
|
947
|
+
mockGetConfig.mockImplementation(() =>
|
|
948
|
+
createMockEvmCoinConfig({
|
|
949
|
+
chainId: 1,
|
|
950
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
945
951
|
feeHistoryBlockCount: 50,
|
|
946
|
-
}
|
|
947
|
-
|
|
952
|
+
})
|
|
953
|
+
)
|
|
948
954
|
const sendSpy = jest
|
|
949
955
|
.spyOn(JsonRpcProvider.prototype, 'send')
|
|
950
956
|
.mockImplementation(async (method) => {
|
|
@@ -967,13 +973,14 @@ describe('EVM Family', () => {
|
|
|
967
973
|
})
|
|
968
974
|
|
|
969
975
|
it('combines block count and minGasPrice floor correctly', async () => {
|
|
970
|
-
mockGetConfig.mockImplementation(()
|
|
971
|
-
|
|
972
|
-
|
|
976
|
+
mockGetConfig.mockImplementation(() =>
|
|
977
|
+
createMockEvmCoinConfig({
|
|
978
|
+
chainId: 1,
|
|
979
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
973
980
|
feeHistoryBlockCount: 20,
|
|
974
981
|
minGasPrice: '20000000000', // 20 Gwei
|
|
975
|
-
}
|
|
976
|
-
|
|
982
|
+
})
|
|
983
|
+
)
|
|
977
984
|
const sendSpy = jest
|
|
978
985
|
.spyOn(JsonRpcProvider.prototype, 'send')
|
|
979
986
|
.mockImplementation(async (method) => {
|
|
@@ -999,12 +1006,13 @@ describe('EVM Family', () => {
|
|
|
999
1006
|
})
|
|
1000
1007
|
|
|
1001
1008
|
it('applies minGasPrice floor to maxPriorityFeePerGas (EIP-1559) when feeHistory reports a lower value', async () => {
|
|
1002
|
-
mockGetConfig.mockImplementation(()
|
|
1003
|
-
|
|
1004
|
-
|
|
1009
|
+
mockGetConfig.mockImplementation(() =>
|
|
1010
|
+
createMockEvmCoinConfig({
|
|
1011
|
+
chainId: 1,
|
|
1012
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
1005
1013
|
minGasPrice: '20000000000', // 20 Gwei floor
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1014
|
+
})
|
|
1015
|
+
)
|
|
1008
1016
|
|
|
1009
1017
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1010
1018
|
if (method === 'eth_feeHistory') {
|
|
@@ -1025,12 +1033,13 @@ describe('EVM Family', () => {
|
|
|
1025
1033
|
})
|
|
1026
1034
|
|
|
1027
1035
|
it('does not lower the priority fee when feeHistory already reports above the configured floor', async () => {
|
|
1028
|
-
mockGetConfig.mockImplementation(()
|
|
1029
|
-
|
|
1030
|
-
|
|
1036
|
+
mockGetConfig.mockImplementation(() =>
|
|
1037
|
+
createMockEvmCoinConfig({
|
|
1038
|
+
chainId: 1,
|
|
1039
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
1031
1040
|
minGasPrice: '1000000000', // 1 Gwei floor
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1041
|
+
})
|
|
1042
|
+
)
|
|
1034
1043
|
|
|
1035
1044
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1036
1045
|
if (method === 'eth_feeHistory') {
|
|
@@ -1049,12 +1058,13 @@ describe('EVM Family', () => {
|
|
|
1049
1058
|
})
|
|
1050
1059
|
|
|
1051
1060
|
it('applies minGasPrice floor from coin config for legacy txs when node reports lower', async () => {
|
|
1052
|
-
mockGetConfig.mockImplementation(()
|
|
1053
|
-
|
|
1054
|
-
|
|
1061
|
+
mockGetConfig.mockImplementation(() =>
|
|
1062
|
+
createMockEvmCoinConfig({
|
|
1063
|
+
chainId: 1,
|
|
1064
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
1055
1065
|
minGasPrice: '20000000000', // 20 Gwei
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1066
|
+
})
|
|
1067
|
+
)
|
|
1058
1068
|
|
|
1059
1069
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1060
1070
|
if (method === 'eth_getBlockByNumber') {
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { EvmConfig } from '../config'
|
|
5
|
-
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
6
|
-
import { safeEncodeEIP55 } from '../utils'
|
|
7
|
-
import { createApi } from './index'
|
|
8
|
-
|
|
9
|
-
describe('Fantom (etherscan explorer)', () => {
|
|
10
|
-
describe('getBlock', () => {
|
|
11
|
-
let module: ReturnType<typeof createApi>
|
|
12
|
-
|
|
13
|
-
const fantomConfig: EvmConfig = {
|
|
14
|
-
chainId: 250,
|
|
15
|
-
name: 'Fantom',
|
|
16
|
-
node: {
|
|
17
|
-
type: 'external',
|
|
18
|
-
uri: 'https://rpcapi.fantom.network',
|
|
19
|
-
},
|
|
20
|
-
explorer: {
|
|
21
|
-
type: 'blockscout',
|
|
22
|
-
uri: 'https://ftmscout.com/api',
|
|
23
|
-
},
|
|
24
|
-
}
|
|
25
|
-
beforeAll(() => {
|
|
26
|
-
module = createApi('fantom')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should include internal native transfer in block transaction', async () => {
|
|
30
|
-
// for fantom, blockscout explorer returns no internal transactions for block 120647648, even though there are 3 !!
|
|
31
|
-
// ❯ curl -s "https://ftmscout.com/api?module=account&action=txlistinternal&startblock=120647648&endblock=120647648"
|
|
32
|
-
// {"message":"No internal transactions found","result":[],"status":"0"}
|
|
33
|
-
|
|
34
|
-
// ❯ curl -s -X POST "https://rpcapi.fantom.network" -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"trace_block","params":["0x730efe0"]}' | jq '.result | length'
|
|
35
|
-
// 6
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
const blockHeight = 120647648
|
|
39
|
-
const expectedAmount = 0x15a7c087e1eb7e18n
|
|
40
|
-
|
|
41
|
-
/*
|
|
42
|
-
* Fantom block 120647648 contains (among others) 3 internal native transfers with value 0x15a7c087e1eb7e18:
|
|
43
|
-
* - 0x59e8070de88cc1e4085293efd08aad4fba2ef6e0 → 0x44ceb2cdd0e9891f26ce5b96d2a7a3017304c25f
|
|
44
|
-
* - 0x44ceb2cdd0e9891f26ce5b96d2a7a3017304c25f → 0x68e369edc0d374f86295690cbaa981ee3709c061
|
|
45
|
-
* - 0x68e369edc0d374f86295690cbaa981ee3709c061 → 0x10bb279126abd92d886aa3f2a60955c28bf14926
|
|
46
|
-
*/
|
|
47
|
-
const addr1 = safeEncodeEIP55('0x59e8070de88cc1e4085293efd08aad4fba2ef6e0')
|
|
48
|
-
const addr2 = safeEncodeEIP55('0x44ceb2cdd0e9891f26ce5b96d2a7a3017304c25f')
|
|
49
|
-
const addr3 = safeEncodeEIP55('0x68e369edc0d374f86295690cbaa981ee3709c061')
|
|
50
|
-
const addr4 = safeEncodeEIP55('0x10bb279126abd92d886aa3f2a60955c28bf14926')
|
|
51
|
-
|
|
52
|
-
const block = await module.getBlock(createMockEvmContext(fantomConfig), blockHeight)
|
|
53
|
-
|
|
54
|
-
expect(block.info.height).toBe(blockHeight)
|
|
55
|
-
|
|
56
|
-
const tx = block.transactions.find(
|
|
57
|
-
(t) => t.hash === '0x18815c2073a78c2264b89ee4b4a9267eb31c4c0a91b9d4d751ddd84b26584493'
|
|
58
|
-
)
|
|
59
|
-
expect(tx!.operations).toContainEqual({
|
|
60
|
-
type: 'transfer',
|
|
61
|
-
address: addr1,
|
|
62
|
-
peer: addr2,
|
|
63
|
-
asset: { type: 'native' },
|
|
64
|
-
amount: -expectedAmount,
|
|
65
|
-
})
|
|
66
|
-
expect(tx!.operations).toContainEqual({
|
|
67
|
-
type: 'transfer',
|
|
68
|
-
address: addr2,
|
|
69
|
-
peer: addr1,
|
|
70
|
-
asset: { type: 'native' },
|
|
71
|
-
amount: expectedAmount,
|
|
72
|
-
})
|
|
73
|
-
expect(tx!.operations).toContainEqual({
|
|
74
|
-
type: 'transfer',
|
|
75
|
-
address: addr2,
|
|
76
|
-
peer: addr3,
|
|
77
|
-
asset: { type: 'native' },
|
|
78
|
-
amount: -expectedAmount,
|
|
79
|
-
})
|
|
80
|
-
expect(tx!.operations).toContainEqual({
|
|
81
|
-
type: 'transfer',
|
|
82
|
-
address: addr3,
|
|
83
|
-
peer: addr2,
|
|
84
|
-
asset: { type: 'native' },
|
|
85
|
-
amount: expectedAmount,
|
|
86
|
-
})
|
|
87
|
-
expect(tx!.operations).toContainEqual({
|
|
88
|
-
type: 'transfer',
|
|
89
|
-
address: addr3,
|
|
90
|
-
peer: addr4,
|
|
91
|
-
asset: { type: 'native' },
|
|
92
|
-
amount: -expectedAmount,
|
|
93
|
-
})
|
|
94
|
-
expect(tx!.operations).toContainEqual({
|
|
95
|
-
type: 'transfer',
|
|
96
|
-
address: addr4,
|
|
97
|
-
peer: addr3,
|
|
98
|
-
asset: { type: 'native' },
|
|
99
|
-
amount: expectedAmount,
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
})
|