@ledgerhq/coin-evm 5.3.2 → 5.3.3

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.
Files changed (47) hide show
  1. package/.oxlintrc.json +1 -1
  2. package/CHANGELOG.md +7 -0
  3. package/package.json +2 -2
  4. package/src/adapters/blockOperations.test.ts +27 -29
  5. package/src/api/index.flare.integ.test.ts +1 -13
  6. package/src/api/index.integ.test.ts +86 -97
  7. package/src/fixtures/context.fixtures.ts +79 -1
  8. package/src/fixtures/ethers.fixtures.ts +26 -0
  9. package/src/logic/broadcast.integ.test.ts +6 -18
  10. package/src/logic/broadcast.test.ts +19 -31
  11. package/src/logic/broadcastSource.test.ts +6 -7
  12. package/src/logic/common.test.ts +120 -112
  13. package/src/logic/craftTransaction.test.ts +161 -199
  14. package/src/logic/craftTransactionData.test.ts +6 -6
  15. package/src/logic/estimateFees.test.ts +19 -15
  16. package/src/logic/getBalance.test.ts +15 -14
  17. package/src/logic/getBlock.test.ts +372 -382
  18. package/src/logic/getBlockInfo.test.ts +6 -6
  19. package/src/logic/getNextSequence.test.ts +5 -5
  20. package/src/logic/getStakes.test.ts +34 -34
  21. package/src/logic/internalTransactionsFetcher.test.ts +23 -19
  22. package/src/logic/lastBlock.test.ts +29 -21
  23. package/src/logic/listOperations.test.ts +43 -40
  24. package/src/logic/validateIntent.test.ts +151 -101
  25. package/src/logic.test.ts +13 -18
  26. package/src/network/explorer/etherscan.test.ts +5 -5
  27. package/src/network/explorer/index.test.ts +51 -21
  28. package/src/network/explorer/ledger.test.ts +15 -4
  29. package/src/network/gasTracker/index.test.ts +14 -8
  30. package/src/network/gasTracker/ledger.test.ts +25 -13
  31. package/src/network/node/index.memoization.test.ts +25 -31
  32. package/src/network/node/index.test.ts +14 -25
  33. package/src/network/node/ledger.test.ts +45 -60
  34. package/src/network/node/node.fixtures.ts +0 -2
  35. package/src/network/node/rpc.test.ts +152 -177
  36. package/src/staking/encoder.test.ts +13 -21
  37. package/src/staking/logic.test.ts +20 -14
  38. package/src/staking/operations/index.test.ts +28 -28
  39. package/src/staking/prepareIntents.test.ts +26 -20
  40. package/src/staking/redelegations.test.ts +27 -18
  41. package/src/staking/rewards.test.ts +23 -15
  42. package/src/staking/rewardsFromReceipt.test.ts +19 -20
  43. package/src/staking/transactionData.test.ts +22 -22
  44. package/src/staking/validators/monad.test.ts +65 -24
  45. package/src/staking/validators/somnia.test.ts +21 -13
  46. package/src/staking/validators/zero_gravity.test.ts +118 -48
  47. package/src/staking/validators.integ.test.ts +13 -25
@@ -1,11 +1,9 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmCoinConfig } from '../config'
5
4
  import type {
6
5
  BufferTxData,
7
6
  MemoNotSupported,
8
- Operation,
9
7
  TransactionIntent,
10
8
  } from '@ledgerhq/coin-module-framework/api/types'
11
9
  import {
@@ -16,6 +14,7 @@ import {
16
14
  NotEnoughBalance,
17
15
  RecipientRequired,
18
16
  } from '@ledgerhq/coin-module-framework/errors'
17
+ import { createStakingTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
19
18
  import BigNumber from 'bignumber.js'
20
19
  import { createContext, setCoinConfig } from '../config'
21
20
  import {
@@ -32,6 +31,12 @@ import {
32
31
  RedelegateDstValAddressRequired,
33
32
  ValAddressRequired,
34
33
  } from '../errors'
34
+ import {
35
+ createMockEvmCoinConfig,
36
+ mkLedgerExplorer,
37
+ mkLedgerGasTracker,
38
+ mkLedgerNode,
39
+ } from '../fixtures/context.fixtures'
35
40
  import ledgerExplorer from '../network/explorer/ledger'
36
41
  import ledgerGasTracker from '../network/gasTracker/ledger'
37
42
  import { getNodeApi } from '../network/node'
@@ -81,43 +86,18 @@ function eip1559Intent(
81
86
  }
82
87
  }
83
88
 
84
- function stakingIntent(
85
- intent: Partial<
86
- TransactionIntent<MemoNotSupported, BufferTxData> & {
87
- mode: 'delegate' | 'redelegate' | 'undelegate' | 'claimReward'
88
- valAddress?: string
89
- dstValAddress?: string
90
- }
91
- >
92
- ): TransactionIntent<MemoNotSupported, BufferTxData> {
93
- return {
94
- type: 'send-legacy',
95
- intentType: 'staking',
96
- sender: '0xsender',
97
- recipient: '0xe2ca7390e76c5A992749bB622087310d2e63ca29',
98
- amount: 1n,
99
- asset: { type: 'native' },
100
- mode: 'delegate',
101
- valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
102
- data: { type: 'buffer', value: Buffer.from([]) },
103
- ...intent,
104
- } as TransactionIntent<MemoNotSupported, BufferTxData>
105
- }
106
-
107
89
  describe('validateIntent', () => {
108
90
  const nodeApiMock = mockNodeApi()
109
91
 
110
92
  beforeEach(() => {
111
- setCoinConfig(
112
- () =>
113
- ({
114
- info: {
115
- name: 'Ethereum',
116
- node: { type: 'ledger', explorerId: 'eth' },
117
- explorer: { type: 'ledger' },
118
- gasTracker: { type: 'ledger', explorerId: 'eth' },
119
- },
120
- }) as unknown as EvmCoinConfig
93
+ setCoinConfig(() =>
94
+ createMockEvmCoinConfig({
95
+ chainId: 1,
96
+ node: mkLedgerNode({ explorerId: 'eth' }),
97
+ name: 'Ethereum',
98
+ explorer: mkLedgerExplorer({ explorerId: 'eth' }),
99
+ gasTracker: mkLedgerGasTracker({ explorerId: 'eth' }),
100
+ })
121
101
  )
122
102
 
123
103
  mockGetNodeApi.mockReturnValue(nodeApiMock)
@@ -440,11 +420,23 @@ describe('validateIntent', () => {
440
420
  lastNftOperations: [],
441
421
  lastTokenOperations: [
442
422
  {
423
+ id: '',
424
+ type: '',
425
+ senders: [],
426
+ recipients: [],
427
+ value: 0n,
443
428
  asset: {
444
429
  type: 'erc20' as const,
445
430
  assetReference: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
446
431
  },
447
- } as unknown as Operation<MemoNotSupported>,
432
+ tx: {
433
+ hash: '',
434
+ block: { height: 0, hash: '', time: new Date(0) },
435
+ fees: 0n,
436
+ date: new Date(0),
437
+ failed: false,
438
+ },
439
+ },
448
440
  ],
449
441
  nextPagingToken: '',
450
442
  })
@@ -539,13 +531,15 @@ describe('validateIntent', () => {
539
531
 
540
532
  describe('staking', () => {
541
533
  it('detects missing validator address for delegate with an error', async () => {
542
- const intent = stakingIntent({ mode: 'delegate' }) as Record<string, unknown>
543
- delete intent.valAddress
544
-
545
534
  const res = await validateIntent(
546
535
  createContext(),
547
536
  'sei_evm',
548
- intent as TransactionIntent<MemoNotSupported, BufferTxData>,
537
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
538
+ type: 'staking-legacy',
539
+ mode: 'delegate',
540
+ valAddress: '',
541
+ data: { type: 'buffer', value: Buffer.from([]) },
542
+ }),
549
543
  [{ value: 50n, asset: { type: 'native' } }],
550
544
  {
551
545
  value: 10n,
@@ -561,16 +555,15 @@ describe('validateIntent', () => {
561
555
  })
562
556
 
563
557
  it('detects missing destination validator address for redelegate with an error', async () => {
564
- const intent = stakingIntent({
565
- mode: 'redelegate',
566
- valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
567
- }) as Record<string, unknown>
568
- delete intent.dstValAddress
569
-
570
558
  const res = await validateIntent(
571
559
  createContext(),
572
560
  'sei_evm',
573
- intent as TransactionIntent<MemoNotSupported, BufferTxData>,
561
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
562
+ type: 'staking-legacy',
563
+ mode: 'redelegate',
564
+ valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
565
+ data: { type: 'buffer', value: Buffer.from([]) },
566
+ }),
574
567
  [{ value: 50n, asset: { type: 'native' } }],
575
568
  {
576
569
  value: 10n,
@@ -589,10 +582,12 @@ describe('validateIntent', () => {
589
582
  const res = await validateIntent(
590
583
  createContext(),
591
584
  'sei_evm',
592
- stakingIntent({
585
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
586
+ type: 'staking-legacy',
593
587
  mode: 'delegate',
594
588
  amount: 45n,
595
589
  valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
590
+ data: { type: 'buffer', value: Buffer.from([]) },
596
591
  }),
597
592
  [{ value: 50n, asset: { type: 'native' } }],
598
593
  {
@@ -612,10 +607,12 @@ describe('validateIntent', () => {
612
607
  const res = await validateIntent(
613
608
  createContext(),
614
609
  'sei_evm',
615
- stakingIntent({
610
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
611
+ type: 'staking-legacy',
616
612
  mode: 'undelegate',
617
613
  amount: 100n,
618
614
  valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
615
+ data: { type: 'buffer', value: Buffer.from([]) },
619
616
  }),
620
617
  [{ value: 50n, asset: { type: 'native' } }],
621
618
  {
@@ -632,11 +629,13 @@ describe('validateIntent', () => {
632
629
  const res = await validateIntent(
633
630
  createContext(),
634
631
  'sei_evm',
635
- stakingIntent({
632
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
633
+ type: 'staking-legacy',
636
634
  mode: 'redelegate',
637
635
  amount: 100n,
638
636
  valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
639
637
  dstValAddress: 'seivaloper1f4cqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq',
638
+ data: { type: 'buffer', value: Buffer.from([]) },
640
639
  }),
641
640
  [{ value: 50n, asset: { type: 'native' } }],
642
641
  {
@@ -653,10 +652,12 @@ describe('validateIntent', () => {
653
652
  const res = await validateIntent(
654
653
  createContext(),
655
654
  'sei_evm',
656
- stakingIntent({
655
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
656
+ type: 'staking-legacy',
657
657
  mode: 'delegate',
658
658
  amount: 1n,
659
659
  valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
660
+ data: { type: 'buffer', value: Buffer.from([]) },
660
661
  }),
661
662
  [{ value: 50n, asset: { type: 'native' } }],
662
663
  {
@@ -676,10 +677,12 @@ describe('validateIntent', () => {
676
677
  const res = await validateIntent(
677
678
  createContext(),
678
679
  'sei_evm',
679
- stakingIntent({
680
- amount: 0n,
680
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
681
+ type: 'staking-legacy',
681
682
  mode: 'claimReward',
683
+ amount: 0n,
682
684
  valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
685
+ data: { type: 'buffer', value: Buffer.from([]) },
683
686
  }),
684
687
  [{ value: 50n, asset: { type: 'native' } }],
685
688
  {
@@ -697,10 +700,12 @@ describe('validateIntent', () => {
697
700
  const res = await validateIntent(
698
701
  createContext(),
699
702
  'sei_evm',
700
- stakingIntent({
701
- amount: 0n,
703
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
704
+ type: 'staking-legacy',
702
705
  mode: 'claimReward',
706
+ amount: 0n,
703
707
  valAddress: '',
708
+ data: { type: 'buffer', value: Buffer.from([]) },
704
709
  }),
705
710
  [{ value: 500n, asset: { type: 'native' } }],
706
711
  {
@@ -718,10 +723,12 @@ describe('validateIntent', () => {
718
723
  const res = await validateIntent(
719
724
  createContext(),
720
725
  'sei_evm',
721
- stakingIntent({
722
- amount: 0n,
726
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
727
+ type: 'staking-legacy',
723
728
  mode: 'claimReward',
729
+ amount: 0n,
724
730
  valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
731
+ data: { type: 'buffer', value: Buffer.from([]) },
725
732
  }),
726
733
  [{ value: 500n, asset: { type: 'native' } }],
727
734
  {
@@ -745,7 +752,12 @@ describe('validateIntent', () => {
745
752
  const res = await validateIntent(
746
753
  createContext(),
747
754
  'unknown_chain',
748
- stakingIntent({ mode: 'delegate', useAllAmount: true }),
755
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
756
+ type: 'staking-legacy',
757
+ mode: 'delegate',
758
+ useAllAmount: true,
759
+ data: { type: 'buffer', value: Buffer.from([]) },
760
+ }),
749
761
  [{ value: balance, asset: { type: 'native' } }],
750
762
  { value: totalFees, parameters: { gasLimit: 100_000n, gasPrice: 1n } }
751
763
  )
@@ -763,7 +775,12 @@ describe('validateIntent', () => {
763
775
  const res = await validateIntent(
764
776
  createContext(),
765
777
  'sei_evm',
766
- stakingIntent({ mode: 'delegate', useAllAmount: true }),
778
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
779
+ type: 'staking-legacy',
780
+ mode: 'delegate',
781
+ useAllAmount: true,
782
+ data: { type: 'buffer', value: Buffer.from([]) },
783
+ }),
767
784
  [{ value: balance, asset: { type: 'native' } }],
768
785
  {
769
786
  value: fees,
@@ -786,7 +803,12 @@ describe('validateIntent', () => {
786
803
  const res = await validateIntent(
787
804
  createContext(),
788
805
  'sei_evm',
789
- stakingIntent({ mode: 'delegate', useAllAmount: true }),
806
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
807
+ type: 'staking-legacy',
808
+ mode: 'delegate',
809
+ useAllAmount: true,
810
+ data: { type: 'buffer', value: Buffer.from([]) },
811
+ }),
790
812
  [{ value: balance, asset: { type: 'native' } }],
791
813
  {
792
814
  value: fees,
@@ -807,10 +829,12 @@ describe('validateIntent', () => {
807
829
  assetReference: '0x0000000000000000000000000000000000000001',
808
830
  }
809
831
  const claimRewardIntent = (overrides: { amount: bigint; native: boolean }) =>
810
- stakingIntent({
832
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
833
+ type: 'staking-legacy',
811
834
  mode: 'claimReward',
812
835
  amount: overrides.amount,
813
836
  valAddress: 'seivaloper1y82m5y3wevjneamzg0pmx87dzanyxzht0kepvn',
837
+ data: { type: 'buffer', value: Buffer.from([]) },
814
838
  ...(overrides.native ? {} : { asset: tokenAsset }),
815
839
  })
816
840
  const claimRewardBalances = (native: boolean) => [
@@ -1082,9 +1106,7 @@ describe('validateIntent', () => {
1082
1106
 
1083
1107
  it('detects gas limit being too low in a tx with an error', async () => {
1084
1108
  const eip7623GasLimit = 21000n
1085
- ;(computeGasLimitModule.computeEIP7623GasLimit as jest.Mock).mockReturnValue(
1086
- eip7623GasLimit
1087
- )
1109
+ jest.mocked(computeGasLimitModule.computeEIP7623GasLimit).mockReturnValue(eip7623GasLimit)
1088
1110
 
1089
1111
  const res = await validateIntent(
1090
1112
  createContext(),
@@ -1108,9 +1130,7 @@ describe('validateIntent', () => {
1108
1130
 
1109
1131
  it('detects custom gas limit being too low in a tx with an error', async () => {
1110
1132
  const eip7623GasLimit = 21000n
1111
- ;(computeGasLimitModule.computeEIP7623GasLimit as jest.Mock).mockReturnValue(
1112
- eip7623GasLimit
1113
- )
1133
+ jest.mocked(computeGasLimitModule.computeEIP7623GasLimit).mockReturnValue(eip7623GasLimit)
1114
1134
 
1115
1135
  const res = await validateIntent(
1116
1136
  createContext(),
@@ -1134,17 +1154,15 @@ describe('validateIntent', () => {
1134
1154
 
1135
1155
  describe('calldata floor coin config', () => {
1136
1156
  it('forwards the configured floor parameters to computeEIP7623GasLimit', async () => {
1137
- setCoinConfig(
1138
- () =>
1139
- ({
1140
- info: {
1141
- node: { type: 'ledger', explorerId: 'eth' },
1142
- explorer: { type: 'ledger' },
1143
- gasTracker: { type: 'ledger', explorerId: 'eth' },
1144
- calldataFloorGasPerToken: 16,
1145
- calldataFloorZeroByteTokens: 4,
1146
- },
1147
- }) as unknown as EvmCoinConfig
1157
+ setCoinConfig(() =>
1158
+ createMockEvmCoinConfig({
1159
+ chainId: 1,
1160
+ node: mkLedgerNode({ explorerId: 'eth' }),
1161
+ explorer: mkLedgerExplorer({ explorerId: 'eth' }),
1162
+ gasTracker: mkLedgerGasTracker({ explorerId: 'eth' }),
1163
+ calldataFloorGasPerToken: 16,
1164
+ calldataFloorZeroByteTokens: 4,
1165
+ })
1148
1166
  )
1149
1167
 
1150
1168
  await validateIntent(
@@ -1364,16 +1382,14 @@ describe('validateIntent', () => {
1364
1382
 
1365
1383
  describe('minGasPrice', () => {
1366
1384
  beforeEach(() => {
1367
- setCoinConfig(
1368
- () =>
1369
- ({
1370
- info: {
1371
- node: { type: 'ledger', explorerId: 'eth' },
1372
- explorer: { type: 'ledger' },
1373
- gasTracker: { type: 'ledger', explorerId: 'eth' },
1374
- minGasPrice: '25000000000',
1375
- },
1376
- }) as unknown as EvmCoinConfig
1385
+ setCoinConfig(() =>
1386
+ createMockEvmCoinConfig({
1387
+ chainId: 1,
1388
+ node: mkLedgerNode({ explorerId: 'eth' }),
1389
+ explorer: mkLedgerExplorer({ explorerId: 'eth' }),
1390
+ gasTracker: mkLedgerGasTracker({ explorerId: 'eth' }),
1391
+ minGasPrice: '25000000000',
1392
+ })
1377
1393
  )
1378
1394
  })
1379
1395
 
@@ -1420,16 +1436,14 @@ describe('validateIntent', () => {
1420
1436
  describe('legacy specific', () => {
1421
1437
  describe('minGasPrice', () => {
1422
1438
  beforeEach(() => {
1423
- setCoinConfig(
1424
- () =>
1425
- ({
1426
- info: {
1427
- node: { type: 'ledger', explorerId: 'eth' },
1428
- explorer: { type: 'ledger' },
1429
- gasTracker: { type: 'ledger', explorerId: 'eth' },
1430
- minGasPrice: '25000000000',
1431
- },
1432
- }) as unknown as EvmCoinConfig
1439
+ setCoinConfig(() =>
1440
+ createMockEvmCoinConfig({
1441
+ chainId: 1,
1442
+ node: mkLedgerNode({ explorerId: 'eth' }),
1443
+ explorer: mkLedgerExplorer({ explorerId: 'eth' }),
1444
+ gasTracker: mkLedgerGasTracker({ explorerId: 'eth' }),
1445
+ minGasPrice: '25000000000',
1446
+ })
1433
1447
  )
1434
1448
  })
1435
1449
 
@@ -1579,8 +1593,20 @@ describe('validateIntent', () => {
1579
1593
  lastNftOperations: [],
1580
1594
  lastTokenOperations: [
1581
1595
  {
1596
+ id: '',
1597
+ type: '',
1598
+ senders: [],
1599
+ recipients: [],
1600
+ value: 0n,
1582
1601
  asset: { type: 'erc20' as const, assetReference: 'contract-address' },
1583
- } as unknown as Operation<MemoNotSupported>,
1602
+ tx: {
1603
+ hash: '',
1604
+ block: { height: 0, hash: '', time: new Date(0) },
1605
+ fees: 0n,
1606
+ date: new Date(0),
1607
+ failed: false,
1608
+ },
1609
+ },
1584
1610
  ],
1585
1611
  nextPagingToken: '',
1586
1612
  })
@@ -1623,8 +1649,20 @@ describe('validateIntent', () => {
1623
1649
  lastNftOperations: [],
1624
1650
  lastTokenOperations: [
1625
1651
  {
1652
+ id: '',
1653
+ type: '',
1654
+ senders: [],
1655
+ recipients: [],
1656
+ value: 0n,
1626
1657
  asset: { type: 'erc20' as const, assetReference: 'contract-address' },
1627
- } as unknown as Operation<MemoNotSupported>,
1658
+ tx: {
1659
+ hash: '',
1660
+ block: { height: 0, hash: '', time: new Date(0) },
1661
+ fees: 0n,
1662
+ date: new Date(0),
1663
+ failed: false,
1664
+ },
1665
+ },
1628
1666
  ],
1629
1667
  nextPagingToken: '',
1630
1668
  })
@@ -1692,8 +1730,20 @@ describe('validateIntent', () => {
1692
1730
  lastNftOperations: [],
1693
1731
  lastTokenOperations: [
1694
1732
  {
1733
+ id: '',
1734
+ type: '',
1735
+ senders: [],
1736
+ recipients: [],
1737
+ value: 0n,
1695
1738
  asset: { type: 'erc20' as const, assetReference: 'contract-address' },
1696
- } as unknown as Operation<MemoNotSupported>,
1739
+ tx: {
1740
+ hash: '',
1741
+ block: { height: 0, hash: '', time: new Date(0) },
1742
+ fees: 0n,
1743
+ date: new Date(0),
1744
+ failed: false,
1745
+ },
1746
+ },
1697
1747
  ],
1698
1748
  nextPagingToken: '',
1699
1749
  })
package/src/logic.test.ts CHANGED
@@ -9,13 +9,18 @@ jest.mock('./network/node/index', () => ({
9
9
  }))
10
10
 
11
11
  import { getCoinConfig } from './config'
12
+ import { createMockEvmConfigInfo, mkExternalNode } from './fixtures/context.fixtures'
12
13
  import { getAdditionalLayer2Fees } from './logic'
13
14
  import { getNodeApi } from './network/node/index'
15
+ import { mockNodeApi } from './network/node/node.fixtures'
14
16
  import { padHexString, safeEncodeEIP55 } from './utils'
15
17
 
16
18
  const mockGetNodeApi = jest.mocked(getNodeApi)
17
- const mockGetOptimismAdditionalFees = jest.fn()
18
- const mockGetScrollAdditionalFees = jest.fn()
19
+ const nodeApiMock = mockNodeApi()
20
+ const {
21
+ getOptimismAdditionalFees: mockGetOptimismAdditionalFees,
22
+ getScrollAdditionalFees: mockGetScrollAdditionalFees,
23
+ } = nodeApiMock
19
24
 
20
25
  jest.mock('./config')
21
26
  const mockGetConfig = jest.mocked(getCoinConfig)
@@ -90,30 +95,20 @@ describe('EVM Family', () => {
90
95
  describe('getAdditionalLayer2Fees', () => {
91
96
  beforeEach(() => {
92
97
  jest.clearAllMocks()
93
- mockGetNodeApi.mockImplementation(
94
- () =>
95
- ({
96
- getOptimismAdditionalFees: mockGetOptimismAdditionalFees,
97
- getScrollAdditionalFees: mockGetScrollAdditionalFees,
98
- }) as any
99
- )
98
+ mockGetNodeApi.mockReturnValue(nodeApiMock)
100
99
  })
101
100
 
102
101
  it('should try to get additionalFees for a valid layer 2', async () => {
103
- mockGetOptimismAdditionalFees.mockClear()
104
- mockGetScrollAdditionalFees.mockClear()
105
-
106
- await getAdditionalLayer2Fees({} as any, 'optimism', {} as any)
102
+ const cfg = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
103
+ await getAdditionalLayer2Fees(cfg, 'optimism', '')
107
104
  expect(mockGetOptimismAdditionalFees).toHaveBeenCalled()
108
- await getAdditionalLayer2Fees({} as any, 'scroll', {} as any)
105
+ await getAdditionalLayer2Fees(cfg, 'scroll', '')
109
106
  expect(mockGetScrollAdditionalFees).toHaveBeenCalled()
110
107
  })
111
108
 
112
109
  it('should not try to get additionalFees for an invalid layer 2', async () => {
113
- mockGetOptimismAdditionalFees.mockClear()
114
- mockGetScrollAdditionalFees.mockClear()
115
-
116
- await getAdditionalLayer2Fees({} as any, 'ethereum', {} as any)
110
+ const cfg = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
111
+ await getAdditionalLayer2Fees(cfg, 'ethereum', '')
117
112
  expect(mockGetOptimismAdditionalFees).not.toHaveBeenCalled()
118
113
  expect(mockGetScrollAdditionalFees).not.toHaveBeenCalled()
119
114
  })
@@ -28,7 +28,7 @@ import * as ETHERSCAN_API from './etherscan'
28
28
 
29
29
  jest.mock('axios')
30
30
  jest.mock('@ledgerhq/coin-module-framework/promises')
31
- ;(delay as jest.Mock).mockImplementation(
31
+ jest.mocked(delay).mockImplementation(
32
32
  () => new Promise((resolve) => setTimeout(resolve, 1)) // mocking the delay supposed to happen after each try
33
33
  )
34
34
 
@@ -1859,7 +1859,7 @@ describe('EVM Family', () => {
1859
1859
  })
1860
1860
 
1861
1861
  describe('getNftOperations supportedTokens atomicity', () => {
1862
- const withSupportedTokens = (supportedTokens: ('erc721' | 'erc1155')[]) => {
1862
+ const withSupportedTokens = (supportedTokens: string[]) => {
1863
1863
  mockGetConfig.mockImplementation((): any => ({
1864
1864
  info: {
1865
1865
  explorer: { type: 'etherscan', uri: 'mock' },
@@ -1931,7 +1931,7 @@ describe('EVM Family', () => {
1931
1931
  // only non-NFT standards (e.g. a future "erc20") must NOT activate NFT fetching. Activation is
1932
1932
  // driven by explicit NFT-standard membership, not by the array being non-empty.
1933
1933
  it('does not activate NFTs for a non-NFT standard such as erc20', async () => {
1934
- withSupportedTokens(['erc20'] as unknown as ('erc721' | 'erc1155')[])
1934
+ withSupportedTokens(['erc20'])
1935
1935
  const { assetTypes, fetchedErc721, fetchedErc1155 } = await fetchNfts()
1936
1936
  expect(assetTypes).toEqual(new Set())
1937
1937
  expect(fetchedErc721).toBe(false)
@@ -2005,7 +2005,7 @@ describe('EVM Family', () => {
2005
2005
  const pageCounts: Record<string, number> = {}
2006
2006
 
2007
2007
  return async (config: any) => {
2008
- const url = config.url as string
2008
+ const url: string = config.url
2009
2009
  const params = config.params
2010
2010
  const startBlock = params.startblock ?? 0
2011
2011
  const endBlock = params.endblock ?? Infinity
@@ -2088,7 +2088,7 @@ describe('EVM Family', () => {
2088
2088
  ...result.lastTokenOperations.map((op) => ({ type: 'T', block: op.tx.block.height })),
2089
2089
  ]
2090
2090
  // Secondary sort order: C < I < T (coin first at same block)
2091
- const typeOrder = { C: 0, I: 1, T: 2 } as Record<string, number>
2091
+ const typeOrder: Record<string, number> = { C: 0, I: 1, T: 2 }
2092
2092
  const ops = tagged
2093
2093
  .filter((op): op is { type: string; block: number } => op.block !== undefined)
2094
2094
  .sort((a, b) => b.block - a.block || typeOrder[a.type] - typeOrder[b.type])