@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,12 +1,7 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { BlockOperation } from '@ledgerhq/coin-module-framework/api/index'
5
- import { createContext, EvmCoinConfig, internalTxSourcesFromList, setCoinConfig } from '../config'
6
- import { UnsupportedRpcMethodError } from '../errors'
7
- import { getInternalTransactionsByBlock } from '../network/explorer/etherscan'
8
- import { getNodeApi } from '../network/node'
9
- import {
4
+ import type {
10
5
  BlockByHeightResult,
11
6
  BlockReceiptInfo,
12
7
  ERC20Transfer,
@@ -15,7 +10,19 @@ import {
15
10
  TraceBlockItem,
16
11
  TransactionInfo,
17
12
  } from '../network/node/types'
18
- import { EtherscanInternalTransaction } from '../types'
13
+ import type { EtherscanInternalTransaction } from '../types'
14
+ import type { BlockOperation } from '@ledgerhq/coin-module-framework/api/index'
15
+ import { createContext, internalTxSourcesFromList, setCoinConfig } from '../config'
16
+ import { UnsupportedRpcMethodError } from '../errors'
17
+ import {
18
+ createMockEvmCoinConfig,
19
+ mkExternalNode,
20
+ mkEtherscanExplorer,
21
+ mkLedgerExplorer,
22
+ } from '../fixtures/context.fixtures'
23
+ import { getInternalTransactionsByBlock } from '../network/explorer/etherscan'
24
+ import { getNodeApi } from '../network/node'
25
+ import { mockNodeApi } from '../network/node/node.fixtures'
19
26
  import { safeEncodeEIP55 } from '../utils'
20
27
  import { getBlock } from './getBlock'
21
28
  import { dropRootTraceDuplicates } from './rootTraceDedup'
@@ -127,10 +134,7 @@ describe('getBlock', () => {
127
134
  }
128
135
 
129
136
  it('returns block with transactions and ERC20 transfers using bulk receipts', async () => {
130
- setCoinConfig(
131
- () =>
132
- ({ info: { node: { type: 'external' as const, retries: 0 } } }) as unknown as EvmCoinConfig
133
- )
137
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
134
138
 
135
139
  const mockGetNodeApi = jest.mocked(getNodeApi)
136
140
  const mockGetBlockByHeight = jest.fn()
@@ -153,11 +157,13 @@ describe('getBlock', () => {
153
157
  }),
154
158
  ])
155
159
 
156
- mockGetNodeApi.mockReturnValue({
157
- getBlockByHeight: mockGetBlockByHeight,
158
- getBlockReceipts: mockGetBlockReceipts,
159
- getTransaction: jest.fn(),
160
- } as any)
160
+ mockGetNodeApi.mockReturnValue(
161
+ mockNodeApi({
162
+ getBlockByHeight: mockGetBlockByHeight,
163
+ getBlockReceipts: mockGetBlockReceipts,
164
+ getTransaction: jest.fn(),
165
+ })
166
+ )
161
167
 
162
168
  const result = await getBlock(createContext(), '', 12345)
163
169
 
@@ -217,32 +223,31 @@ describe('getBlock', () => {
217
223
  })
218
224
 
219
225
  it('adds SmartContractInteraction details on prefetched tx with non-trivial input', async () => {
220
- setCoinConfig(
221
- () =>
222
- ({ info: { node: { type: 'external' as const, retries: 0 } } }) as unknown as EvmCoinConfig
223
- )
226
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
224
227
 
225
228
  const calldata = '0xa9059cbb00000000'
226
229
  const mockGetNodeApi = jest.mocked(getNodeApi)
227
- mockGetNodeApi.mockReturnValue({
228
- getBlockByHeight: jest.fn().mockResolvedValueOnce(
229
- makeNodeBlock({
230
- transactions: [
231
- makeNodeBlockTx({
232
- hash: '0xtx1',
233
- from: address1,
234
- to: address2,
235
- value: '0',
236
- input: calldata,
237
- }),
238
- ],
239
- })
240
- ),
241
- getBlockReceipts: jest
242
- .fn()
243
- .mockResolvedValueOnce([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
244
- getTransaction: jest.fn(),
245
- } as any)
230
+ mockGetNodeApi.mockReturnValue(
231
+ mockNodeApi({
232
+ getBlockByHeight: jest.fn().mockResolvedValueOnce(
233
+ makeNodeBlock({
234
+ transactions: [
235
+ makeNodeBlockTx({
236
+ hash: '0xtx1',
237
+ from: address1,
238
+ to: address2,
239
+ value: '0',
240
+ input: calldata,
241
+ }),
242
+ ],
243
+ })
244
+ ),
245
+ getBlockReceipts: jest
246
+ .fn()
247
+ .mockResolvedValueOnce([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
248
+ getTransaction: jest.fn(),
249
+ })
250
+ )
246
251
 
247
252
  const result = await getBlock(createContext(), '', 12345)
248
253
 
@@ -257,34 +262,35 @@ describe('getBlock', () => {
257
262
  })
258
263
 
259
264
  it('adds SmartContractDeployment details when prefetched tx has input but no to', async () => {
260
- setCoinConfig(
261
- () =>
262
- ({ info: { node: { type: 'external' as const, retries: 0 } } }) as unknown as EvmCoinConfig
263
- )
265
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
264
266
 
265
267
  const initCode = '0x6001600055'
266
268
  const mockGetNodeApi = jest.mocked(getNodeApi)
267
- mockGetNodeApi.mockReturnValue({
268
- getBlockByHeight: jest.fn().mockResolvedValueOnce(
269
- makeNodeBlock({
270
- transactions: [
271
- makeNodeBlockTx({
272
- hash: '0xdeploy',
273
- from: address1,
274
- to: undefined,
275
- value: '0',
276
- input: initCode,
277
- }),
278
- ],
279
- })
280
- ),
281
- getBlockReceipts: jest
282
- .fn()
283
- .mockResolvedValueOnce([
284
- makeNodeBlockReceipt({ hash: '0xdeploy', erc20Transfers: [], contractAddress: address2 }),
269
+ mockGetNodeApi.mockReturnValue(
270
+ mockNodeApi({
271
+ getBlockByHeight: jest.fn().mockResolvedValueOnce(
272
+ makeNodeBlock({
273
+ transactions: [
274
+ makeNodeBlockTx({
275
+ hash: '0xdeploy',
276
+ from: address1,
277
+ to: undefined,
278
+ value: '0',
279
+ input: initCode,
280
+ }),
281
+ ],
282
+ })
283
+ ),
284
+ getBlockReceipts: jest.fn().mockResolvedValueOnce([
285
+ makeNodeBlockReceipt({
286
+ hash: '0xdeploy',
287
+ erc20Transfers: [],
288
+ contractAddress: address2,
289
+ }),
285
290
  ]),
286
- getTransaction: jest.fn(),
287
- } as any)
291
+ getTransaction: jest.fn(),
292
+ })
293
+ )
288
294
 
289
295
  const result = await getBlock(createContext(), '', 12345)
290
296
 
@@ -299,28 +305,27 @@ describe('getBlock', () => {
299
305
  })
300
306
 
301
307
  it('omits contract details for prefetched tx with trivial input', async () => {
302
- setCoinConfig(
303
- () =>
304
- ({ info: { node: { type: 'external' as const, retries: 0 } } }) as unknown as EvmCoinConfig
305
- )
308
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
306
309
 
307
310
  const mockGetNodeApi = jest.mocked(getNodeApi)
308
- mockGetNodeApi.mockReturnValue({
309
- getBlockByHeight: jest.fn().mockResolvedValueOnce(
310
- makeNodeBlock({
311
- transactions: [
312
- makeNodeBlockTx({
313
- hash: '0xtx1',
314
- input: '0x',
315
- }),
316
- ],
317
- })
318
- ),
319
- getBlockReceipts: jest
320
- .fn()
321
- .mockResolvedValueOnce([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
322
- getTransaction: jest.fn(),
323
- } as any)
311
+ mockGetNodeApi.mockReturnValue(
312
+ mockNodeApi({
313
+ getBlockByHeight: jest.fn().mockResolvedValueOnce(
314
+ makeNodeBlock({
315
+ transactions: [
316
+ makeNodeBlockTx({
317
+ hash: '0xtx1',
318
+ input: '0x',
319
+ }),
320
+ ],
321
+ })
322
+ ),
323
+ getBlockReceipts: jest
324
+ .fn()
325
+ .mockResolvedValueOnce([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
326
+ getTransaction: jest.fn(),
327
+ })
328
+ )
324
329
 
325
330
  const result = await getBlock(createContext(), '', 12345)
326
331
 
@@ -331,10 +336,7 @@ describe('getBlock', () => {
331
336
  })
332
337
 
333
338
  it('adds contract details when falling back to getTransaction with non-trivial input', async () => {
334
- setCoinConfig(
335
- () =>
336
- ({ info: { node: { type: 'external' as const, retries: 0 } } }) as unknown as EvmCoinConfig
337
- )
339
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
338
340
 
339
341
  const calldata = '0xdeadbeef'
340
342
  const mockGetNodeApi = jest.mocked(getNodeApi)
@@ -358,11 +360,13 @@ describe('getBlock', () => {
358
360
  })
359
361
  )
360
362
 
361
- mockGetNodeApi.mockReturnValue({
362
- getBlockByHeight: mockGetBlockByHeight,
363
- getBlockReceipts: mockGetBlockReceipts,
364
- getTransaction: mockGetTransaction,
365
- } as any)
363
+ mockGetNodeApi.mockReturnValue(
364
+ mockNodeApi({
365
+ getBlockByHeight: mockGetBlockByHeight,
366
+ getBlockReceipts: mockGetBlockReceipts,
367
+ getTransaction: mockGetTransaction,
368
+ })
369
+ )
366
370
 
367
371
  const result = await getBlock(createContext(), '', 12345)
368
372
 
@@ -377,10 +381,7 @@ describe('getBlock', () => {
377
381
  })
378
382
 
379
383
  it('falls back to per-transaction calls when bulk receipts are unavailable', async () => {
380
- setCoinConfig(
381
- () =>
382
- ({ info: { node: { type: 'external' as const, retries: 0 } } }) as unknown as EvmCoinConfig
383
- )
384
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
384
385
 
385
386
  const mockGetNodeApi = jest.mocked(getNodeApi)
386
387
  const mockGetBlockByHeight = jest.fn().mockResolvedValueOnce(
@@ -399,11 +400,13 @@ describe('getBlock', () => {
399
400
  .fn()
400
401
  .mockResolvedValueOnce(makeNodeTxInfo({ hash: '0xtx1', value: '1000' }))
401
402
 
402
- mockGetNodeApi.mockReturnValue({
403
- getBlockByHeight: mockGetBlockByHeight,
404
- getBlockReceipts: mockGetBlockReceipts,
405
- getTransaction: mockGetTransaction,
406
- } as any)
403
+ mockGetNodeApi.mockReturnValue(
404
+ mockNodeApi({
405
+ getBlockByHeight: mockGetBlockByHeight,
406
+ getBlockReceipts: mockGetBlockReceipts,
407
+ getTransaction: mockGetTransaction,
408
+ })
409
+ )
407
410
 
408
411
  const result = await getBlock(createContext(), '', 12345)
409
412
 
@@ -422,10 +425,7 @@ describe('getBlock', () => {
422
425
  })
423
426
 
424
427
  it('falls back to per-transaction calls when prefetchTxs is not supported', async () => {
425
- setCoinConfig(
426
- () =>
427
- ({ info: { node: { type: 'external' as const, retries: 0 } } }) as unknown as EvmCoinConfig
428
- )
428
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
429
429
 
430
430
  const mockGetNodeApi = jest.mocked(getNodeApi)
431
431
  const mockGetBlockByHeight = jest
@@ -434,11 +434,13 @@ describe('getBlock', () => {
434
434
  const mockGetBlockReceipts = jest.fn()
435
435
  const mockGetTransaction = jest.fn().mockResolvedValueOnce(makeNodeTxInfo({ hash: '0xtx1' }))
436
436
 
437
- mockGetNodeApi.mockReturnValue({
438
- getBlockByHeight: mockGetBlockByHeight,
439
- getBlockReceipts: mockGetBlockReceipts,
440
- getTransaction: mockGetTransaction,
441
- } as any)
437
+ mockGetNodeApi.mockReturnValue(
438
+ mockNodeApi({
439
+ getBlockByHeight: mockGetBlockByHeight,
440
+ getBlockReceipts: mockGetBlockReceipts,
441
+ getTransaction: mockGetTransaction,
442
+ })
443
+ )
442
444
 
443
445
  const result = await getBlock(createContext(), '', 12345)
444
446
 
@@ -458,10 +460,7 @@ describe('getBlock', () => {
458
460
  })
459
461
 
460
462
  it('does not fallback when getBlockReceipts fails for another reason', async () => {
461
- setCoinConfig(
462
- () =>
463
- ({ info: { node: { type: 'external' as const, retries: 0 } } }) as unknown as EvmCoinConfig
464
- )
463
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
465
464
 
466
465
  const mockGetNodeApi = jest.mocked(getNodeApi)
467
466
  const mockGetBlockByHeight = jest.fn().mockResolvedValueOnce(
@@ -474,11 +473,13 @@ describe('getBlock', () => {
474
473
  const mockGetBlockReceipts = jest.fn().mockRejectedValueOnce(serverError)
475
474
  const mockGetTransaction = jest.fn()
476
475
 
477
- mockGetNodeApi.mockReturnValue({
478
- getBlockByHeight: mockGetBlockByHeight,
479
- getBlockReceipts: mockGetBlockReceipts,
480
- getTransaction: mockGetTransaction,
481
- } as any)
476
+ mockGetNodeApi.mockReturnValue(
477
+ mockNodeApi({
478
+ getBlockByHeight: mockGetBlockByHeight,
479
+ getBlockReceipts: mockGetBlockReceipts,
480
+ getTransaction: mockGetTransaction,
481
+ })
482
+ )
482
483
 
483
484
  await expect(getBlock(createContext(), '', 12345)).rejects.toThrow('timeout')
484
485
  expect(mockGetTransaction).not.toHaveBeenCalled()
@@ -507,14 +508,12 @@ describe('getBlock', () => {
507
508
  }
508
509
 
509
510
  it('merges internal transactions from explorer into block transactions', async () => {
510
- setCoinConfig(
511
- () =>
512
- ({
513
- info: {
514
- node: { type: 'external' as const, retries: 0 },
515
- explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
516
- },
517
- }) as unknown as EvmCoinConfig
511
+ setCoinConfig(() =>
512
+ createMockEvmCoinConfig({
513
+ chainId: 1,
514
+ node: mkExternalNode(),
515
+ explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
516
+ })
518
517
  )
519
518
 
520
519
  const mockGetNodeApi = jest.mocked(getNodeApi)
@@ -527,11 +526,13 @@ describe('getBlock', () => {
527
526
  .fn()
528
527
  .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })])
529
528
 
530
- mockGetNodeApi.mockReturnValue({
531
- getBlockByHeight: mockGetBlockByHeight,
532
- getBlockReceipts: mockGetBlockReceipts,
533
- getTransaction: jest.fn(),
534
- } as any)
529
+ mockGetNodeApi.mockReturnValue(
530
+ mockNodeApi({
531
+ getBlockByHeight: mockGetBlockByHeight,
532
+ getBlockReceipts: mockGetBlockReceipts,
533
+ getTransaction: jest.fn(),
534
+ })
535
+ )
535
536
 
536
537
  const amount = 240000481795678944n
537
538
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
@@ -581,29 +582,29 @@ describe('getBlock', () => {
581
582
  // That entry has `from`, `to`, `value` identical to the coin tx's own native transfer, so merging
582
583
  // it naively would double-count the native transfer. The dedup in mergeInternalTransactions
583
584
  // drops internal native ops whose (address, peer, amount) match one of the coin tx's own.
584
- setCoinConfig(
585
- () =>
586
- ({
587
- info: {
588
- node: { type: 'external' as const, retries: 0 },
589
- explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
590
- },
591
- }) as unknown as EvmCoinConfig
585
+ setCoinConfig(() =>
586
+ createMockEvmCoinConfig({
587
+ chainId: 1,
588
+ node: mkExternalNode(),
589
+ explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
590
+ })
592
591
  )
593
592
 
594
593
  const amount = 200000000000000000n
595
594
  const mockGetNodeApi = jest.mocked(getNodeApi)
596
- mockGetNodeApi.mockReturnValue({
597
- getBlockByHeight: jest.fn().mockResolvedValueOnce(
598
- makeNodeBlock({
599
- transactions: [makeNodeBlockTx({ hash: '0xtx1', value: amount.toString() })],
600
- })
601
- ),
602
- getBlockReceipts: jest
603
- .fn()
604
- .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
605
- getTransaction: jest.fn(),
606
- } as any)
595
+ mockGetNodeApi.mockReturnValue(
596
+ mockNodeApi({
597
+ getBlockByHeight: jest.fn().mockResolvedValueOnce(
598
+ makeNodeBlock({
599
+ transactions: [makeNodeBlockTx({ hash: '0xtx1', value: amount.toString() })],
600
+ })
601
+ ),
602
+ getBlockReceipts: jest
603
+ .fn()
604
+ .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
605
+ getTransaction: jest.fn(),
606
+ })
607
+ )
607
608
 
608
609
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
609
610
  mockGetInternalTransactionsByBlock.mockResolvedValueOnce([
@@ -628,14 +629,12 @@ describe('getBlock', () => {
628
629
  it("keeps a nested internal transaction that does not match the coin tx's native transfer", async () => {
629
630
  // Sanity: when the explorer reports a legitimate subcall (different from/to than the coin tx),
630
631
  // it is kept alongside the coin tx's own native ops.
631
- setCoinConfig(
632
- () =>
633
- ({
634
- info: {
635
- node: { type: 'external' as const, retries: 0 },
636
- explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
637
- },
638
- }) as unknown as EvmCoinConfig
632
+ setCoinConfig(() =>
633
+ createMockEvmCoinConfig({
634
+ chainId: 1,
635
+ node: mkExternalNode(),
636
+ explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
637
+ })
639
638
  )
640
639
 
641
640
  // Same amount as the coin tx, on purpose: the match key is (address, peer, amount),
@@ -644,17 +643,19 @@ describe('getBlock', () => {
644
643
  const nestedAmount = 200000000000000000n
645
644
  const nestedRecipient = '0x330E16622F947CBBfA15aB2fdf83014EAa27eCd1'
646
645
  const mockGetNodeApi = jest.mocked(getNodeApi)
647
- mockGetNodeApi.mockReturnValue({
648
- getBlockByHeight: jest.fn().mockResolvedValueOnce(
649
- makeNodeBlock({
650
- transactions: [makeNodeBlockTx({ hash: '0xtx1', value: coinAmount.toString() })],
651
- })
652
- ),
653
- getBlockReceipts: jest
654
- .fn()
655
- .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
656
- getTransaction: jest.fn(),
657
- } as any)
646
+ mockGetNodeApi.mockReturnValue(
647
+ mockNodeApi({
648
+ getBlockByHeight: jest.fn().mockResolvedValueOnce(
649
+ makeNodeBlock({
650
+ transactions: [makeNodeBlockTx({ hash: '0xtx1', value: coinAmount.toString() })],
651
+ })
652
+ ),
653
+ getBlockReceipts: jest
654
+ .fn()
655
+ .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
656
+ getTransaction: jest.fn(),
657
+ })
658
+ )
658
659
 
659
660
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
660
661
  mockGetInternalTransactionsByBlock.mockResolvedValueOnce([
@@ -698,14 +699,8 @@ describe('getBlock', () => {
698
699
  })
699
700
 
700
701
  it('when explorer is not etherscan like, falls back to node.traceBlockErigon', async () => {
701
- setCoinConfig(
702
- () =>
703
- ({
704
- info: {
705
- node: { type: 'external' as const, retries: 0 },
706
- explorer: { type: 'ledger' },
707
- },
708
- }) as unknown as EvmCoinConfig
702
+ setCoinConfig(() =>
703
+ createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode(), explorer: mkLedgerExplorer() })
709
704
  )
710
705
 
711
706
  const amount = 240000481795678944n
@@ -716,17 +711,19 @@ describe('getBlock', () => {
716
711
  }),
717
712
  ])
718
713
  const mockGetNodeApi = jest.mocked(getNodeApi)
719
- mockGetNodeApi.mockReturnValue({
720
- getBlockByHeight: jest.fn().mockResolvedValue(
721
- makeNodeBlock({
722
- hash: '0xabc',
723
- transactions: [makeNodeBlockTx({ hash: '0xtx1' })],
724
- })
725
- ),
726
- getBlockReceipts: jest.fn().mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1' })]),
727
- getTransaction: jest.fn(),
728
- traceBlockErigon: mockTraceBlock,
729
- } as any)
714
+ mockGetNodeApi.mockReturnValue(
715
+ mockNodeApi({
716
+ getBlockByHeight: jest.fn().mockResolvedValue(
717
+ makeNodeBlock({
718
+ hash: '0xabc',
719
+ transactions: [makeNodeBlockTx({ hash: '0xtx1' })],
720
+ })
721
+ ),
722
+ getBlockReceipts: jest.fn().mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1' })]),
723
+ getTransaction: jest.fn(),
724
+ traceBlockErigon: mockTraceBlock,
725
+ })
726
+ )
730
727
 
731
728
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
732
729
 
@@ -758,15 +755,13 @@ describe('getBlock', () => {
758
755
  })
759
756
 
760
757
  it('when traceBlockErigon throws UnsupportedRpcMethodError and empty is not configured, the exception is propagated so that the caller can retry to fetch the whole block', async () => {
761
- setCoinConfig(
762
- () =>
763
- ({
764
- info: {
765
- node: { type: 'external' as const, retries: 0 },
766
- explorer: { type: 'ledger' },
767
- getBlockInternalTxsSources: internalTxSourcesFromList(['trace_block']),
768
- },
769
- }) as unknown as EvmCoinConfig
758
+ setCoinConfig(() =>
759
+ createMockEvmCoinConfig({
760
+ chainId: 1,
761
+ node: mkExternalNode(),
762
+ explorer: mkLedgerExplorer(),
763
+ getBlockInternalTxsSources: internalTxSourcesFromList(['trace_block']),
764
+ })
770
765
  )
771
766
 
772
767
  const error = new UnsupportedRpcMethodError(
@@ -778,17 +773,19 @@ describe('getBlock', () => {
778
773
  )
779
774
  const mockTraceBlock = jest.fn().mockRejectedValue(error)
780
775
  const mockGetNodeApi = jest.mocked(getNodeApi)
781
- mockGetNodeApi.mockReturnValue({
782
- getBlockByHeight: jest.fn().mockResolvedValue(
783
- makeNodeBlock({
784
- hash: '0xabc',
785
- transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
786
- })
787
- ),
788
- getBlockReceipts: jest.fn().mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1' })]),
789
- getTransaction: jest.fn(),
790
- traceBlockErigon: mockTraceBlock,
791
- } as any)
776
+ mockGetNodeApi.mockReturnValue(
777
+ mockNodeApi({
778
+ getBlockByHeight: jest.fn().mockResolvedValue(
779
+ makeNodeBlock({
780
+ hash: '0xabc',
781
+ transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
782
+ })
783
+ ),
784
+ getBlockReceipts: jest.fn().mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1' })]),
785
+ getTransaction: jest.fn(),
786
+ traceBlockErigon: mockTraceBlock,
787
+ })
788
+ )
792
789
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
793
790
 
794
791
  await expect(getBlock(createContext(), '', 12345)).rejects.toThrow(error)
@@ -798,28 +795,28 @@ describe('getBlock', () => {
798
795
  })
799
796
 
800
797
  it('when explorer.getInternalTransactionsByBlock fails and node trace methods are undefined, returns block with no internal transactions', async () => {
801
- setCoinConfig(
802
- () =>
803
- ({
804
- info: {
805
- node: { type: 'external' as const, retries: 0 },
806
- explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
807
- },
808
- }) as unknown as EvmCoinConfig
798
+ setCoinConfig(() =>
799
+ createMockEvmCoinConfig({
800
+ chainId: 1,
801
+ node: mkExternalNode(),
802
+ explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
803
+ })
809
804
  )
810
805
 
811
806
  const mockGetNodeApi = jest.mocked(getNodeApi)
812
- mockGetNodeApi.mockReturnValue({
813
- getBlockByHeight: jest.fn().mockResolvedValue(
814
- makeNodeBlock({
815
- transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
816
- })
817
- ),
818
- getBlockReceipts: jest
819
- .fn()
820
- .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
821
- getTransaction: jest.fn(),
822
- } as any)
807
+ mockGetNodeApi.mockReturnValue(
808
+ mockNodeApi({
809
+ getBlockByHeight: jest.fn().mockResolvedValue(
810
+ makeNodeBlock({
811
+ transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
812
+ })
813
+ ),
814
+ getBlockReceipts: jest
815
+ .fn()
816
+ .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
817
+ getTransaction: jest.fn(),
818
+ })
819
+ )
823
820
 
824
821
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
825
822
  mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
@@ -840,14 +837,12 @@ describe('getBlock', () => {
840
837
  })
841
838
 
842
839
  it('when getInternalTransactionsByBlock fails and traceBlockErigon is defined, falls back to traceBlockErigon for internal transactions', async () => {
843
- setCoinConfig(
844
- () =>
845
- ({
846
- info: {
847
- node: { type: 'external' as const, retries: 0 },
848
- explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
849
- },
850
- }) as unknown as EvmCoinConfig
840
+ setCoinConfig(() =>
841
+ createMockEvmCoinConfig({
842
+ chainId: 1,
843
+ node: mkExternalNode(),
844
+ explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
845
+ })
851
846
  )
852
847
 
853
848
  const amount = 240000481795678944n
@@ -857,18 +852,20 @@ describe('getBlock', () => {
857
852
 
858
853
  const mockTraceBlock = jest.fn().mockResolvedValue([traceBlockItem])
859
854
  const mockGetNodeApi = jest.mocked(getNodeApi)
860
- mockGetNodeApi.mockReturnValue({
861
- getBlockByHeight: jest.fn().mockResolvedValue(
862
- makeNodeBlock({
863
- transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
864
- })
865
- ),
866
- getBlockReceipts: jest
867
- .fn()
868
- .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
869
- getTransaction: jest.fn(),
870
- traceBlockErigon: mockTraceBlock,
871
- } as any)
855
+ mockGetNodeApi.mockReturnValue(
856
+ mockNodeApi({
857
+ getBlockByHeight: jest.fn().mockResolvedValue(
858
+ makeNodeBlock({
859
+ transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
860
+ })
861
+ ),
862
+ getBlockReceipts: jest
863
+ .fn()
864
+ .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
865
+ getTransaction: jest.fn(),
866
+ traceBlockErigon: mockTraceBlock,
867
+ })
868
+ )
872
869
 
873
870
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
874
871
  mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
@@ -907,15 +904,13 @@ describe('getBlock', () => {
907
904
  })
908
905
 
909
906
  it('when explorer.getInternalTransactionsByBlock fails and traceBlockErigon rejects UnsupportedRpcMethodError without empty source, propagates the error', async () => {
910
- setCoinConfig(
911
- () =>
912
- ({
913
- info: {
914
- node: { type: 'external' as const, retries: 0 },
915
- explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
916
- getBlockInternalTxsSources: internalTxSourcesFromList(['explorer', 'trace_block']),
917
- },
918
- }) as unknown as EvmCoinConfig
907
+ setCoinConfig(() =>
908
+ createMockEvmCoinConfig({
909
+ chainId: 1,
910
+ node: mkExternalNode(),
911
+ explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
912
+ getBlockInternalTxsSources: internalTxSourcesFromList(['explorer', 'trace_block']),
913
+ })
919
914
  )
920
915
 
921
916
  const error = new UnsupportedRpcMethodError(
@@ -927,18 +922,20 @@ describe('getBlock', () => {
927
922
  )
928
923
  const mockTraceBlock = jest.fn().mockRejectedValue(error)
929
924
  const mockGetNodeApi = jest.mocked(getNodeApi)
930
- mockGetNodeApi.mockReturnValue({
931
- getBlockByHeight: jest.fn().mockResolvedValue(
932
- makeNodeBlock({
933
- transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
934
- })
935
- ),
936
- getBlockReceipts: jest
937
- .fn()
938
- .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
939
- getTransaction: jest.fn(),
940
- traceBlockErigon: mockTraceBlock,
941
- } as any)
925
+ mockGetNodeApi.mockReturnValue(
926
+ mockNodeApi({
927
+ getBlockByHeight: jest.fn().mockResolvedValue(
928
+ makeNodeBlock({
929
+ transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
930
+ })
931
+ ),
932
+ getBlockReceipts: jest
933
+ .fn()
934
+ .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
935
+ getTransaction: jest.fn(),
936
+ traceBlockErigon: mockTraceBlock,
937
+ })
938
+ )
942
939
 
943
940
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
944
941
  mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
@@ -950,14 +947,12 @@ describe('getBlock', () => {
950
947
  })
951
948
 
952
949
  it('with default source list, propagates trace errors when explorer and both trace methods fail at runtime', async () => {
953
- setCoinConfig(
954
- () =>
955
- ({
956
- info: {
957
- node: { type: 'external' as const, retries: 0 },
958
- explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
959
- },
960
- }) as unknown as EvmCoinConfig
950
+ setCoinConfig(() =>
951
+ createMockEvmCoinConfig({
952
+ chainId: 1,
953
+ node: mkExternalNode(),
954
+ explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
955
+ })
961
956
  )
962
957
 
963
958
  const erigonError = new UnsupportedRpcMethodError(
@@ -971,19 +966,21 @@ describe('getBlock', () => {
971
966
  const mockTraceBlockErigon = jest.fn().mockRejectedValue(erigonError)
972
967
  const mockTraceBlockGeth = jest.fn().mockRejectedValue(gethError)
973
968
  const mockGetNodeApi = jest.mocked(getNodeApi)
974
- mockGetNodeApi.mockReturnValue({
975
- getBlockByHeight: jest.fn().mockResolvedValue(
976
- makeNodeBlock({
977
- transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
978
- })
979
- ),
980
- getBlockReceipts: jest
981
- .fn()
982
- .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
983
- getTransaction: jest.fn(),
984
- traceBlockErigon: mockTraceBlockErigon,
985
- traceBlockGeth: mockTraceBlockGeth,
986
- } as any)
969
+ mockGetNodeApi.mockReturnValue(
970
+ mockNodeApi({
971
+ getBlockByHeight: jest.fn().mockResolvedValue(
972
+ makeNodeBlock({
973
+ transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
974
+ })
975
+ ),
976
+ getBlockReceipts: jest
977
+ .fn()
978
+ .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
979
+ getTransaction: jest.fn(),
980
+ traceBlockErigon: mockTraceBlockErigon,
981
+ traceBlockGeth: mockTraceBlockGeth,
982
+ })
983
+ )
987
984
 
988
985
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
989
986
  mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
@@ -996,14 +993,12 @@ describe('getBlock', () => {
996
993
  })
997
994
 
998
995
  it('with default source list, falls back from traceBlockErigon to traceBlockGeth when explorer fails', async () => {
999
- setCoinConfig(
1000
- () =>
1001
- ({
1002
- info: {
1003
- node: { type: 'external' as const, retries: 0 },
1004
- explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
1005
- },
1006
- }) as unknown as EvmCoinConfig
996
+ setCoinConfig(() =>
997
+ createMockEvmCoinConfig({
998
+ chainId: 1,
999
+ node: mkExternalNode(),
1000
+ explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
1001
+ })
1007
1002
  )
1008
1003
 
1009
1004
  const amount = 240000481795678944n
@@ -1014,18 +1009,20 @@ describe('getBlock', () => {
1014
1009
  }),
1015
1010
  ])
1016
1011
  const mockGetNodeApi = jest.mocked(getNodeApi)
1017
- mockGetNodeApi.mockReturnValue({
1018
- getBlockByHeight: jest.fn().mockResolvedValue(
1019
- makeNodeBlock({
1020
- hash: '0xabc',
1021
- transactions: [makeNodeBlockTx({ hash: '0xtx1' })],
1022
- })
1023
- ),
1024
- getBlockReceipts: jest.fn().mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1' })]),
1025
- getTransaction: jest.fn(),
1026
- traceBlockErigon: mockTraceBlockErigon,
1027
- traceBlockGeth: mockTraceBlockGeth,
1028
- } as any)
1012
+ mockGetNodeApi.mockReturnValue(
1013
+ mockNodeApi({
1014
+ getBlockByHeight: jest.fn().mockResolvedValue(
1015
+ makeNodeBlock({
1016
+ hash: '0xabc',
1017
+ transactions: [makeNodeBlockTx({ hash: '0xtx1' })],
1018
+ })
1019
+ ),
1020
+ getBlockReceipts: jest.fn().mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1' })]),
1021
+ getTransaction: jest.fn(),
1022
+ traceBlockErigon: mockTraceBlockErigon,
1023
+ traceBlockGeth: mockTraceBlockGeth,
1024
+ })
1025
+ )
1029
1026
 
1030
1027
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
1031
1028
  mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
@@ -1057,14 +1054,12 @@ describe('getBlock', () => {
1057
1054
  })
1058
1055
 
1059
1056
  it('with default source list, propagates traceBlockErigon error when traceBlockGeth is unavailable', async () => {
1060
- setCoinConfig(
1061
- () =>
1062
- ({
1063
- info: {
1064
- node: { type: 'external' as const, retries: 0 },
1065
- explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
1066
- },
1067
- }) as unknown as EvmCoinConfig
1057
+ setCoinConfig(() =>
1058
+ createMockEvmCoinConfig({
1059
+ chainId: 1,
1060
+ node: mkExternalNode(),
1061
+ explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
1062
+ })
1068
1063
  )
1069
1064
 
1070
1065
  const erigonError = new UnsupportedRpcMethodError(
@@ -1073,18 +1068,20 @@ describe('getBlock', () => {
1073
1068
  )
1074
1069
  const mockTraceBlockErigon = jest.fn().mockRejectedValue(erigonError)
1075
1070
  const mockGetNodeApi = jest.mocked(getNodeApi)
1076
- mockGetNodeApi.mockReturnValue({
1077
- getBlockByHeight: jest.fn().mockResolvedValue(
1078
- makeNodeBlock({
1079
- transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
1080
- })
1081
- ),
1082
- getBlockReceipts: jest
1083
- .fn()
1084
- .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
1085
- getTransaction: jest.fn(),
1086
- traceBlockErigon: mockTraceBlockErigon,
1087
- } as any)
1071
+ mockGetNodeApi.mockReturnValue(
1072
+ mockNodeApi({
1073
+ getBlockByHeight: jest.fn().mockResolvedValue(
1074
+ makeNodeBlock({
1075
+ transactions: [makeNodeBlockTx({ hash: '0xtx1', value: '0' })],
1076
+ })
1077
+ ),
1078
+ getBlockReceipts: jest
1079
+ .fn()
1080
+ .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1', erc20Transfers: [] })]),
1081
+ getTransaction: jest.fn(),
1082
+ traceBlockErigon: mockTraceBlockErigon,
1083
+ })
1084
+ )
1088
1085
 
1089
1086
  const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
1090
1087
  mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
@@ -1094,62 +1091,56 @@ describe('getBlock', () => {
1094
1091
  })
1095
1092
 
1096
1093
  it('uses prefetched tx gasPrice as fallback when Cronos receipt omits effectiveGasPrice and gasPrice', async () => {
1097
- setCoinConfig(
1098
- () =>
1099
- ({
1100
- info: { node: { type: 'external' as const, retries: 0 } },
1101
- }) as unknown as EvmCoinConfig
1102
- )
1094
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
1103
1095
  const gasUsed = 21000n
1104
1096
  const txGasPrice = '568125000000'
1105
1097
  const mockGetNodeApi = jest.mocked(getNodeApi)
1106
- mockGetNodeApi.mockReturnValue({
1107
- getBlockByHeight: jest.fn().mockResolvedValueOnce(
1108
- makeNodeBlock({
1109
- transactions: [makeNodeBlockTx({ hash: '0xtx1', gasPrice: txGasPrice })],
1110
- })
1111
- ),
1112
- getBlockReceipts: jest.fn().mockResolvedValueOnce([
1113
- makeNodeBlockReceipt({
1114
- hash: '0xtx1',
1115
- gasUsed: gasUsed.toString(),
1116
- gasPrice: '0', // what getBlockReceipts returns for a Cronos receipt
1117
- erc20Transfers: [],
1118
- }),
1119
- ]),
1120
- getTransaction: jest.fn(),
1121
- } as any)
1098
+ mockGetNodeApi.mockReturnValue(
1099
+ mockNodeApi({
1100
+ getBlockByHeight: jest.fn().mockResolvedValueOnce(
1101
+ makeNodeBlock({
1102
+ transactions: [makeNodeBlockTx({ hash: '0xtx1', gasPrice: txGasPrice })],
1103
+ })
1104
+ ),
1105
+ getBlockReceipts: jest.fn().mockResolvedValueOnce([
1106
+ makeNodeBlockReceipt({
1107
+ hash: '0xtx1',
1108
+ gasUsed: gasUsed.toString(),
1109
+ gasPrice: '0', // what getBlockReceipts returns for a Cronos receipt
1110
+ erc20Transfers: [],
1111
+ }),
1112
+ ]),
1113
+ getTransaction: jest.fn(),
1114
+ })
1115
+ )
1122
1116
  const result = await getBlock(createContext(), '', 12345)
1123
1117
  expect(result.transactions[0].fees).toEqual(21000n * 568125000000n)
1124
1118
  })
1125
1119
 
1126
1120
  it('uses receipt effectiveGasPrice over prefetched tx gasPrice on mainnet-shaped receipts', async () => {
1127
- setCoinConfig(
1128
- () =>
1129
- ({
1130
- info: { node: { type: 'external' as const, retries: 0 } },
1131
- }) as unknown as EvmCoinConfig
1132
- )
1121
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
1133
1122
  const gasUsed = 21000n
1134
1123
  const receiptEffectiveGasPrice = '1000000000' // 1 Gwei — resolved from effectiveGasPrice by getBlockReceipts
1135
1124
  const txGasPrice = '568125000000' // higher value in the prefetched tx — must NOT win
1136
1125
  const mockGetNodeApi = jest.mocked(getNodeApi)
1137
- mockGetNodeApi.mockReturnValue({
1138
- getBlockByHeight: jest.fn().mockResolvedValueOnce(
1139
- makeNodeBlock({
1140
- transactions: [makeNodeBlockTx({ hash: '0xtx1', gasPrice: txGasPrice })],
1141
- })
1142
- ),
1143
- getBlockReceipts: jest.fn().mockResolvedValueOnce([
1144
- makeNodeBlockReceipt({
1145
- hash: '0xtx1',
1146
- gasUsed: gasUsed.toString(),
1147
- gasPrice: receiptEffectiveGasPrice, // non-zero → receipt wins over tx.gasPrice
1148
- erc20Transfers: [],
1149
- }),
1150
- ]),
1151
- getTransaction: jest.fn(),
1152
- } as any)
1126
+ mockGetNodeApi.mockReturnValue(
1127
+ mockNodeApi({
1128
+ getBlockByHeight: jest.fn().mockResolvedValueOnce(
1129
+ makeNodeBlock({
1130
+ transactions: [makeNodeBlockTx({ hash: '0xtx1', gasPrice: txGasPrice })],
1131
+ })
1132
+ ),
1133
+ getBlockReceipts: jest.fn().mockResolvedValueOnce([
1134
+ makeNodeBlockReceipt({
1135
+ hash: '0xtx1',
1136
+ gasUsed: gasUsed.toString(),
1137
+ gasPrice: receiptEffectiveGasPrice, // non-zero → receipt wins over tx.gasPrice
1138
+ erc20Transfers: [],
1139
+ }),
1140
+ ]),
1141
+ getTransaction: jest.fn(),
1142
+ })
1143
+ )
1153
1144
  const result = await getBlock(createContext(), '', 12345)
1154
1145
  expect(result.transactions[0].fees).toEqual(21000n * 1000000000n)
1155
1146
  })
@@ -1164,21 +1155,21 @@ describe('getBlock', () => {
1164
1155
  txOverrides: Partial<PrefetchedBlockTransaction>,
1165
1156
  receiptOverrides: Partial<BlockReceiptInfo>
1166
1157
  ): void {
1167
- setCoinConfig(
1168
- () => ({ info: { node: { type: 'external', retries: 0 } } }) as unknown as EvmCoinConfig
1169
- )
1158
+ setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
1170
1159
  const mockGetNodeApi = jest.mocked(getNodeApi)
1171
- mockGetNodeApi.mockReturnValue({
1172
- getBlockByHeight: jest
1173
- .fn()
1174
- .mockResolvedValue(
1175
- makeNodeBlock({ transactions: [makeNodeBlockTx({ hash: '0xtx', ...txOverrides })] })
1176
- ),
1177
- getBlockReceipts: jest
1178
- .fn()
1179
- .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx', ...receiptOverrides })]),
1180
- getTransaction: jest.fn(),
1181
- } as any)
1160
+ mockGetNodeApi.mockReturnValue(
1161
+ mockNodeApi({
1162
+ getBlockByHeight: jest
1163
+ .fn()
1164
+ .mockResolvedValue(
1165
+ makeNodeBlock({ transactions: [makeNodeBlockTx({ hash: '0xtx', ...txOverrides })] })
1166
+ ),
1167
+ getBlockReceipts: jest
1168
+ .fn()
1169
+ .mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx', ...receiptOverrides })]),
1170
+ getTransaction: jest.fn(),
1171
+ })
1172
+ )
1182
1173
  }
1183
1174
 
1184
1175
  it('does not modify ops when receipt type is undefined (regular L2 tx)', async () => {