@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
@@ -4,26 +4,58 @@
4
4
  import type { EvmConfigInfo } from '../../config'
5
5
  import { AssertionError, fail } from 'assert'
6
6
  import { UnknownExplorer } from '../../errors'
7
+ import {
8
+ createMockEvmConfigInfo,
9
+ mkEtherscanExplorer,
10
+ mkExternalNode,
11
+ mkLedgerExplorer,
12
+ } from '../../fixtures/context.fixtures'
7
13
  import etherscanLikeApi from './etherscan'
8
14
  import ledgerExplorerApi from './ledger'
9
15
  import { getExplorerApi } from './index'
10
16
 
11
17
  const configFor = (currencyId: string): EvmConfigInfo => {
18
+ const node = mkExternalNode()
12
19
  switch (currencyId) {
13
20
  case 'anything-coin':
14
- return { explorer: { type: 'anything', uri: 'notworking' } } as any
21
+ return createMockEvmConfigInfo({
22
+ chainId: 1,
23
+ node,
24
+ // @ts-expect-error — intentional invalid explorer type to test UnknownExplorer error path
25
+ explorer: { type: 'anything', uri: 'notworking' },
26
+ })
15
27
  case 'etherscan-coin':
16
- return { explorer: { type: 'etherscan', uri: 'working' } } as any
28
+ return createMockEvmConfigInfo({
29
+ chainId: 1,
30
+ node,
31
+ explorer: mkEtherscanExplorer({ uri: 'working' }),
32
+ })
17
33
  case 'blockscout-coin':
18
- return { explorer: { type: 'blockscout', uri: 'working' } } as any
34
+ return createMockEvmConfigInfo({
35
+ chainId: 1,
36
+ node,
37
+ explorer: { type: 'blockscout', uri: 'working' },
38
+ })
19
39
  case 'etherscan-coin-no-cache':
20
- return { explorer: { type: 'etherscan', uri: 'working', noCache: true } } as any
40
+ return createMockEvmConfigInfo({
41
+ chainId: 1,
42
+ node,
43
+ explorer: mkEtherscanExplorer({ uri: 'working', noCache: true }),
44
+ })
21
45
  case 'blockscout-coin-no-cache':
22
- return { explorer: { type: 'blockscout', uri: 'working', noCache: true } } as any
46
+ return createMockEvmConfigInfo({
47
+ chainId: 1,
48
+ node,
49
+ explorer: { type: 'blockscout', uri: 'working', noCache: true },
50
+ })
23
51
  case 'ledger-coin':
24
- return { explorer: { type: 'ledger', explorerId: 'eth' } } as any
52
+ return createMockEvmConfigInfo({
53
+ chainId: 1,
54
+ node,
55
+ explorer: mkLedgerExplorer({ explorerId: 'eth' }),
56
+ })
25
57
  default:
26
- return {} as any
58
+ return createMockEvmConfigInfo({ chainId: 1, node })
27
59
  }
28
60
  }
29
61
 
@@ -32,7 +64,7 @@ describe('EVM Family', () => {
32
64
  describe('getExplorerApi', () => {
33
65
  it('should throw when requesting a non existing explorer', () => {
34
66
  try {
35
- getExplorerApi(configFor('anything-coin'), { id: 'anything-coin' } as any)
67
+ getExplorerApi(configFor('anything-coin'), 'anything-coin')
36
68
  fail('Promise should have been rejected')
37
69
  } catch (e) {
38
70
  if (e instanceof AssertionError) {
@@ -43,31 +75,29 @@ describe('EVM Family', () => {
43
75
  })
44
76
 
45
77
  it('should return the etherscan api', () => {
46
- const explorerA = getExplorerApi(configFor('etherscan-coin'), {
47
- id: 'etherscan-coin',
48
- } as any)
49
- const explorerB = getExplorerApi(configFor('blockscout-coin'), {
50
- id: 'blockscout-coin',
51
- } as any)
78
+ const explorerA = getExplorerApi(configFor('etherscan-coin'), 'etherscan-coin')
79
+ const explorerB = getExplorerApi(configFor('blockscout-coin'), 'blockscout-coin')
52
80
 
53
81
  expect(explorerA).toBe(etherscanLikeApi.explorerApi)
54
82
  expect(explorerB).toBe(etherscanLikeApi.explorerApi)
55
83
  })
56
84
 
57
85
  it('should return the no cache etherscan api', () => {
58
- const explorerA = getExplorerApi(configFor('etherscan-coin-no-cache'), {
59
- id: 'etherscan-coin-no-cache',
60
- } as any)
61
- const explorerB = getExplorerApi(configFor('blockscout-coin-no-cache'), {
62
- id: 'blockscout-coin-no-cache',
63
- } as any)
86
+ const explorerA = getExplorerApi(
87
+ configFor('etherscan-coin-no-cache'),
88
+ 'etherscan-coin-no-cache'
89
+ )
90
+ const explorerB = getExplorerApi(
91
+ configFor('blockscout-coin-no-cache'),
92
+ 'blockscout-coin-no-cache'
93
+ )
64
94
 
65
95
  expect(explorerA).toBe(etherscanLikeApi.explorerApiNoCache)
66
96
  expect(explorerB).toBe(etherscanLikeApi.explorerApiNoCache)
67
97
  })
68
98
 
69
99
  it('should return the ledger api', () => {
70
- const explorerA = getExplorerApi(configFor('ledger-coin'), { id: 'ledger-coin' } as any)
100
+ const explorerA = getExplorerApi(configFor('ledger-coin'), 'ledger-coin')
71
101
 
72
102
  expect(explorerA).toBe(ledgerExplorerApi)
73
103
  })
@@ -18,7 +18,7 @@ import * as LEDGER_API from './ledger'
18
18
 
19
19
  jest.mock('axios')
20
20
  jest.mock('@ledgerhq/coin-module-framework/promises')
21
- ;(delay as jest.Mock).mockImplementation(
21
+ jest.mocked(delay).mockImplementation(
22
22
  () => new Promise((resolve) => setTimeout(resolve, 1)) // mocking the delay supposed to happen after each try
23
23
  )
24
24
 
@@ -55,7 +55,12 @@ describe('EVM Family', () => {
55
55
  }
56
56
  return { data: { data: [] } }
57
57
  })
58
- const response = await LEDGER_API.fetchPaginatedOpsWithRetries({} as any, null, [], retries)
58
+ const response = await LEDGER_API.fetchPaginatedOpsWithRetries(
59
+ { explorerId: 'test', address: '0x', fromBlock: 0, batchSize: 10 },
60
+ null,
61
+ [],
62
+ retries
63
+ )
59
64
 
60
65
  expect(response).toEqual([])
61
66
  // it should fail 2 times and succeed on the next try
@@ -74,7 +79,10 @@ describe('EVM Family', () => {
74
79
  return { data: { data: [] } }
75
80
  })
76
81
  try {
77
- await LEDGER_API.fetchPaginatedOpsWithRetries({} as any, null)
82
+ await LEDGER_API.fetchPaginatedOpsWithRetries(
83
+ { explorerId: 'test', address: '0x', fromBlock: 0, batchSize: 10 },
84
+ null
85
+ )
78
86
  fail('Promise should have been rejected')
79
87
  } catch (e) {
80
88
  if (e instanceof AssertionError) {
@@ -113,7 +121,10 @@ describe('EVM Family', () => {
113
121
  }
114
122
  })
115
123
 
116
- const response = await LEDGER_API.fetchPaginatedOpsWithRetries({} as any, null)
124
+ const response = await LEDGER_API.fetchPaginatedOpsWithRetries(
125
+ { explorerId: 'test', address: '0x', fromBlock: 0, batchSize: 10 },
126
+ null
127
+ )
117
128
 
118
129
  expect(response).toEqual([coinOperation1, coinOperation2, coinOperation3])
119
130
  })
@@ -1,18 +1,24 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo } from '../../config'
4
+ import {
5
+ createMockEvmConfigInfo,
6
+ mkLedgerGasTracker,
7
+ mkLedgerNode,
8
+ } from '../../fixtures/context.fixtures'
5
9
  import { getGasOptions as ledgerGetGasOptions } from './ledger'
6
10
  import { getGasTracker } from './index'
7
11
 
8
- const configWithGasTracker = {
9
- node: { type: 'ledger', explorerId: 'eth' },
10
- gasTracker: { type: 'ledger', explorerId: 'eth' },
11
- } as unknown as EvmConfigInfo
12
+ const configWithGasTracker = createMockEvmConfigInfo({
13
+ chainId: 1,
14
+ node: mkLedgerNode({ explorerId: 'eth' }),
15
+ gasTracker: mkLedgerGasTracker({ explorerId: 'eth' }),
16
+ })
12
17
 
13
- const configWithoutGasTracker = {
14
- node: { type: 'ledger', explorerId: 'eth' },
15
- } as unknown as EvmConfigInfo
18
+ const configWithoutGasTracker = createMockEvmConfigInfo({
19
+ chainId: 1,
20
+ node: mkLedgerNode({ explorerId: 'eth' }),
21
+ })
16
22
 
17
23
  describe('EVM Family', () => {
18
24
  describe('network/gasTracker/index.ts', () => {
@@ -1,24 +1,28 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo } from '../../config'
5
4
  import type { GasOptions } from '../../types'
6
5
  import { AssertionError } from 'assert'
7
6
  import network from '@ledgerhq/live-network/network'
8
7
  import BigNumber from 'bignumber.js'
9
8
  import { LedgerGasTrackerUsedIncorrectly, NoGasTrackerFound } from '../../errors'
9
+ import {
10
+ createMockEvmConfigInfo,
11
+ mkExternalNode,
12
+ mkLedgerGasTracker,
13
+ mkLedgerNode,
14
+ } from '../../fixtures/context.fixtures'
10
15
  import { getGasOptions } from './ledger'
11
16
 
12
17
  jest.mock('@ledgerhq/live-network/network')
13
18
  const mockedNetwork = jest.mocked(network)
14
19
 
15
- const TEST_EIP1559_BASE_FEE_MULTIPLIER = 2
16
-
17
- const ledgerGasTrackerConfig = {
18
- node: { type: 'ledger', explorerId: 'eth' },
19
- gasTracker: { type: 'ledger', explorerId: 'eth' },
20
- eip1559BaseFeeMultiplier: TEST_EIP1559_BASE_FEE_MULTIPLIER,
21
- } as unknown as EvmConfigInfo
20
+ const ledgerGasTrackerConfig = createMockEvmConfigInfo({
21
+ chainId: 1,
22
+ node: mkLedgerNode({ explorerId: 'eth' }),
23
+ gasTracker: mkLedgerGasTracker({ explorerId: 'eth' }),
24
+ eip1559BaseFeeMultiplier: 2,
25
+ })
22
26
 
23
27
  describe('EVM Family', () => {
24
28
  describe('network/gasTracker/index.ts', () => {
@@ -139,7 +143,7 @@ describe('EVM Family', () => {
139
143
  it('should use overrideGasTracker', async () => {
140
144
  await getGasOptions({
141
145
  currencyId: 'ethereum',
142
- config: { gasTracker: { type: 'other', explorerId: 'anything' } } as any,
146
+ config: createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
143
147
  options: {
144
148
  useEIP1559: true,
145
149
  overrideGasTracker: { type: 'ledger', explorerId: 'eth_sepolia' },
@@ -190,7 +194,11 @@ describe('EVM Family', () => {
190
194
  it('should return legacy gas options when EIP-1559 not supported by gas tracker', async () => {
191
195
  const gasOptions: GasOptions = await getGasOptions({
192
196
  currencyId: 'ethereum_classic',
193
- config: { gasTracker: { type: 'ledger', explorerId: 'etc' } } as any,
197
+ config: createMockEvmConfigInfo({
198
+ chainId: 1,
199
+ node: mkExternalNode(),
200
+ gasTracker: mkLedgerGasTracker({ explorerId: 'etc' }),
201
+ }),
194
202
  options: { useEIP1559: true },
195
203
  })
196
204
 
@@ -252,7 +260,7 @@ describe('EVM Family', () => {
252
260
  it('should use overrideGasTracker', async () => {
253
261
  await getGasOptions({
254
262
  currencyId: 'ethereum',
255
- config: { gasTracker: { type: 'other', explorerId: 'anything' } } as any,
263
+ config: createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
256
264
  options: {
257
265
  useEIP1559: false,
258
266
  overrideGasTracker: { type: 'ledger', explorerId: 'eth_sepolia' },
@@ -270,7 +278,7 @@ describe('EVM Family', () => {
270
278
  try {
271
279
  await getGasOptions({
272
280
  currencyId: 'ethereum',
273
- config: { gasTracker: { type: 'wrong', explorerId: 'anything' } } as any,
281
+ config: createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
274
282
  })
275
283
  fail('Promise should have been rejected')
276
284
  } catch (e) {
@@ -285,7 +293,11 @@ describe('EVM Family', () => {
285
293
  try {
286
294
  await getGasOptions({
287
295
  currencyId: 'ethereum',
288
- config: { gasTracker: { type: 'ledger', explorerId: 'anything' } } as any,
296
+ config: createMockEvmConfigInfo({
297
+ chainId: 1,
298
+ node: mkExternalNode(),
299
+ gasTracker: mkLedgerGasTracker({ explorerId: 'anything' }),
300
+ }),
289
301
  })
290
302
  fail('Promise should have been rejected')
291
303
  } catch (e) {
@@ -1,57 +1,51 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo } from '../../config'
4
+ import { createMockEvmConfigInfo, mkExternalNode } from '../../fixtures/context.fixtures'
5
5
  import { getNodeApi } from './index'
6
6
 
7
- const externalNodeConfig = (): EvmConfigInfo =>
8
- ({ node: { type: 'external', uri: 'working' } }) as unknown as EvmConfigInfo
9
-
10
7
  describe('getNodeApi memoization', () => {
11
8
  it('should return the same NodeApi instance for same currency and retries (memoization)', () => {
12
- const node1 = getNodeApi(externalNodeConfig(), 'ethereum')
13
- const node2 = getNodeApi(externalNodeConfig(), 'ethereum')
14
-
15
- expect(node1).toBe(node2)
9
+ const config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
10
+ expect(getNodeApi(config, 'ethereum')).toBe(getNodeApi(config, 'ethereum'))
16
11
  })
17
12
 
18
13
  it('should return cached NodeApi on subsequent calls (createNodeApi called once)', () => {
19
- const cachedInstance = getNodeApi(externalNodeConfig(), 'cached_value_test')
20
- const second = getNodeApi(externalNodeConfig(), 'cached_value_test')
21
- const third = getNodeApi(externalNodeConfig(), 'cached_value_test')
14
+ const config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
15
+ const cachedInstance = getNodeApi(config, 'cached_value_test')
22
16
 
23
- expect(second).toBe(cachedInstance)
24
- expect(third).toBe(cachedInstance)
17
+ expect(getNodeApi(config, 'cached_value_test')).toBe(cachedInstance)
18
+ expect(getNodeApi(config, 'cached_value_test')).toBe(cachedInstance)
25
19
  })
26
20
 
27
- function generateConfig(node: { type: string; uri: string; retries: number }): EvmConfigInfo {
28
- return { node } as unknown as EvmConfigInfo
29
- }
30
21
  it('should return different NodeApi instances for different retries', () => {
31
- const nodeConf1 = { type: 'external', uri: 'u', retries: 2 }
32
- const node1 = getNodeApi(generateConfig(nodeConf1), 'ethereum')
33
-
34
- const nodeConf2 = { ...nodeConf1, retries: 5 }
35
- const node2 = getNodeApi(generateConfig(nodeConf2), 'ethereum')
22
+ const node1 = getNodeApi(
23
+ createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'u', retries: 2 }) }),
24
+ 'ethereum'
25
+ )
26
+ const node2 = getNodeApi(
27
+ createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'u', retries: 5 }) }),
28
+ 'ethereum'
29
+ )
36
30
  expect(node1).not.toBe(node2)
37
31
  })
38
32
 
39
33
  it('should return different NodeApi instances for different uris', () => {
40
- const nodeConf1 = { type: 'external', uri: 'u1', retries: 2 }
41
- const node1 = getNodeApi(generateConfig(nodeConf1), 'ethereum')
42
-
43
- const nodeConf2 = { ...nodeConf1, uri: 'u2' }
44
- const node2 = getNodeApi(generateConfig(nodeConf2), 'ethereum')
34
+ const node1 = getNodeApi(
35
+ createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'u1' }) }),
36
+ 'ethereum'
37
+ )
38
+ const node2 = getNodeApi(
39
+ createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'u2' }) }),
40
+ 'ethereum'
41
+ )
45
42
 
46
43
  expect(node1).not.toBe(node2)
47
44
  })
48
45
 
49
46
  it('should return different NodeApi instances for different currencies', () => {
50
- const conf = generateConfig({ type: 'external', uri: 'u1', retries: 2 })
51
-
52
- const node1 = getNodeApi(conf, 'ethereum1')
53
- const node2 = getNodeApi(conf, 'ethereum2')
47
+ const conf = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'u1' }) })
54
48
 
55
- expect(node1).not.toBe(node2)
49
+ expect(getNodeApi(conf, 'ethereum1')).not.toBe(getNodeApi(conf, 'ethereum2'))
56
50
  })
57
51
  })
@@ -1,36 +1,27 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { AssertionError, fail } from 'assert'
5
4
  import { UnknownNode } from '../../errors'
5
+ import {
6
+ createMockEvmConfigInfo,
7
+ mkExternalNode,
8
+ mkLedgerNode,
9
+ } from '../../fixtures/context.fixtures'
6
10
  import { getNodeApi } from './index'
7
11
 
8
12
  describe('EVM Family', () => {
9
13
  describe('network/node/index.ts', () => {
10
14
  describe('getNodeApi', () => {
11
- it('should throw when requesting a non existing node type', async () => {
12
- try {
13
- getNodeApi(
14
- {
15
- node: { type: 'anything', uri: 'notworking' },
16
- } as any,
17
- { id: 'not-existing' } as any
18
- )
19
- fail('Promise should have been rejected')
20
- } catch (e) {
21
- if (e instanceof AssertionError) {
22
- throw e
23
- }
24
- expect(e).toBeInstanceOf(UnknownNode)
25
- }
15
+ it('should throw when requesting a non existing node type', () => {
16
+ const config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
17
+ Object.assign(config, { node: { type: 'anything', uri: 'notworking' } })
18
+ expect(() => getNodeApi(config, 'not-existing')).toThrow(UnknownNode)
26
19
  })
27
20
 
28
- it('should return the rpc api', async () => {
21
+ it('should return the rpc api', () => {
29
22
  const node = getNodeApi(
30
- {
31
- node: { type: 'external', uri: 'working' },
32
- } as any,
33
- { id: 'external' } as any
23
+ createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'working' }) }),
24
+ 'external'
34
25
  )
35
26
 
36
27
  expect(node).toEqual(
@@ -50,10 +41,8 @@ describe('EVM Family', () => {
50
41
 
51
42
  it('should return the ledger api', () => {
52
43
  const node = getNodeApi(
53
- {
54
- node: { type: 'ledger', explorerId: 'eth' },
55
- } as any,
56
- { id: 'ledger-supported' } as any
44
+ createMockEvmConfigInfo({ chainId: 1, node: mkLedgerNode({ explorerId: 'eth' }) }),
45
+ 'ledger-supported'
57
46
  )
58
47
 
59
48
  expect(node).toEqual(
@@ -1,13 +1,13 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { AssertionError, fail } from 'assert'
5
4
  import { delay } from '@ledgerhq/coin-module-framework/promises'
6
5
  import axios from 'axios'
7
6
  import BigNumber from 'bignumber.js'
8
7
  import { Transaction } from 'ethers'
9
8
  import { DEFAULT_LEDGER_EXPLORER_URI } from '../../config'
10
9
  import { GasEstimationError } from '../../errors'
10
+ import { createMockEvmConfigInfo } from '../../fixtures/context.fixtures'
11
11
  import { getGasOptions } from '../gasTracker/ledger'
12
12
  import { createLedgerNodeApi } from './ledger'
13
13
 
@@ -19,9 +19,9 @@ jest.mock('../gasTracker/ledger', () => ({
19
19
  getGasOptions: jest.fn(),
20
20
  }))
21
21
 
22
- const mockGetGasOptions = getGasOptions as jest.Mock
22
+ const mockGetGasOptions = jest.mocked(getGasOptions)
23
23
 
24
- ;(delay as jest.Mock).mockImplementation(
24
+ jest.mocked(delay).mockImplementation(
25
25
  () => new Promise((resolve) => setTimeout(resolve, 1)) // mocking the delay supposed to happen after each try
26
26
  )
27
27
 
@@ -149,15 +149,7 @@ describe('EVM Family', () => {
149
149
  }
150
150
  return { data: {} }
151
151
  })
152
- try {
153
- await api.getTransaction(currencyId, '0xHash')
154
- fail('Promise should have been rejected')
155
- } catch (e) {
156
- if (e instanceof AssertionError) {
157
- throw e
158
- }
159
- expect(e).toBeInstanceOf(SpyError)
160
- }
152
+ await expect(api.getTransaction(currencyId, '0xHash')).rejects.toBeInstanceOf(SpyError)
161
153
  })
162
154
  })
163
155
 
@@ -290,15 +282,9 @@ describe('EVM Family', () => {
290
282
  throw new Error()
291
283
  })
292
284
 
293
- try {
294
- await api.getGasEstimation(currencyId, address, {} as any)
295
- fail('Promise should have been rejected')
296
- } catch (e) {
297
- if (e instanceof AssertionError) {
298
- throw e
299
- }
300
- expect(e).toBeInstanceOf(GasEstimationError)
301
- }
285
+ await expect(
286
+ api.getGasEstimation(currencyId, address, { amount: new BigNumber(0), recipient: '0x0' })
287
+ ).rejects.toBeInstanceOf(GasEstimationError)
302
288
  })
303
289
 
304
290
  it('should throw GasEstimationError if request throws ECONNABORTED', async () => {
@@ -307,34 +293,17 @@ describe('EVM Family', () => {
307
293
  .spyOn(axios, 'request')
308
294
  .mockImplementation(() => Promise.reject({ code: 'ECONNABORTED' }))
309
295
 
310
- try {
311
- await api.getGasEstimation(currencyId, address, {} as any)
312
- fail('Promise should have been rejected')
313
- } catch (e) {
314
- if (e instanceof AssertionError) {
315
- throw e
316
- }
317
- expect(e).toBeInstanceOf(GasEstimationError)
318
- }
296
+ await expect(
297
+ api.getGasEstimation(currencyId, address, { amount: new BigNumber(0), recipient: '0x0' })
298
+ ).rejects.toBeInstanceOf(GasEstimationError)
319
299
  })
320
300
 
321
301
  it('should return the expected payload', async () => {
322
302
  const api = createLedgerNodeApi(ledgerConfig)
323
- jest.spyOn(axios, 'request').mockImplementation(async ({ data: transaction }) => {
324
- return (transaction as any)?.data?.length > 2
325
- ? {
326
- data: {
327
- to: '0xBob',
328
- estimated_gas_limit: '1000000',
329
- },
330
- }
331
- : {
332
- data: {
333
- to: '0xBob',
334
- estimated_gas_limit: '789',
335
- },
336
- }
337
- })
303
+ jest
304
+ .spyOn(axios, 'request')
305
+ .mockResolvedValueOnce({ data: { to: '0xBob', estimated_gas_limit: '789' } })
306
+ .mockResolvedValueOnce({ data: { to: '0xBob', estimated_gas_limit: '1000000' } })
338
307
 
339
308
  const transaction = {
340
309
  family: 'evm',
@@ -385,18 +354,30 @@ describe('EVM Family', () => {
385
354
  },
386
355
  }))
387
356
 
388
- const slowFeeData = await api.getFeeData({} as any, currencyId, {
389
- type: 2,
390
- feesStrategy: 'slow',
391
- } as any)
392
- const mediumFeeData = await api.getFeeData({} as any, currencyId, {
393
- type: 2,
394
- feesStrategy: 'medium',
395
- } as any)
396
- const fastFeeData = await api.getFeeData({} as any, currencyId, {
397
- type: 2,
398
- feesStrategy: 'fast',
399
- })
357
+ const slowFeeData = await api.getFeeData(
358
+ createMockEvmConfigInfo({ chainId: 1, node: ledgerConfig }),
359
+ currencyId,
360
+ {
361
+ type: 2,
362
+ feesStrategy: 'slow',
363
+ }
364
+ )
365
+ const mediumFeeData = await api.getFeeData(
366
+ createMockEvmConfigInfo({ chainId: 1, node: ledgerConfig }),
367
+ currencyId,
368
+ {
369
+ type: 2,
370
+ feesStrategy: 'medium',
371
+ }
372
+ )
373
+ const fastFeeData = await api.getFeeData(
374
+ createMockEvmConfigInfo({ chainId: 1, node: ledgerConfig }),
375
+ currencyId,
376
+ {
377
+ type: 2,
378
+ feesStrategy: 'fast',
379
+ }
380
+ )
400
381
 
401
382
  expect(slowFeeData).toEqual({
402
383
  maxFeePerGas: new BigNumber(1),
@@ -441,7 +422,11 @@ describe('EVM Family', () => {
441
422
  },
442
423
  }))
443
424
 
444
- const feeData = await api.getFeeData({} as any, currencyId, { type: 2 } as any)
425
+ const feeData = await api.getFeeData(
426
+ createMockEvmConfigInfo({ chainId: 1, node: ledgerConfig }),
427
+ currencyId,
428
+ { type: 2 }
429
+ )
445
430
 
446
431
  expect(feeData).toEqual({
447
432
  maxFeePerGas: new BigNumber(5),
@@ -579,7 +564,7 @@ describe('EVM Family', () => {
579
564
  describe('getOptimismAdditionalFees', () => {
580
565
  it('should return 0 for an incompatible currency', async () => {
581
566
  const api = createLedgerNodeApi(ledgerConfig)
582
- expect(await api.getOptimismAdditionalFees(currencyId, {} as any)).toEqual(new BigNumber(0))
567
+ expect(await api.getOptimismAdditionalFees(currencyId, '')).toEqual(new BigNumber(0))
583
568
  })
584
569
 
585
570
  it('should return the expected payload', async () => {
@@ -659,7 +644,7 @@ describe('EVM Family', () => {
659
644
  describe('getScrollAdditionalFees', () => {
660
645
  it('should return 0 for an incompatible currency', async () => {
661
646
  const api = createLedgerNodeApi(ledgerConfig)
662
- expect(await api.getScrollAdditionalFees(currencyId, {} as any)).toEqual(new BigNumber(0))
647
+ expect(await api.getScrollAdditionalFees(currencyId, '')).toEqual(new BigNumber(0))
663
648
  })
664
649
 
665
650
  it('should return the expected payload', async () => {
@@ -15,8 +15,6 @@ export function mockNodeApi(overrides: Partial<jest.Mocked<NodeApi>> = {}): jest
15
15
  broadcastTransaction: jest.fn(),
16
16
  getBlockByHeight: jest.fn(),
17
17
  getBlockReceipts: jest.fn(),
18
- traceBlockErigon: jest.fn(),
19
- traceBlockGeth: jest.fn(),
20
18
  getOptimismAdditionalFees: jest.fn(),
21
19
  getScrollAdditionalFees: jest.fn(),
22
20
  ...overrides,