@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.
- package/.oxlintrc.json +3 -13
- package/CHANGELOG.md +13 -0
- package/lib/adapters/blockOperations.d.ts +2 -2
- package/lib/adapters/blockOperations.d.ts.map +1 -1
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/logic/combine.d.ts +2 -1
- package/lib/logic/combine.d.ts.map +1 -1
- package/lib/logic/combine.js.map +1 -1
- package/lib/logic/common.d.ts +2 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransactionData.d.ts +1 -1
- package/lib/logic/craftTransactionData.d.ts.map +1 -1
- package/lib/logic/estimateFees.d.ts +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getStakes.d.ts +1 -1
- package/lib/logic/getStakes.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic.d.ts +1 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +4 -4
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/index.d.ts +2 -2
- package/lib/network/explorer/index.d.ts.map +1 -1
- package/lib/network/explorer/index.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts +2 -2
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/none.d.ts +1 -1
- package/lib/network/explorer/none.d.ts.map +1 -1
- package/lib/network/explorer/none.js.map +1 -1
- package/lib/network/explorer/types.d.ts +1 -1
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/gasTracker/index.d.ts +2 -2
- package/lib/network/gasTracker/index.d.ts.map +1 -1
- package/lib/network/gasTracker/index.js.map +1 -1
- package/lib/network/gasTracker/ledger.d.ts +3 -3
- package/lib/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib/network/gasTracker/ledger.js.map +1 -1
- package/lib/network/gasTracker/types.d.ts +2 -2
- package/lib/network/gasTracker/types.d.ts.map +1 -1
- package/lib/network/node/ledger.d.ts +2 -2
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +3 -3
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/staking/validators/monad.d.ts +2 -1
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts +2 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib/types/assets.d.ts +1 -1
- package/lib/types/assets.d.ts.map +1 -1
- package/lib/types/transaction.d.ts +1 -1
- package/lib/types/transaction.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.d.ts +2 -2
- package/lib-es/adapters/blockOperations.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/api/index.d.ts +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/config.d.ts +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/logic/combine.d.ts +2 -1
- package/lib-es/logic/combine.d.ts.map +1 -1
- package/lib-es/logic/combine.js.map +1 -1
- package/lib-es/logic/common.d.ts +2 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +1 -1
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransactionData.d.ts +1 -1
- package/lib-es/logic/craftTransactionData.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts +1 -1
- package/lib-es/logic/getStakes.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic.d.ts +1 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +4 -4
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/index.d.ts +2 -2
- package/lib-es/network/explorer/index.d.ts.map +1 -1
- package/lib-es/network/explorer/index.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts +2 -2
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/none.d.ts +1 -1
- package/lib-es/network/explorer/none.d.ts.map +1 -1
- package/lib-es/network/explorer/none.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +1 -1
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.d.ts +2 -2
- package/lib-es/network/gasTracker/index.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.js.map +1 -1
- package/lib-es/network/gasTracker/ledger.d.ts +3 -3
- package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib-es/network/gasTracker/ledger.js +1 -1
- package/lib-es/network/gasTracker/ledger.js.map +1 -1
- package/lib-es/network/gasTracker/types.d.ts +2 -2
- package/lib-es/network/gasTracker/types.d.ts.map +1 -1
- package/lib-es/network/node/ledger.d.ts +2 -2
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +1 -1
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +3 -3
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.d.ts +2 -1
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts +2 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/types/assets.d.ts +1 -1
- package/lib-es/types/assets.d.ts.map +1 -1
- package/lib-es/types/transaction.d.ts +1 -1
- package/lib-es/types/transaction.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/adapters/blockOperations.test.ts +29 -31
- package/src/adapters/blockOperations.ts +3 -2
- package/src/adapters/etherscan.test.ts +7 -7
- package/src/adapters/ledger.test.ts +2 -2
- package/src/api/getBlock.integ.test.ts +1 -1
- package/src/api/index.fantom.integ.test.ts +1 -1
- package/src/api/index.flare.integ.test.ts +2 -14
- package/src/api/index.integ.test.ts +330 -246
- package/src/api/index.linea.integ.test.ts +1 -1
- package/src/api/index.optimism.integ.test.ts +1 -1
- package/src/api/index.shape.integ.test.ts +1 -1
- package/src/api/index.ts +1 -1
- package/src/config.ts +1 -1
- package/src/fixtures/context.fixtures.ts +79 -1
- package/src/fixtures/ethers.fixtures.ts +26 -0
- package/src/fixtures/ledger.fixtures.ts +1 -1
- package/src/internalTxSources.test.ts +3 -6
- 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/combine.test.ts +2 -2
- package/src/logic/combine.ts +2 -1
- package/src/logic/common.test.ts +120 -112
- package/src/logic/common.ts +2 -7
- package/src/logic/craftTransaction.test.ts +163 -200
- package/src/logic/craftTransaction.ts +3 -2
- package/src/logic/craftTransactionData.test.ts +6 -6
- package/src/logic/craftTransactionData.ts +1 -1
- package/src/logic/estimateFees.test.ts +19 -15
- package/src/logic/estimateFees.ts +6 -3
- package/src/logic/getBalance.test.ts +16 -15
- package/src/logic/getBalance.ts +4 -3
- package/src/logic/getBlock.test.ts +379 -388
- package/src/logic/getBlock.ts +3 -2
- package/src/logic/getBlockInfo.test.ts +7 -9
- package/src/logic/getNextSequence.test.ts +5 -5
- package/src/logic/getStakes.test.ts +35 -35
- package/src/logic/getStakes.ts +1 -1
- package/src/logic/internalTransactionsFetcher.test.ts +26 -24
- package/src/logic/internalTransactionsFetcher.ts +1 -1
- package/src/logic/lastBlock.test.ts +29 -20
- package/src/logic/listOperations.test.ts +44 -40
- package/src/logic/validateIntent.test.ts +152 -101
- package/src/logic/validateIntent.ts +4 -2
- package/src/logic.test.ts +13 -18
- package/src/logic.ts +1 -1
- package/src/network/explorer/etherscan.test.ts +6 -6
- package/src/network/explorer/etherscan.ts +12 -10
- package/src/network/explorer/index.test.ts +52 -22
- package/src/network/explorer/index.ts +2 -2
- package/src/network/explorer/ledger.test.ts +17 -5
- package/src/network/explorer/ledger.ts +3 -2
- package/src/network/explorer/none.ts +2 -1
- package/src/network/explorer/types.ts +1 -1
- package/src/network/gasTracker/index.test.ts +14 -8
- package/src/network/gasTracker/index.ts +2 -2
- package/src/network/gasTracker/ledger.test.ts +34 -29
- package/src/network/gasTracker/ledger.ts +5 -7
- package/src/network/gasTracker/types.ts +2 -2
- 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/ledger.ts +6 -5
- package/src/network/node/node.fixtures.ts +0 -2
- package/src/network/node/rpc.common.ts +14 -14
- package/src/network/node/rpc.test.ts +153 -184
- package/src/network/node/types.ts +3 -3
- package/src/staking/detectOperationType.test.ts +1 -1
- package/src/staking/encoder.test.ts +14 -22
- package/src/staking/logic.test.ts +20 -14
- package/src/staking/operations/index.test.ts +29 -29
- package/src/staking/prepareIntents.test.ts +26 -20
- package/src/staking/redelegations.test.ts +50 -33
- package/src/staking/rewards.test.ts +29 -17
- package/src/staking/rewardsFromReceipt.test.ts +20 -21
- package/src/staking/transactionData.test.ts +23 -23
- package/src/staking/validators/monad.test.ts +65 -24
- package/src/staking/validators/monad.ts +2 -1
- package/src/staking/validators/monadResolver.ts +2 -1
- package/src/staking/validators/somnia.test.ts +21 -13
- package/src/staking/validators/somnia.ts +2 -1
- package/src/staking/validators/zero_gravity.test.ts +118 -48
- package/src/staking/validators/zero_gravity.ts +2 -1
- package/src/staking/validators.integ.test.ts +13 -25
- package/src/staking/validators.test.ts +7 -2
- package/src/types/assets.ts +1 -1
- 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 {
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
.fn()
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
287
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
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
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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
|
-
|
|
635
|
-
|
|
636
|
-
|
|
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
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
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
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
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
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
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
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
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
|
-
|
|
805
|
-
|
|
806
|
-
|
|
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
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
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
|
-
|
|
847
|
-
|
|
848
|
-
|
|
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
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
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
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
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
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
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
|
-
|
|
957
|
-
|
|
958
|
-
|
|
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
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
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
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
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
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
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
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
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
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
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
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
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
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
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
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
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 () => {
|