@ledgerhq/coin-evm 5.3.1 → 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 (255) hide show
  1. package/.oxlintrc.json +3 -13
  2. package/CHANGELOG.md +13 -0
  3. package/lib/adapters/blockOperations.d.ts +2 -2
  4. package/lib/adapters/blockOperations.d.ts.map +1 -1
  5. package/lib/adapters/blockOperations.js.map +1 -1
  6. package/lib/api/index.d.ts +1 -1
  7. package/lib/api/index.d.ts.map +1 -1
  8. package/lib/config.d.ts +1 -1
  9. package/lib/config.d.ts.map +1 -1
  10. package/lib/logic/combine.d.ts +2 -1
  11. package/lib/logic/combine.d.ts.map +1 -1
  12. package/lib/logic/combine.js.map +1 -1
  13. package/lib/logic/common.d.ts +2 -1
  14. package/lib/logic/common.d.ts.map +1 -1
  15. package/lib/logic/common.js.map +1 -1
  16. package/lib/logic/craftTransaction.d.ts +1 -1
  17. package/lib/logic/craftTransaction.d.ts.map +1 -1
  18. package/lib/logic/craftTransaction.js.map +1 -1
  19. package/lib/logic/craftTransactionData.d.ts +1 -1
  20. package/lib/logic/craftTransactionData.d.ts.map +1 -1
  21. package/lib/logic/estimateFees.d.ts +1 -1
  22. package/lib/logic/estimateFees.d.ts.map +1 -1
  23. package/lib/logic/estimateFees.js.map +1 -1
  24. package/lib/logic/getBalance.d.ts +1 -1
  25. package/lib/logic/getBalance.d.ts.map +1 -1
  26. package/lib/logic/getBalance.js.map +1 -1
  27. package/lib/logic/getBlock.d.ts +1 -1
  28. package/lib/logic/getBlock.d.ts.map +1 -1
  29. package/lib/logic/getBlock.js.map +1 -1
  30. package/lib/logic/getStakes.d.ts +1 -1
  31. package/lib/logic/getStakes.d.ts.map +1 -1
  32. package/lib/logic/internalTransactionsFetcher.d.ts +1 -1
  33. package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
  34. package/lib/logic/internalTransactionsFetcher.js.map +1 -1
  35. package/lib/logic/validateIntent.d.ts +1 -1
  36. package/lib/logic/validateIntent.d.ts.map +1 -1
  37. package/lib/logic/validateIntent.js.map +1 -1
  38. package/lib/logic.d.ts +1 -1
  39. package/lib/logic.d.ts.map +1 -1
  40. package/lib/network/explorer/etherscan.d.ts +4 -4
  41. package/lib/network/explorer/etherscan.d.ts.map +1 -1
  42. package/lib/network/explorer/etherscan.js.map +1 -1
  43. package/lib/network/explorer/index.d.ts +2 -2
  44. package/lib/network/explorer/index.d.ts.map +1 -1
  45. package/lib/network/explorer/index.js.map +1 -1
  46. package/lib/network/explorer/ledger.d.ts +2 -2
  47. package/lib/network/explorer/ledger.d.ts.map +1 -1
  48. package/lib/network/explorer/ledger.js.map +1 -1
  49. package/lib/network/explorer/none.d.ts +1 -1
  50. package/lib/network/explorer/none.d.ts.map +1 -1
  51. package/lib/network/explorer/none.js.map +1 -1
  52. package/lib/network/explorer/types.d.ts +1 -1
  53. package/lib/network/explorer/types.d.ts.map +1 -1
  54. package/lib/network/gasTracker/index.d.ts +2 -2
  55. package/lib/network/gasTracker/index.d.ts.map +1 -1
  56. package/lib/network/gasTracker/index.js.map +1 -1
  57. package/lib/network/gasTracker/ledger.d.ts +3 -3
  58. package/lib/network/gasTracker/ledger.d.ts.map +1 -1
  59. package/lib/network/gasTracker/ledger.js.map +1 -1
  60. package/lib/network/gasTracker/types.d.ts +2 -2
  61. package/lib/network/gasTracker/types.d.ts.map +1 -1
  62. package/lib/network/node/ledger.d.ts +2 -2
  63. package/lib/network/node/ledger.d.ts.map +1 -1
  64. package/lib/network/node/ledger.js.map +1 -1
  65. package/lib/network/node/rpc.common.d.ts +1 -1
  66. package/lib/network/node/rpc.common.d.ts.map +1 -1
  67. package/lib/network/node/rpc.common.js.map +1 -1
  68. package/lib/network/node/types.d.ts +3 -3
  69. package/lib/network/node/types.d.ts.map +1 -1
  70. package/lib/staking/validators/monad.d.ts +2 -1
  71. package/lib/staking/validators/monad.d.ts.map +1 -1
  72. package/lib/staking/validators/monad.js.map +1 -1
  73. package/lib/staking/validators/monadResolver.d.ts +2 -1
  74. package/lib/staking/validators/monadResolver.d.ts.map +1 -1
  75. package/lib/staking/validators/monadResolver.js.map +1 -1
  76. package/lib/staking/validators/somnia.d.ts.map +1 -1
  77. package/lib/staking/validators/somnia.js.map +1 -1
  78. package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
  79. package/lib/staking/validators/zero_gravity.js.map +1 -1
  80. package/lib/types/assets.d.ts +1 -1
  81. package/lib/types/assets.d.ts.map +1 -1
  82. package/lib/types/transaction.d.ts +1 -1
  83. package/lib/types/transaction.d.ts.map +1 -1
  84. package/lib-es/adapters/blockOperations.d.ts +2 -2
  85. package/lib-es/adapters/blockOperations.d.ts.map +1 -1
  86. package/lib-es/adapters/blockOperations.js.map +1 -1
  87. package/lib-es/api/index.d.ts +1 -1
  88. package/lib-es/api/index.d.ts.map +1 -1
  89. package/lib-es/config.d.ts +1 -1
  90. package/lib-es/config.d.ts.map +1 -1
  91. package/lib-es/logic/combine.d.ts +2 -1
  92. package/lib-es/logic/combine.d.ts.map +1 -1
  93. package/lib-es/logic/combine.js.map +1 -1
  94. package/lib-es/logic/common.d.ts +2 -1
  95. package/lib-es/logic/common.d.ts.map +1 -1
  96. package/lib-es/logic/common.js +1 -1
  97. package/lib-es/logic/common.js.map +1 -1
  98. package/lib-es/logic/craftTransaction.d.ts +1 -1
  99. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  100. package/lib-es/logic/craftTransaction.js.map +1 -1
  101. package/lib-es/logic/craftTransactionData.d.ts +1 -1
  102. package/lib-es/logic/craftTransactionData.d.ts.map +1 -1
  103. package/lib-es/logic/estimateFees.d.ts +1 -1
  104. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  105. package/lib-es/logic/estimateFees.js.map +1 -1
  106. package/lib-es/logic/getBalance.d.ts +1 -1
  107. package/lib-es/logic/getBalance.d.ts.map +1 -1
  108. package/lib-es/logic/getBalance.js.map +1 -1
  109. package/lib-es/logic/getBlock.d.ts +1 -1
  110. package/lib-es/logic/getBlock.d.ts.map +1 -1
  111. package/lib-es/logic/getBlock.js.map +1 -1
  112. package/lib-es/logic/getStakes.d.ts +1 -1
  113. package/lib-es/logic/getStakes.d.ts.map +1 -1
  114. package/lib-es/logic/internalTransactionsFetcher.d.ts +1 -1
  115. package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
  116. package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
  117. package/lib-es/logic/validateIntent.d.ts +1 -1
  118. package/lib-es/logic/validateIntent.d.ts.map +1 -1
  119. package/lib-es/logic/validateIntent.js.map +1 -1
  120. package/lib-es/logic.d.ts +1 -1
  121. package/lib-es/logic.d.ts.map +1 -1
  122. package/lib-es/network/explorer/etherscan.d.ts +4 -4
  123. package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
  124. package/lib-es/network/explorer/etherscan.js.map +1 -1
  125. package/lib-es/network/explorer/index.d.ts +2 -2
  126. package/lib-es/network/explorer/index.d.ts.map +1 -1
  127. package/lib-es/network/explorer/index.js.map +1 -1
  128. package/lib-es/network/explorer/ledger.d.ts +2 -2
  129. package/lib-es/network/explorer/ledger.d.ts.map +1 -1
  130. package/lib-es/network/explorer/ledger.js.map +1 -1
  131. package/lib-es/network/explorer/none.d.ts +1 -1
  132. package/lib-es/network/explorer/none.d.ts.map +1 -1
  133. package/lib-es/network/explorer/none.js.map +1 -1
  134. package/lib-es/network/explorer/types.d.ts +1 -1
  135. package/lib-es/network/explorer/types.d.ts.map +1 -1
  136. package/lib-es/network/gasTracker/index.d.ts +2 -2
  137. package/lib-es/network/gasTracker/index.d.ts.map +1 -1
  138. package/lib-es/network/gasTracker/index.js.map +1 -1
  139. package/lib-es/network/gasTracker/ledger.d.ts +3 -3
  140. package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
  141. package/lib-es/network/gasTracker/ledger.js +1 -1
  142. package/lib-es/network/gasTracker/ledger.js.map +1 -1
  143. package/lib-es/network/gasTracker/types.d.ts +2 -2
  144. package/lib-es/network/gasTracker/types.d.ts.map +1 -1
  145. package/lib-es/network/node/ledger.d.ts +2 -2
  146. package/lib-es/network/node/ledger.d.ts.map +1 -1
  147. package/lib-es/network/node/ledger.js.map +1 -1
  148. package/lib-es/network/node/rpc.common.d.ts +1 -1
  149. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  150. package/lib-es/network/node/rpc.common.js +1 -1
  151. package/lib-es/network/node/rpc.common.js.map +1 -1
  152. package/lib-es/network/node/types.d.ts +3 -3
  153. package/lib-es/network/node/types.d.ts.map +1 -1
  154. package/lib-es/staking/validators/monad.d.ts +2 -1
  155. package/lib-es/staking/validators/monad.d.ts.map +1 -1
  156. package/lib-es/staking/validators/monad.js.map +1 -1
  157. package/lib-es/staking/validators/monadResolver.d.ts +2 -1
  158. package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
  159. package/lib-es/staking/validators/monadResolver.js.map +1 -1
  160. package/lib-es/staking/validators/somnia.d.ts.map +1 -1
  161. package/lib-es/staking/validators/somnia.js.map +1 -1
  162. package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
  163. package/lib-es/staking/validators/zero_gravity.js.map +1 -1
  164. package/lib-es/types/assets.d.ts +1 -1
  165. package/lib-es/types/assets.d.ts.map +1 -1
  166. package/lib-es/types/transaction.d.ts +1 -1
  167. package/lib-es/types/transaction.d.ts.map +1 -1
  168. package/package.json +2 -2
  169. package/src/adapters/blockOperations.test.ts +29 -31
  170. package/src/adapters/blockOperations.ts +3 -2
  171. package/src/adapters/etherscan.test.ts +7 -7
  172. package/src/adapters/ledger.test.ts +2 -2
  173. package/src/api/getBlock.integ.test.ts +1 -1
  174. package/src/api/index.fantom.integ.test.ts +1 -1
  175. package/src/api/index.flare.integ.test.ts +2 -14
  176. package/src/api/index.integ.test.ts +330 -246
  177. package/src/api/index.linea.integ.test.ts +1 -1
  178. package/src/api/index.optimism.integ.test.ts +1 -1
  179. package/src/api/index.shape.integ.test.ts +1 -1
  180. package/src/api/index.ts +1 -1
  181. package/src/config.ts +1 -1
  182. package/src/fixtures/context.fixtures.ts +79 -1
  183. package/src/fixtures/ethers.fixtures.ts +26 -0
  184. package/src/fixtures/ledger.fixtures.ts +1 -1
  185. package/src/internalTxSources.test.ts +3 -6
  186. package/src/logic/broadcast.integ.test.ts +6 -18
  187. package/src/logic/broadcast.test.ts +19 -31
  188. package/src/logic/broadcastSource.test.ts +6 -7
  189. package/src/logic/combine.test.ts +2 -2
  190. package/src/logic/combine.ts +2 -1
  191. package/src/logic/common.test.ts +120 -112
  192. package/src/logic/common.ts +2 -7
  193. package/src/logic/craftTransaction.test.ts +163 -200
  194. package/src/logic/craftTransaction.ts +3 -2
  195. package/src/logic/craftTransactionData.test.ts +6 -6
  196. package/src/logic/craftTransactionData.ts +1 -1
  197. package/src/logic/estimateFees.test.ts +19 -15
  198. package/src/logic/estimateFees.ts +6 -3
  199. package/src/logic/getBalance.test.ts +16 -15
  200. package/src/logic/getBalance.ts +4 -3
  201. package/src/logic/getBlock.test.ts +379 -388
  202. package/src/logic/getBlock.ts +3 -2
  203. package/src/logic/getBlockInfo.test.ts +7 -9
  204. package/src/logic/getNextSequence.test.ts +5 -5
  205. package/src/logic/getStakes.test.ts +35 -35
  206. package/src/logic/getStakes.ts +1 -1
  207. package/src/logic/internalTransactionsFetcher.test.ts +26 -24
  208. package/src/logic/internalTransactionsFetcher.ts +1 -1
  209. package/src/logic/lastBlock.test.ts +29 -20
  210. package/src/logic/listOperations.test.ts +44 -40
  211. package/src/logic/validateIntent.test.ts +152 -101
  212. package/src/logic/validateIntent.ts +4 -2
  213. package/src/logic.test.ts +13 -18
  214. package/src/logic.ts +1 -1
  215. package/src/network/explorer/etherscan.test.ts +6 -6
  216. package/src/network/explorer/etherscan.ts +12 -10
  217. package/src/network/explorer/index.test.ts +52 -22
  218. package/src/network/explorer/index.ts +2 -2
  219. package/src/network/explorer/ledger.test.ts +17 -5
  220. package/src/network/explorer/ledger.ts +3 -2
  221. package/src/network/explorer/none.ts +2 -1
  222. package/src/network/explorer/types.ts +1 -1
  223. package/src/network/gasTracker/index.test.ts +14 -8
  224. package/src/network/gasTracker/index.ts +2 -2
  225. package/src/network/gasTracker/ledger.test.ts +34 -29
  226. package/src/network/gasTracker/ledger.ts +5 -7
  227. package/src/network/gasTracker/types.ts +2 -2
  228. package/src/network/node/index.memoization.test.ts +25 -31
  229. package/src/network/node/index.test.ts +14 -25
  230. package/src/network/node/ledger.test.ts +45 -60
  231. package/src/network/node/ledger.ts +6 -5
  232. package/src/network/node/node.fixtures.ts +0 -2
  233. package/src/network/node/rpc.common.ts +14 -14
  234. package/src/network/node/rpc.test.ts +153 -184
  235. package/src/network/node/types.ts +3 -3
  236. package/src/staking/detectOperationType.test.ts +1 -1
  237. package/src/staking/encoder.test.ts +14 -22
  238. package/src/staking/logic.test.ts +20 -14
  239. package/src/staking/operations/index.test.ts +29 -29
  240. package/src/staking/prepareIntents.test.ts +26 -20
  241. package/src/staking/redelegations.test.ts +50 -33
  242. package/src/staking/rewards.test.ts +29 -17
  243. package/src/staking/rewardsFromReceipt.test.ts +20 -21
  244. package/src/staking/transactionData.test.ts +23 -23
  245. package/src/staking/validators/monad.test.ts +65 -24
  246. package/src/staking/validators/monad.ts +2 -1
  247. package/src/staking/validators/monadResolver.ts +2 -1
  248. package/src/staking/validators/somnia.test.ts +21 -13
  249. package/src/staking/validators/somnia.ts +2 -1
  250. package/src/staking/validators/zero_gravity.test.ts +118 -48
  251. package/src/staking/validators/zero_gravity.ts +2 -1
  252. package/src/staking/validators.integ.test.ts +13 -25
  253. package/src/staking/validators.test.ts +7 -2
  254. package/src/types/assets.ts +1 -1
  255. package/src/types/transaction.ts +1 -1
@@ -1,20 +1,17 @@
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 BigNumber from 'bignumber.js'
7
- import {
8
- FetchRequest,
9
- JsonRpcProvider,
10
- Network,
11
- Transaction,
12
- TransactionReceipt,
13
- TransactionResponse,
14
- ethers,
15
- } from 'ethers'
16
- import { EvmConfigInfo, getCoinConfig } from '../../config'
6
+ import { FeeData, FetchRequest, JsonRpcProvider, Network, Transaction } from 'ethers'
7
+ import { getCoinConfig } from '../../config'
17
8
  import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors'
9
+ import { createMockEvmConfigInfo, mkExternalNode } from '../../fixtures/context.fixtures'
10
+ import {
11
+ mkBlock,
12
+ mkTransactionReceipt,
13
+ mkTransactionResponse,
14
+ } from '../../fixtures/ethers.fixtures'
18
15
  import {
19
16
  createNodeApi,
20
17
  DEFAULT_RETRIES_RPC_METHODS,
@@ -28,11 +25,11 @@ import {
28
25
 
29
26
  const currencyId = 'my_new_chain'
30
27
 
31
- const evmConfig = {
28
+ const evmConfig = createMockEvmConfigInfo({
32
29
  chainId: 1,
33
30
  name: 'My New Chain',
34
- node: { type: 'external', uri: 'http://test' },
35
- } as EvmConfigInfo
31
+ node: mkExternalNode({ uri: 'http://test' }),
32
+ })
36
33
 
37
34
  const nodeApi = createNodeApi(evmConfig, {
38
35
  type: 'external',
@@ -50,7 +47,7 @@ const now = Math.floor(Date.now() / 1000)
50
47
  const address = '0x6cBCD73CD8e8a42844662f0A0e76D7F79Afd933d'
51
48
 
52
49
  jest.mock('@ledgerhq/coin-module-framework/promises')
53
- ;(delay as jest.Mock).mockImplementation(
50
+ jest.mocked(delay).mockImplementation(
54
51
  () => new Promise((resolve) => setTimeout(resolve, 1)) // mocking the delay supposed to happen after each try
55
52
  )
56
53
 
@@ -61,9 +58,7 @@ describe('EVM Family', () => {
61
58
 
62
59
  beforeEach(() => {
63
60
  jest.resetAllMocks()
64
- jest
65
- .spyOn(JsonRpcProvider.prototype as any, '_detectNetwork')
66
- .mockResolvedValue(Network.from(1))
61
+ jest.spyOn(JsonRpcProvider.prototype, '_detectNetwork').mockResolvedValue(Network.from(1))
67
62
 
68
63
  mockGetConfig.mockImplementation((): any => {
69
64
  return {
@@ -76,66 +71,66 @@ describe('EVM Family', () => {
76
71
  }
77
72
  })
78
73
 
79
- jest.spyOn(JsonRpcProvider.prototype, 'getFeeData').mockResolvedValue({
80
- gasPrice: BigInt(666),
81
- maxFeePerGas: 0n,
82
- maxPriorityFeePerGas: 0n,
83
- } as ethers.FeeData)
74
+ jest
75
+ .spyOn(JsonRpcProvider.prototype, 'getFeeData')
76
+ .mockResolvedValue(new FeeData(BigInt(666), 0n, 0n))
84
77
 
85
78
  jest.spyOn(JsonRpcProvider.prototype, 'getBalance').mockResolvedValue(BigInt(420))
86
79
  jest
87
80
  .spyOn(JsonRpcProvider.prototype, 'call')
88
81
  .mockResolvedValue('0x000000000000000000000000000000000000000000000000000000000000A455')
89
- jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValue({
90
- hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
91
- parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
92
- number: 1,
93
- difficulty: 0n,
94
- gasLimit: BigInt(1),
95
- gasUsed: BigInt(2),
96
- extraData: '0x',
97
- baseFeePerGas: BigInt(123),
98
- timestamp: now,
99
- } as Partial<ethers.Block> as ethers.Block)
82
+ jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValue(
83
+ mkBlock({
84
+ hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
85
+ parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
86
+ number: 1,
87
+ difficulty: 0n,
88
+ gasLimit: BigInt(1),
89
+ gasUsed: BigInt(2),
90
+ extraData: '0x',
91
+ baseFeePerGas: BigInt(123),
92
+ timestamp: now,
93
+ })
94
+ )
100
95
 
101
96
  jest.spyOn(JsonRpcProvider.prototype, 'getTransactionCount').mockResolvedValue(5)
102
97
 
103
- jest.spyOn(JsonRpcProvider.prototype, 'getTransaction').mockResolvedValue({
104
- hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
105
- blockNumber: 69,
106
- blockHash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
107
- nonce: 123,
108
- value: BigInt(456),
109
- gasLimit: BigInt(123),
110
- gasPrice: BigInt(789),
111
- data: '0x',
112
- to: '0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C',
113
- from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
114
- type: 0,
115
- confirmations: jest.fn().mockResolvedValue(1),
116
- provider: {} as any,
117
- } as Partial<TransactionResponse> as TransactionResponse)
118
-
119
- jest.spyOn(JsonRpcProvider.prototype, 'getTransactionReceipt').mockResolvedValue({
120
- blockHash: '0x8a179bc6cb299f936c4fd614995e62d597ec6108b579c23034fb220967ceaa94',
121
- blockNumber: 69,
122
- byzantium: true,
123
- confirmations: jest.fn().mockResolvedValue(100),
124
- contractAddress: null,
125
- cumulativeGasUsed: BigInt(121),
126
- effectiveGasPrice: BigInt(789),
127
- from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
128
- gasUsed: BigInt(122),
129
- gasLimit: BigInt(21000),
130
- gasPrice: BigInt(789),
131
- logs: [],
132
- logsBloom: '0x',
133
- status: 1,
134
- to: '0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C',
135
- transactionHash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
136
- transactionIndex: 123,
137
- type: 0,
138
- } as Partial<TransactionReceipt> as TransactionReceipt)
98
+ jest.spyOn(JsonRpcProvider.prototype, 'getTransaction').mockResolvedValue(
99
+ mkTransactionResponse({
100
+ hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
101
+ blockNumber: 69,
102
+ blockHash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
103
+ nonce: 123,
104
+ value: BigInt(456),
105
+ gasLimit: BigInt(123),
106
+ gasPrice: BigInt(789),
107
+ data: '0x',
108
+ to: '0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C',
109
+ from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
110
+ type: 0,
111
+ confirmations: jest.fn().mockResolvedValue(1),
112
+ })
113
+ )
114
+
115
+ jest.spyOn(JsonRpcProvider.prototype, 'getTransactionReceipt').mockResolvedValue(
116
+ mkTransactionReceipt({
117
+ blockHash: '0x8a179bc6cb299f936c4fd614995e62d597ec6108b579c23034fb220967ceaa94',
118
+ blockNumber: 69,
119
+ confirmations: jest.fn().mockResolvedValue(100),
120
+ contractAddress: null,
121
+ cumulativeGasUsed: BigInt(121),
122
+ from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
123
+ gasUsed: BigInt(122),
124
+ gasPrice: BigInt(789),
125
+ logs: [],
126
+ logsBloom: '0x',
127
+ status: 1,
128
+ to: '0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C',
129
+ hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
130
+ index: 123,
131
+ type: 0,
132
+ })
133
+ )
139
134
 
140
135
  jest
141
136
  .spyOn(JsonRpcProvider.prototype, 'broadcastTransaction')
@@ -198,15 +193,7 @@ describe('EVM Family', () => {
198
193
  retries: DEFAULT_RETRIES_RPC_METHODS,
199
194
  }
200
195
 
201
- try {
202
- await withApi(evmConfig, currencyId, spy, nodeConfig)
203
- fail('Promise should have been rejected')
204
- } catch (e) {
205
- if (e instanceof AssertionError) {
206
- throw e
207
- }
208
- expect(e).toBeInstanceOf(SpyError)
209
- }
196
+ await expect(withApi(evmConfig, currencyId, spy, nodeConfig)).rejects.toThrow(SpyError)
210
197
  })
211
198
 
212
199
  it('provider cache should reuse the same JsonRpcProvider for the same currency id and same uri', async () => {
@@ -701,14 +688,12 @@ describe('EVM Family', () => {
701
688
 
702
689
  describe('getGasEstimation', () => {
703
690
  it('should return the expected payload', async () => {
704
- jest
705
- .spyOn(JsonRpcProvider.prototype as any, '_perform')
706
- .mockImplementation(async (req: any) => {
707
- if (req.method === 'estimateGas') {
708
- return 5n
709
- }
710
- return null
711
- })
691
+ jest.spyOn(JsonRpcProvider.prototype, '_perform').mockImplementation(async (req: any) => {
692
+ if (req.method === 'estimateGas') {
693
+ return 5n
694
+ }
695
+ return null
696
+ })
712
697
  expect(
713
698
  await nodeApi.getGasEstimation(currencyId, address, {
714
699
  recipient: '0x0000000000000000000000000000000000000000',
@@ -719,14 +704,12 @@ describe('EVM Family', () => {
719
704
  })
720
705
 
721
706
  it('should throw a GasEstimationError in case of error', async () => {
722
- jest
723
- .spyOn(JsonRpcProvider.prototype as any, '_perform')
724
- .mockImplementation(async (req: any) => {
725
- if (req.method === 'estimateGas') {
726
- throw new Error('fail')
727
- }
728
- return null
729
- })
707
+ jest.spyOn(JsonRpcProvider.prototype, '_perform').mockImplementation(async (req: any) => {
708
+ if (req.method === 'estimateGas') {
709
+ throw new Error('fail')
710
+ }
711
+ return null
712
+ })
730
713
 
731
714
  await expect(
732
715
  nodeApi.getGasEstimation(currencyId, address, {
@@ -963,7 +946,7 @@ describe('EVM Family', () => {
963
946
  },
964
947
  }))
965
948
  const sendSpy = jest
966
- .spyOn(JsonRpcProvider.prototype as any, 'send')
949
+ .spyOn(JsonRpcProvider.prototype, 'send')
967
950
  .mockImplementation(async (method) => {
968
951
  if (method === 'eth_getBlockByNumber') {
969
952
  return {
@@ -1073,28 +1056,24 @@ describe('EVM Family', () => {
1073
1056
  },
1074
1057
  }))
1075
1058
 
1076
- jest
1077
- .spyOn(JsonRpcProvider.prototype as any, 'send')
1078
- .mockImplementationOnce(async (method) => {
1079
- if (method === 'eth_getBlockByNumber') {
1080
- return {
1081
- parentHash: '0x0',
1082
- number: 1,
1083
- timestamp: 123,
1084
- difficulty: 0n,
1085
- gasLimit: 1n,
1086
- gasUsed: 2n,
1087
- extraData: '0x',
1088
- }
1059
+ jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
1060
+ if (method === 'eth_getBlockByNumber') {
1061
+ return {
1062
+ parentHash: '0x0',
1063
+ number: 1,
1064
+ timestamp: 123,
1065
+ difficulty: 0n,
1066
+ gasLimit: 1n,
1067
+ gasUsed: 2n,
1068
+ extraData: '0x',
1089
1069
  }
1090
- })
1070
+ }
1071
+ })
1091
1072
  // node reports 1 Gwei via the getFeeData mock at the top of the suite (666 wei), but
1092
1073
  // we override here to assert the floor wins
1093
- jest.spyOn(JsonRpcProvider.prototype, 'getFeeData').mockResolvedValueOnce({
1094
- gasPrice: BigInt('1000000000'), // 1 Gwei
1095
- maxFeePerGas: 0n,
1096
- maxPriorityFeePerGas: 0n,
1097
- } as ethers.FeeData)
1074
+ jest.spyOn(JsonRpcProvider.prototype, 'getFeeData').mockResolvedValueOnce(
1075
+ new FeeData(BigInt('1000000000'), 0n, 0n) // 1 Gwei
1076
+ )
1098
1077
 
1099
1078
  const result = await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, legacyTx)
1100
1079
 
@@ -1141,24 +1120,22 @@ describe('EVM Family', () => {
1141
1120
  }
1142
1121
 
1143
1122
  it('should return the expected payload for a legacy tx', async () => {
1144
- jest
1145
- .spyOn(JsonRpcProvider.prototype as any, 'send')
1146
- .mockImplementationOnce(async (method) => {
1147
- switch (method) {
1148
- case 'eth_getBlockByNumber':
1149
- return {
1150
- parentHash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1151
- number: 1,
1152
- timestamp: 123,
1153
- difficulty: 0n,
1154
- gasLimit: 1n,
1155
- gasUsed: 2n,
1156
- extraData: '0x',
1157
- }
1158
- default:
1159
- throw new Error(`Method not mocked: ${method}`)
1160
- }
1161
- })
1123
+ jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
1124
+ switch (method) {
1125
+ case 'eth_getBlockByNumber':
1126
+ return {
1127
+ parentHash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1128
+ number: 1,
1129
+ timestamp: 123,
1130
+ difficulty: 0n,
1131
+ gasLimit: 1n,
1132
+ gasUsed: 2n,
1133
+ extraData: '0x',
1134
+ }
1135
+ default:
1136
+ throw new Error(`Method not mocked: ${method}`)
1137
+ }
1138
+ })
1162
1139
 
1163
1140
  expect(
1164
1141
  await nodeApi.getFeeData(getCoinConfig('optimism').info, 'optimism', legacyTx)
@@ -1184,30 +1161,18 @@ describe('EVM Family', () => {
1184
1161
  const serializedTransaction =
1185
1162
  '0x02f873012d85010c388d0085077715912682520894c2907efcce4011c491bbeda8a0fa63ba7aab596c87038d7ea4c6800080c001a0bbffe7ba303ab03f697d64672c4a288ae863df8a62ffc67ba72872ce8c227f6fa01261e7c9f06af13631f03fad9b88d3c48931d353b6b41b4072fddcca5ec41628'
1186
1163
 
1187
- try {
1188
- await nodeApi.broadcastTransaction(currencyId, serializedTransaction)
1189
- fail('Promise should have been rejected')
1190
- } catch (e) {
1191
- if (e instanceof AssertionError) {
1192
- throw e
1193
- }
1194
- expect(e).toBeInstanceOf(InsufficientFunds)
1195
- }
1164
+ await expect(nodeApi.broadcastTransaction(currencyId, serializedTransaction)).rejects.toThrow(
1165
+ InsufficientFunds
1166
+ )
1196
1167
  })
1197
1168
 
1198
1169
  it('should throw any other error', async () => {
1199
1170
  const serializedTransaction =
1200
1171
  '0x02f873012d85010c388d0085077715912682520894c2907efcce4011c491bbeda8a0fa63ba7aab596c87038d7ea4c6800080c001a0bbffe7ba303ab03f697d64672c4a288ae863df8a62ffc67ba72872ce8c227f6fa01261e7c9f06af13631f03fad9b88d3c48931d353b6b41b4072fddcca5ec41625'
1201
1172
 
1202
- try {
1203
- await nodeApi.broadcastTransaction(currencyId, serializedTransaction)
1204
- fail('Promise should have been rejected')
1205
- } catch (e) {
1206
- if (e instanceof AssertionError) {
1207
- throw e
1208
- }
1209
- expect((e as Error).message).toEqual('any error')
1210
- }
1173
+ await expect(nodeApi.broadcastTransaction(currencyId, serializedTransaction)).rejects.toThrow(
1174
+ 'any error'
1175
+ )
1211
1176
  })
1212
1177
  })
1213
1178
 
@@ -1225,22 +1190,24 @@ describe('EVM Family', () => {
1225
1190
  })
1226
1191
 
1227
1192
  it('should prefetch block transactions when requested', async () => {
1228
- jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce({
1229
- hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1230
- parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
1231
- number: 1,
1232
- timestamp: now,
1233
- transactions: ['0xtx1'],
1234
- prefetchedTransactions: [
1235
- {
1236
- hash: '0xtx1',
1237
- value: 1n,
1238
- from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
1239
- to: '0xc2907efcce4011c491bbeda8a0fa63ba7aab596c',
1240
- gasPrice: '0',
1241
- },
1242
- ],
1243
- } as any)
1193
+ jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce(
1194
+ mkBlock({
1195
+ hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1196
+ parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
1197
+ number: 1,
1198
+ timestamp: now,
1199
+ transactions: ['0xtx1'],
1200
+ prefetchedTransactions: [
1201
+ mkTransactionResponse({
1202
+ hash: '0xtx1',
1203
+ value: 1n,
1204
+ from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
1205
+ to: '0xc2907efcce4011c491bbeda8a0fa63ba7aab596c',
1206
+ gasPrice: 0n,
1207
+ }),
1208
+ ],
1209
+ })
1210
+ )
1244
1211
 
1245
1212
  expect(await nodeApi.getBlockByHeight(currencyId, 1, true)).toEqual({
1246
1213
  hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
@@ -1261,18 +1228,23 @@ describe('EVM Family', () => {
1261
1228
  })
1262
1229
 
1263
1230
  it('should fallback to transaction hashes when prefetched transactions are unavailable', async () => {
1264
- jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce({
1231
+ const blockWithThrowingGetter = mkBlock({
1265
1232
  hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1266
1233
  parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
1267
1234
  number: 1,
1268
1235
  timestamp: now,
1269
1236
  transactions: ['0xtx1'],
1270
- get prefetchedTransactions() {
1237
+ })
1238
+ Object.defineProperty(blockWithThrowingGetter, 'prefetchedTransactions', {
1239
+ get() {
1271
1240
  const error = new Error('transactions were not prefetched with block request')
1272
- ;(error as Error & { code?: string }).code = 'UNSUPPORTED_OPERATION'
1241
+ Object.assign(error, { code: 'UNSUPPORTED_OPERATION' })
1273
1242
  throw error
1274
1243
  },
1275
- } as any)
1244
+ })
1245
+ jest
1246
+ .spyOn(JsonRpcProvider.prototype, 'getBlock')
1247
+ .mockResolvedValueOnce(blockWithThrowingGetter)
1276
1248
 
1277
1249
  expect(await nodeApi.getBlockByHeight(currencyId, 1, true)).toEqual({
1278
1250
  hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
@@ -1484,7 +1456,7 @@ describe('EVM Family', () => {
1484
1456
  (e: unknown) => e
1485
1457
  )
1486
1458
  expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
1487
- expect((err as { method?: string }).method).toBe('trace_block')
1459
+ expect(err).toMatchObject({ method: 'trace_block' })
1488
1460
  }
1489
1461
  )
1490
1462
  })
@@ -1554,7 +1526,7 @@ describe('EVM Family', () => {
1554
1526
  (e: unknown) => e
1555
1527
  )
1556
1528
  expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
1557
- expect((err as { method?: string }).method).toBe('debug_traceBlockByNumber')
1529
+ expect(err).toMatchObject({ method: 'debug_traceBlockByNumber' })
1558
1530
  }
1559
1531
  )
1560
1532
 
@@ -1574,7 +1546,7 @@ describe('EVM Family', () => {
1574
1546
  (e: unknown) => e
1575
1547
  )
1576
1548
  expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
1577
- expect((err as { method?: string }).method).toBe('debug_traceBlockByNumber')
1549
+ expect(err).toMatchObject({ method: 'debug_traceBlockByNumber' })
1578
1550
  })
1579
1551
  })
1580
1552
 
@@ -1753,16 +1725,13 @@ describe('EVM Family', () => {
1753
1725
  const NORMALIZED_RECIPIENT = '0xc2907efcce4011c491bbeda8a0fa63ba7aab596c'
1754
1726
 
1755
1727
  let capturedTransaction: { from?: string; to?: string } | undefined
1756
- jest
1757
- .spyOn(JsonRpcProvider.prototype as any, '_perform')
1758
- .mockImplementation(async (arg: unknown) => {
1759
- const req = arg as { method: string; transaction?: typeof capturedTransaction }
1760
- if (req.method === 'estimateGas') {
1761
- capturedTransaction = req.transaction
1762
- return 21000n
1763
- }
1764
- return null
1765
- })
1728
+ jest.spyOn(JsonRpcProvider.prototype, '_perform').mockImplementation(async (arg) => {
1729
+ if (arg.method === 'estimateGas') {
1730
+ capturedTransaction = arg.transaction
1731
+ return 21000n
1732
+ }
1733
+ return null
1734
+ })
1766
1735
 
1767
1736
  await nodeApi.getGasEstimation(currencyId, address, {
1768
1737
  recipient: EIP1191_RECIPIENT,
@@ -1,10 +1,10 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import type { BlockFinalizationTag, EvmConfigInfo } from '../../config'
5
+ import type { FeeData } from '../../types'
4
6
  import type { BroadcastConfig } from '@ledgerhq/coin-module-framework/api/types'
5
- import BigNumber from 'bignumber.js'
6
- import { BlockFinalizationTag, EvmConfigInfo } from '../../config'
7
- import { FeeData } from '../../types'
7
+ import type BigNumber from 'bignumber.js'
8
8
 
9
9
  /**
10
10
  * Asset information for token transfers
@@ -1,8 +1,8 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import type { StakingOperation } from '../types/staking'
4
5
  import { ethers } from 'ethers'
5
- import { StakingOperation } from '../types/staking'
6
6
  import { detectEvmStakingOperationType, isStakingOperation } from './detectOperationType'
7
7
 
8
8
  describe('isStakingOperation', () => {
@@ -1,8 +1,8 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import type { StakingOperation } from '../types/staking'
4
5
  import { ethers } from 'ethers'
5
- import { StakingOperation } from '../types/staking'
6
6
  import { extractSeiDelegation, getSeiDelegationAmount } from '../utils'
7
7
  import { STAKING_CONTRACTS } from './contracts'
8
8
  import { encodeStakingData, decodeStakingResult } from './encoder'
@@ -18,7 +18,7 @@ describe('encodeStakingData', () => {
18
18
 
19
19
  const encoded = encodeStakingData({
20
20
  currencyId,
21
- operation: 'delegate' as StakingOperation,
21
+ operation: 'delegate',
22
22
  config,
23
23
  params,
24
24
  })
@@ -33,7 +33,7 @@ describe('encodeStakingData', () => {
33
33
 
34
34
  const encoded = encodeStakingData({
35
35
  currencyId,
36
- operation: 'undelegate' as StakingOperation,
36
+ operation: 'undelegate',
37
37
  config,
38
38
  params,
39
39
  })
@@ -49,7 +49,7 @@ describe('encodeStakingData', () => {
49
49
 
50
50
  const encoded = encodeStakingData({
51
51
  currencyId,
52
- operation: 'redelegate' as StakingOperation,
52
+ operation: 'redelegate',
53
53
  config,
54
54
  params,
55
55
  })
@@ -84,7 +84,7 @@ describe('encodeStakingData', () => {
84
84
 
85
85
  const encoded = encodeStakingData({
86
86
  currencyId,
87
- operation: 'delegate' as StakingOperation,
87
+ operation: 'delegate',
88
88
  config,
89
89
  params,
90
90
  })
@@ -99,7 +99,7 @@ describe('encodeStakingData', () => {
99
99
 
100
100
  const encoded = encodeStakingData({
101
101
  currencyId,
102
- operation: 'undelegate' as StakingOperation,
102
+ operation: 'undelegate',
103
103
  config,
104
104
  params,
105
105
  })
@@ -115,7 +115,7 @@ describe('encodeStakingData', () => {
115
115
  expect(() => {
116
116
  encodeStakingData({
117
117
  currencyId: 'unsupported_currency',
118
- operation: 'delegate' as StakingOperation,
118
+ operation: 'delegate',
119
119
  config,
120
120
  params: ['validator'],
121
121
  })
@@ -126,7 +126,8 @@ describe('encodeStakingData', () => {
126
126
  expect(() => {
127
127
  encodeStakingData({
128
128
  currencyId: 'sei_evm',
129
- operation: 'invalidOperation' as StakingOperation,
129
+ // @ts-ignore — intentionally invalid operation to test error path
130
+ operation: 'invalidOperation',
130
131
  config,
131
132
  params: ['validator'],
132
133
  })
@@ -197,12 +198,7 @@ describe('decodeStakingResult', () => {
197
198
  [mockBalance, mockDelegation],
198
199
  ])
199
200
 
200
- const decoded = decodeStakingResult(
201
- currencyId,
202
- 'getStakedBalance' as StakingOperation,
203
- config,
204
- encodedResult
205
- )
201
+ const decoded = decodeStakingResult(currencyId, 'getStakedBalance', config, encodedResult)
206
202
 
207
203
  expect(decoded).toBeInstanceOf(Array)
208
204
  expect(decoded.length).toBeGreaterThan(0)
@@ -265,7 +261,7 @@ describe('decodeStakingResult', () => {
265
261
 
266
262
  const decoded = decodeStakingResult(
267
263
  'sei_evm',
268
- 'getStakedBalance' as StakingOperation,
264
+ 'getStakedBalance',
269
265
  STAKING_CONTRACTS['sei_evm'],
270
266
  encodedResult
271
267
  )
@@ -283,18 +279,14 @@ describe('decodeStakingResult', () => {
283
279
 
284
280
  it('should throw error for unsupported currency', () => {
285
281
  expect(() => {
286
- decodeStakingResult(
287
- 'unsupported_currency',
288
- 'getStakedBalance' as StakingOperation,
289
- config,
290
- '0x'
291
- )
282
+ decodeStakingResult('unsupported_currency', 'getStakedBalance', config, '0x')
292
283
  }).toThrow('No ABI found for staking currency: unsupported_currency')
293
284
  })
294
285
 
295
286
  it('should throw error for unsupported operation', () => {
296
287
  expect(() => {
297
- decodeStakingResult('sei_evm', 'invalidOperation' as StakingOperation, config, '0x')
288
+ // @ts-ignore — intentionally invalid operation to test error path
289
+ decodeStakingResult('sei_evm', 'invalidOperation', config, '0x')
298
290
  }).toThrow("Operation 'invalidOperation' not supported for currency: sei_evm")
299
291
  })
300
292
  })