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