@ledgerhq/coin-evm 5.4.0 → 7.0.0
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/CHANGELOG.md +197 -0
- package/docs/evm-family-integration-process/README.md +1 -1
- package/knip.json +2 -3
- package/lib/adapters/blockOperations.js +6 -6
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/adapters/etherscan.js +23 -23
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.js +17 -17
- package/lib/adapters/ledger.js.map +1 -1
- package/lib/api/index.js +4 -4
- package/lib/api/index.js.map +1 -1
- package/lib/config.d.ts +21 -15
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +5 -25
- package/lib/config.js.map +1 -1
- package/lib/errors.d.ts +9 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +15 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/broadcast.js +1 -1
- package/lib/logic/broadcast.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 +4 -4
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +2 -2
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +9 -9
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +50 -16
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +19 -11
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getBlockInfo.js +1 -1
- package/lib/logic/getBlockInfo.js.map +1 -1
- package/lib/logic/getNextSequence.d.ts.map +1 -1
- package/lib/logic/getNextSequence.js +1 -1
- package/lib/logic/getNextSequence.js.map +1 -1
- package/lib/logic/index.d.ts +2 -0
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +4 -0
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/lastBlock.js +1 -1
- package/lib/logic/lastBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +10 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js +12 -12
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic-public/index.d.ts +3 -0
- package/lib/logic-public/index.d.ts.map +1 -0
- package/lib/logic-public/index.js +19 -0
- package/lib/logic-public/index.js.map +1 -0
- package/lib/{utils.d.ts → logic-public/utils.d.ts} +0 -44
- package/lib/logic-public/utils.d.ts.map +1 -0
- package/lib/logic-public/utils.js +166 -0
- package/lib/logic-public/utils.js.map +1 -0
- package/lib/logic.d.ts +2 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/logic.js +3 -3
- package/lib/logic.js.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +16 -3
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js +61 -6
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts +50 -4
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js +286 -37
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/none.d.ts +1 -0
- package/lib/network/explorer/none.d.ts.map +1 -1
- package/lib/network/explorer/none.js +4 -1
- package/lib/network/explorer/none.js.map +1 -1
- package/lib/network/explorer/types.d.ts +15 -2
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/index.d.ts +5 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +23 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/node/explorerProxy.d.ts +27 -0
- package/lib/network/node/explorerProxy.d.ts.map +1 -0
- package/lib/network/node/explorerProxy.js +262 -0
- package/lib/network/node/explorerProxy.js.map +1 -0
- package/lib/network/node/index.d.ts +2 -1
- package/lib/network/node/index.d.ts.map +1 -1
- package/lib/network/node/index.js +11 -10
- package/lib/network/node/index.js.map +1 -1
- package/lib/network/node/ledger.js +7 -7
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +2 -2
- package/lib/network/node/rpc.common.js +19 -19
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/withNodeSources.d.ts +21 -0
- package/lib/network/node/withNodeSources.d.ts.map +1 -0
- package/lib/network/node/withNodeSources.js +78 -0
- package/lib/network/node/withNodeSources.js.map +1 -0
- package/lib/nodeSources.d.ts +15 -0
- package/lib/nodeSources.d.ts.map +1 -0
- package/lib/nodeSources.js +33 -0
- package/lib/nodeSources.js.map +1 -0
- package/lib/staking/contracts.js +1 -1
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/fetchers.js +1 -1
- package/lib/staking/fetchers.js.map +1 -1
- package/lib/staking/operations/sei.js +1 -1
- package/lib/staking/operations/sei.js.map +1 -1
- package/lib/staking/prepareIntents.js +3 -3
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/rewards.js +1 -1
- package/lib/staking/rewards.js.map +1 -1
- package/lib/staking/transactionData.js +2 -2
- package/lib/staking/transactionData.js.map +1 -1
- package/lib/staking/utils.d.ts +45 -0
- package/lib/staking/utils.d.ts.map +1 -0
- package/lib/{utils.js → staking/utils.js} +5 -164
- package/lib/staking/utils.js.map +1 -0
- package/lib/staking/validators/sei.js +1 -1
- package/lib/staking/validators/sei.js.map +1 -1
- package/lib/types/staking.d.ts +2 -2
- package/lib-es/adapters/blockOperations.js +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/adapters/etherscan.js +1 -1
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/adapters/ledger.js +1 -1
- package/lib-es/adapters/ledger.js.map +1 -1
- package/lib-es/api/index.js +2 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/config.d.ts +21 -15
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +1 -21
- package/lib-es/config.js.map +1 -1
- package/lib-es/errors.d.ts +9 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +13 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/broadcast.js +1 -1
- package/lib-es/logic/broadcast.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 +3 -3
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +2 -2
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +6 -6
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +50 -16
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +16 -8
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getBlockInfo.js +1 -1
- package/lib-es/logic/getBlockInfo.js.map +1 -1
- package/lib-es/logic/getNextSequence.d.ts.map +1 -1
- package/lib-es/logic/getNextSequence.js +1 -1
- package/lib-es/logic/getNextSequence.js.map +1 -1
- package/lib-es/logic/index.d.ts +2 -0
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +4 -0
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/lastBlock.js +1 -1
- package/lib-es/logic/lastBlock.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +10 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js +4 -4
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic-public/index.d.ts +3 -0
- package/lib-es/logic-public/index.d.ts.map +1 -0
- package/lib-es/logic-public/index.js +4 -0
- package/lib-es/logic-public/index.js.map +1 -0
- package/lib-es/{utils.d.ts → logic-public/utils.d.ts} +0 -44
- package/lib-es/logic-public/utils.d.ts.map +1 -0
- package/lib-es/logic-public/utils.js +150 -0
- package/lib-es/logic-public/utils.js.map +1 -0
- package/lib-es/logic.d.ts +2 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/logic.js +3 -3
- package/lib-es/logic.js.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +16 -3
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js +60 -5
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts +50 -4
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js +283 -37
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/none.d.ts +1 -0
- package/lib-es/network/explorer/none.d.ts.map +1 -1
- package/lib-es/network/explorer/none.js +2 -0
- package/lib-es/network/explorer/none.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +15 -2
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/explorer/types.js.map +1 -1
- package/lib-es/network/index.d.ts +5 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +7 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/node/explorerProxy.d.ts +27 -0
- package/lib-es/network/node/explorerProxy.d.ts.map +1 -0
- package/lib-es/network/node/explorerProxy.js +254 -0
- package/lib-es/network/node/explorerProxy.js.map +1 -0
- package/lib-es/network/node/index.d.ts +2 -1
- package/lib-es/network/node/index.d.ts.map +1 -1
- package/lib-es/network/node/index.js +11 -10
- package/lib-es/network/node/index.js.map +1 -1
- package/lib-es/network/node/ledger.js +1 -1
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +2 -2
- package/lib-es/network/node/rpc.common.js +3 -3
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/withNodeSources.d.ts +21 -0
- package/lib-es/network/node/withNodeSources.d.ts.map +1 -0
- package/lib-es/network/node/withNodeSources.js +74 -0
- package/lib-es/network/node/withNodeSources.js.map +1 -0
- package/lib-es/nodeSources.d.ts +15 -0
- package/lib-es/nodeSources.d.ts.map +1 -0
- package/lib-es/nodeSources.js +28 -0
- package/lib-es/nodeSources.js.map +1 -0
- package/lib-es/staking/contracts.js +1 -1
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/fetchers.js +1 -1
- package/lib-es/staking/fetchers.js.map +1 -1
- package/lib-es/staking/operations/sei.js +1 -1
- package/lib-es/staking/operations/sei.js.map +1 -1
- package/lib-es/staking/prepareIntents.js +1 -1
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/rewards.js +1 -1
- package/lib-es/staking/rewards.js.map +1 -1
- package/lib-es/staking/transactionData.js +1 -1
- package/lib-es/staking/transactionData.js.map +1 -1
- package/lib-es/staking/utils.d.ts +45 -0
- package/lib-es/staking/utils.d.ts.map +1 -0
- package/lib-es/{utils.js → staking/utils.js} +1 -147
- package/lib-es/staking/utils.js.map +1 -0
- package/lib-es/staking/validators/sei.js +1 -1
- package/lib-es/staking/validators/sei.js.map +1 -1
- package/lib-es/types/staking.d.ts +2 -2
- package/package.json +72 -7
- package/src/adapters/blockOperations.ts +1 -1
- package/src/adapters/etherscan.ts +1 -1
- package/src/adapters/ledger.ts +1 -1
- package/src/api/{index.arc_testnet.integ.test.ts → index.arc.integ.test.ts} +15 -12
- package/src/api/index.monad_testnet.integ.test.ts +95 -4
- package/src/api/index.ts +2 -2
- package/src/config.ts +22 -34
- package/src/errors.ts +13 -0
- package/src/fixtures/context.fixtures.ts +6 -1
- package/src/logic/broadcast.ts +1 -1
- package/src/logic/common.ts +4 -2
- package/src/logic/craftTransaction.ts +2 -1
- package/src/logic/estimateFees.ts +20 -6
- package/src/logic/getBalance.ts +72 -26
- package/src/logic/getBlock.ts +26 -14
- package/src/logic/getBlockInfo.ts +1 -1
- package/src/logic/getNextSequence.ts +4 -1
- package/src/logic/index.ts +4 -0
- package/src/logic/lastBlock.ts +1 -1
- package/src/logic/listOperations.ts +14 -1
- package/src/logic/tests/broadcast.integ.test.ts +53 -0
- package/src/logic/{broadcast.test.ts → tests/broadcast.test.ts} +7 -7
- package/src/logic/{broadcastSource.test.ts → tests/broadcastSource.test.ts} +6 -6
- package/src/logic/{combine.test.ts → tests/combine.test.ts} +1 -1
- package/src/logic/{common.test.ts → tests/common.test.ts} +45 -21
- package/src/logic/{computeGasLimit.test.ts → tests/computeGasLimit.test.ts} +2 -2
- package/src/logic/{craftTransaction.test.ts → tests/craftTransaction.test.ts} +7 -7
- package/src/logic/{craftTransactionData.test.ts → tests/craftTransactionData.test.ts} +4 -4
- package/src/logic/{estimateFees.test.ts → tests/estimateFees.test.ts} +12 -12
- package/src/logic/tests/getBalance.test.ts +602 -0
- package/src/logic/{getBlock.test.ts → tests/getBlock.test.ts} +182 -89
- package/src/logic/{getBlockInfo.test.ts → tests/getBlockInfo.test.ts} +8 -8
- package/src/logic/{getErc20Data.test.ts → tests/getErc20Data.test.ts} +1 -1
- package/src/logic/{getNextSequence.test.ts → tests/getNextSequence.test.ts} +7 -7
- package/src/logic/{getStakes.test.ts → tests/getStakes.test.ts} +13 -13
- package/src/logic/{internalTransactionsFetcher.test.ts → tests/internalTransactionsFetcher.test.ts} +8 -8
- package/src/logic/{lastBlock.test.ts → tests/lastBlock.test.ts} +7 -7
- package/src/logic/{listOperations.test.ts → tests/listOperations.test.ts} +125 -6
- package/src/logic/{validateAddress.test.ts → tests/validateAddress.test.ts} +1 -1
- package/src/logic/{validateIntent.test.ts → tests/validateIntent.test.ts} +80 -78
- package/src/logic/validateIntent.ts +7 -4
- package/src/logic-public/index.ts +18 -0
- package/src/{utils.test.ts → logic-public/tests/utils.test.ts} +1 -27
- package/src/logic-public/utils.ts +184 -0
- package/src/logic.test.ts +5 -59
- package/src/logic.ts +5 -3
- package/src/network/explorer/etherscan.test.ts +403 -195
- package/src/network/explorer/etherscan.ts +99 -10
- package/src/network/explorer/index.test.ts +27 -0
- package/src/network/explorer/ledger.test.ts +791 -62
- package/src/network/explorer/ledger.ts +426 -54
- package/src/network/explorer/none.ts +3 -0
- package/src/network/explorer/types.ts +29 -5
- package/src/network/index.ts +7 -0
- package/src/network/node/explorerProxy.test.ts +673 -0
- package/src/network/node/explorerProxy.ts +308 -0
- package/src/network/node/index.memoization.test.ts +22 -10
- package/src/network/node/index.test.ts +6 -3
- package/src/network/node/index.ts +11 -7
- package/src/network/node/ledger.ts +1 -1
- package/src/network/node/rpc.common.ts +3 -3
- package/src/network/node/rpc.test.ts +66 -105
- package/src/network/node/withNodeSources.test.ts +240 -0
- package/src/network/node/withNodeSources.ts +95 -0
- package/src/nodeSources.ts +38 -0
- package/src/staking/contracts.ts +1 -1
- package/src/staking/encoder.test.ts +1 -1
- package/src/staking/fetchers.ts +1 -1
- package/src/staking/operations/sei.ts +1 -1
- package/src/staking/prepareIntents.ts +1 -1
- package/src/staking/redelegations.test.ts +1 -1
- package/src/staking/rewards.test.ts +1 -1
- package/src/staking/rewards.ts +1 -1
- package/src/staking/transactionData.ts +1 -1
- package/src/staking/unbondings.test.ts +1 -1
- package/src/staking/utils.test.ts +25 -0
- package/src/{utils.ts → staking/utils.ts} +2 -182
- package/src/staking/validators/sei.ts +1 -1
- package/src/types/staking.ts +2 -2
- package/lib/constants.d.ts +0 -2
- package/lib/constants.d.ts.map +0 -1
- package/lib/constants.js +0 -11
- package/lib/constants.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
- package/lib-es/constants.d.ts +0 -2
- package/lib-es/constants.d.ts.map +0 -1
- package/lib-es/constants.js +0 -7
- package/lib-es/constants.js.map +0 -1
- package/lib-es/utils.d.ts.map +0 -1
- package/lib-es/utils.js.map +0 -1
- package/src/constants.ts +0 -9
- package/src/logic/broadcast.integ.test.ts +0 -46
- package/src/logic/getBalance.test.ts +0 -362
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { EvmContext } from '../../config'
|
|
4
5
|
import type {
|
|
5
6
|
BlockByHeightResult,
|
|
6
7
|
BlockReceiptInfo,
|
|
@@ -9,29 +10,30 @@ import type {
|
|
|
9
10
|
TraceBlockCallAction,
|
|
10
11
|
TraceBlockItem,
|
|
11
12
|
TransactionInfo,
|
|
12
|
-
} from '
|
|
13
|
-
import type { EtherscanInternalTransaction } from '
|
|
13
|
+
} from '../../network/node/types'
|
|
14
|
+
import type { EtherscanInternalTransaction } from '../../types'
|
|
14
15
|
import type { BlockOperation } from '@ledgerhq/coin-module-framework/api/index'
|
|
15
|
-
import {
|
|
16
|
-
import { UnsupportedRpcMethodError } from '
|
|
16
|
+
import { internalTxSourcesFromList } from '../../config'
|
|
17
|
+
import { UnsupportedRpcMethodError } from '../../errors'
|
|
17
18
|
import {
|
|
18
|
-
|
|
19
|
+
createMockEvmConfigInfo,
|
|
20
|
+
createMockEvmContext,
|
|
19
21
|
mkExternalNode,
|
|
20
22
|
mkEtherscanExplorer,
|
|
21
23
|
mkLedgerExplorer,
|
|
22
|
-
} from '
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import { getBlock } from '
|
|
28
|
-
import { dropRootTraceDuplicates } from '
|
|
24
|
+
} from '../../fixtures/context.fixtures'
|
|
25
|
+
import { safeEncodeEIP55 } from '../../logic-public'
|
|
26
|
+
import { getInternalTransactionsByBlock } from '../../network/explorer/etherscan'
|
|
27
|
+
import { getNodeApi } from '../../network/node'
|
|
28
|
+
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
29
|
+
import { getBlock } from '../getBlock'
|
|
30
|
+
import { dropRootTraceDuplicates } from '../rootTraceDedup'
|
|
29
31
|
|
|
30
32
|
// fixme refactor this test
|
|
31
33
|
// use builder function to build the mocked return values
|
|
32
34
|
|
|
33
|
-
jest.mock('
|
|
34
|
-
jest.mock('
|
|
35
|
+
jest.mock('../../network/node')
|
|
36
|
+
jest.mock('../../network/explorer/etherscan', () => ({
|
|
35
37
|
getInternalTransactionsByBlock: jest.fn().mockResolvedValue([]),
|
|
36
38
|
}))
|
|
37
39
|
|
|
@@ -133,8 +135,74 @@ describe('getBlock', () => {
|
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
|
|
138
|
+
it('does not query an internal tx source for a block with no transactions', async () => {
|
|
139
|
+
// Internal transactions only exist inside transactions, so a block with none has nothing to
|
|
140
|
+
// merge. The explorer source costs one metered `txlistinternal` request per block, so it must
|
|
141
|
+
// not be reached at all here.
|
|
142
|
+
const context = createMockEvmContext(
|
|
143
|
+
createMockEvmConfigInfo({
|
|
144
|
+
chainId: 1,
|
|
145
|
+
node: mkExternalNode(),
|
|
146
|
+
explorer: mkEtherscanExplorer(),
|
|
147
|
+
})
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
151
|
+
const mockGetBlockByHeight = jest
|
|
152
|
+
.fn()
|
|
153
|
+
.mockResolvedValueOnce(makeNodeBlock({ transactions: [] }))
|
|
154
|
+
const mockTraceBlockErigon = jest.fn()
|
|
155
|
+
|
|
156
|
+
mockGetNodeApi.mockReturnValue(
|
|
157
|
+
mockNodeApi({
|
|
158
|
+
getBlockByHeight: mockGetBlockByHeight,
|
|
159
|
+
getBlockReceipts: jest.fn(),
|
|
160
|
+
getTransaction: jest.fn(),
|
|
161
|
+
traceBlockErigon: mockTraceBlockErigon,
|
|
162
|
+
})
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
const result = await getBlock(context, '', 12345)
|
|
166
|
+
|
|
167
|
+
expect(result.transactions).toEqual([])
|
|
168
|
+
expect(jest.mocked(getInternalTransactionsByBlock)).not.toHaveBeenCalled()
|
|
169
|
+
expect(mockTraceBlockErigon).not.toHaveBeenCalled()
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
it('still queries an internal tx source for a block that has transactions', async () => {
|
|
173
|
+
const context = createMockEvmContext(
|
|
174
|
+
createMockEvmConfigInfo({
|
|
175
|
+
chainId: 1,
|
|
176
|
+
node: mkExternalNode(),
|
|
177
|
+
explorer: mkEtherscanExplorer(),
|
|
178
|
+
})
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
182
|
+
const mockGetBlockByHeight = jest
|
|
183
|
+
.fn()
|
|
184
|
+
.mockResolvedValueOnce(makeNodeBlock({ transactions: [makeNodeBlockTx({ hash: '0xtx1' })] }))
|
|
185
|
+
|
|
186
|
+
mockGetNodeApi.mockReturnValue(
|
|
187
|
+
mockNodeApi({
|
|
188
|
+
getBlockByHeight: mockGetBlockByHeight,
|
|
189
|
+
getBlockReceipts: jest.fn().mockResolvedValue([makeNodeBlockReceipt({ hash: '0xtx1' })]),
|
|
190
|
+
getTransaction: jest.fn(),
|
|
191
|
+
})
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
await getBlock(context, '', 12345)
|
|
195
|
+
|
|
196
|
+
expect(jest.mocked(getInternalTransactionsByBlock)).toHaveBeenCalledWith(
|
|
197
|
+
expect.anything(),
|
|
198
|
+
12345
|
|
199
|
+
)
|
|
200
|
+
})
|
|
201
|
+
|
|
136
202
|
it('returns block with transactions and ERC20 transfers using bulk receipts', async () => {
|
|
137
|
-
|
|
203
|
+
const context = createMockEvmContext(
|
|
204
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
205
|
+
)
|
|
138
206
|
|
|
139
207
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
140
208
|
const mockGetBlockByHeight = jest.fn()
|
|
@@ -165,7 +233,7 @@ describe('getBlock', () => {
|
|
|
165
233
|
})
|
|
166
234
|
)
|
|
167
235
|
|
|
168
|
-
const result = await getBlock(
|
|
236
|
+
const result = await getBlock(context, '', 12345)
|
|
169
237
|
|
|
170
238
|
expect(result).toMatchObject({
|
|
171
239
|
info: {
|
|
@@ -223,7 +291,9 @@ describe('getBlock', () => {
|
|
|
223
291
|
})
|
|
224
292
|
|
|
225
293
|
it('adds SmartContractInteraction details on prefetched tx with non-trivial input', async () => {
|
|
226
|
-
|
|
294
|
+
const context = createMockEvmContext(
|
|
295
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
296
|
+
)
|
|
227
297
|
|
|
228
298
|
const calldata = '0xa9059cbb00000000'
|
|
229
299
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
@@ -249,7 +319,7 @@ describe('getBlock', () => {
|
|
|
249
319
|
})
|
|
250
320
|
)
|
|
251
321
|
|
|
252
|
-
const result = await getBlock(
|
|
322
|
+
const result = await getBlock(context, '', 12345)
|
|
253
323
|
|
|
254
324
|
expect(result.transactions[0]).toMatchObject({
|
|
255
325
|
hash: '0xtx1',
|
|
@@ -262,7 +332,9 @@ describe('getBlock', () => {
|
|
|
262
332
|
})
|
|
263
333
|
|
|
264
334
|
it('adds SmartContractDeployment details when prefetched tx has input but no to', async () => {
|
|
265
|
-
|
|
335
|
+
const context = createMockEvmContext(
|
|
336
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
337
|
+
)
|
|
266
338
|
|
|
267
339
|
const initCode = '0x6001600055'
|
|
268
340
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
@@ -292,7 +364,7 @@ describe('getBlock', () => {
|
|
|
292
364
|
})
|
|
293
365
|
)
|
|
294
366
|
|
|
295
|
-
const result = await getBlock(
|
|
367
|
+
const result = await getBlock(context, '', 12345)
|
|
296
368
|
|
|
297
369
|
expect(result.transactions[0]).toMatchObject({
|
|
298
370
|
hash: '0xdeploy',
|
|
@@ -305,7 +377,9 @@ describe('getBlock', () => {
|
|
|
305
377
|
})
|
|
306
378
|
|
|
307
379
|
it('omits contract details for prefetched tx with trivial input', async () => {
|
|
308
|
-
|
|
380
|
+
const context = createMockEvmContext(
|
|
381
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
382
|
+
)
|
|
309
383
|
|
|
310
384
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
311
385
|
mockGetNodeApi.mockReturnValue(
|
|
@@ -327,7 +401,7 @@ describe('getBlock', () => {
|
|
|
327
401
|
})
|
|
328
402
|
)
|
|
329
403
|
|
|
330
|
-
const result = await getBlock(
|
|
404
|
+
const result = await getBlock(context, '', 12345)
|
|
331
405
|
|
|
332
406
|
expect({
|
|
333
407
|
hash: result.transactions[0].hash,
|
|
@@ -336,7 +410,9 @@ describe('getBlock', () => {
|
|
|
336
410
|
})
|
|
337
411
|
|
|
338
412
|
it('adds contract details when falling back to getTransaction with non-trivial input', async () => {
|
|
339
|
-
|
|
413
|
+
const context = createMockEvmContext(
|
|
414
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
415
|
+
)
|
|
340
416
|
|
|
341
417
|
const calldata = '0xdeadbeef'
|
|
342
418
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
@@ -368,7 +444,7 @@ describe('getBlock', () => {
|
|
|
368
444
|
})
|
|
369
445
|
)
|
|
370
446
|
|
|
371
|
-
const result = await getBlock(
|
|
447
|
+
const result = await getBlock(context, '', 12345)
|
|
372
448
|
|
|
373
449
|
expect(result.transactions[0]).toMatchObject({
|
|
374
450
|
hash: '0xtx1',
|
|
@@ -381,7 +457,9 @@ describe('getBlock', () => {
|
|
|
381
457
|
})
|
|
382
458
|
|
|
383
459
|
it('falls back to per-transaction calls when bulk receipts are unavailable', async () => {
|
|
384
|
-
|
|
460
|
+
const context = createMockEvmContext(
|
|
461
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
462
|
+
)
|
|
385
463
|
|
|
386
464
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
387
465
|
const mockGetBlockByHeight = jest.fn().mockResolvedValueOnce(
|
|
@@ -408,7 +486,7 @@ describe('getBlock', () => {
|
|
|
408
486
|
})
|
|
409
487
|
)
|
|
410
488
|
|
|
411
|
-
const result = await getBlock(
|
|
489
|
+
const result = await getBlock(context, '', 12345)
|
|
412
490
|
|
|
413
491
|
expect(result).toMatchObject({
|
|
414
492
|
info: {
|
|
@@ -425,7 +503,9 @@ describe('getBlock', () => {
|
|
|
425
503
|
})
|
|
426
504
|
|
|
427
505
|
it('falls back to per-transaction calls when prefetchTxs is not supported', async () => {
|
|
428
|
-
|
|
506
|
+
const context = createMockEvmContext(
|
|
507
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
508
|
+
)
|
|
429
509
|
|
|
430
510
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
431
511
|
const mockGetBlockByHeight = jest
|
|
@@ -442,7 +522,7 @@ describe('getBlock', () => {
|
|
|
442
522
|
})
|
|
443
523
|
)
|
|
444
524
|
|
|
445
|
-
const result = await getBlock(
|
|
525
|
+
const result = await getBlock(context, '', 12345)
|
|
446
526
|
|
|
447
527
|
expect(result).toMatchObject({
|
|
448
528
|
info: {
|
|
@@ -460,7 +540,9 @@ describe('getBlock', () => {
|
|
|
460
540
|
})
|
|
461
541
|
|
|
462
542
|
it('does not fallback when getBlockReceipts fails for another reason', async () => {
|
|
463
|
-
|
|
543
|
+
const context = createMockEvmContext(
|
|
544
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
545
|
+
)
|
|
464
546
|
|
|
465
547
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
466
548
|
const mockGetBlockByHeight = jest.fn().mockResolvedValueOnce(
|
|
@@ -481,7 +563,7 @@ describe('getBlock', () => {
|
|
|
481
563
|
})
|
|
482
564
|
)
|
|
483
565
|
|
|
484
|
-
await expect(getBlock(
|
|
566
|
+
await expect(getBlock(context, '', 12345)).rejects.toThrow('timeout')
|
|
485
567
|
expect(mockGetTransaction).not.toHaveBeenCalled()
|
|
486
568
|
})
|
|
487
569
|
|
|
@@ -508,8 +590,8 @@ describe('getBlock', () => {
|
|
|
508
590
|
}
|
|
509
591
|
|
|
510
592
|
it('merges internal transactions from explorer into block transactions', async () => {
|
|
511
|
-
|
|
512
|
-
|
|
593
|
+
const context = createMockEvmContext(
|
|
594
|
+
createMockEvmConfigInfo({
|
|
513
595
|
chainId: 1,
|
|
514
596
|
node: mkExternalNode(),
|
|
515
597
|
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
@@ -545,7 +627,7 @@ describe('getBlock', () => {
|
|
|
545
627
|
}),
|
|
546
628
|
])
|
|
547
629
|
|
|
548
|
-
const result = await getBlock(
|
|
630
|
+
const result = await getBlock(context, '', 12345)
|
|
549
631
|
|
|
550
632
|
const encodedFrom = safeEncodeEIP55(address1)
|
|
551
633
|
const encodedTo = safeEncodeEIP55(address2)
|
|
@@ -582,8 +664,8 @@ describe('getBlock', () => {
|
|
|
582
664
|
// That entry has `from`, `to`, `value` identical to the coin tx's own native transfer, so merging
|
|
583
665
|
// it naively would double-count the native transfer. The dedup in mergeInternalTransactions
|
|
584
666
|
// drops internal native ops whose (address, peer, amount) match one of the coin tx's own.
|
|
585
|
-
|
|
586
|
-
|
|
667
|
+
const context = createMockEvmContext(
|
|
668
|
+
createMockEvmConfigInfo({
|
|
587
669
|
chainId: 1,
|
|
588
670
|
node: mkExternalNode(),
|
|
589
671
|
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
@@ -617,7 +699,7 @@ describe('getBlock', () => {
|
|
|
617
699
|
}),
|
|
618
700
|
])
|
|
619
701
|
|
|
620
|
-
const result = await getBlock(
|
|
702
|
+
const result = await getBlock(context, '', 12345)
|
|
621
703
|
|
|
622
704
|
// Only the two ops from the coin tx itself (sender + recipient side), no duplicates.
|
|
623
705
|
const nativeOps = result.transactions[0].operations.filter(
|
|
@@ -629,8 +711,8 @@ describe('getBlock', () => {
|
|
|
629
711
|
it("keeps a nested internal transaction that does not match the coin tx's native transfer", async () => {
|
|
630
712
|
// Sanity: when the explorer reports a legitimate subcall (different from/to than the coin tx),
|
|
631
713
|
// it is kept alongside the coin tx's own native ops.
|
|
632
|
-
|
|
633
|
-
|
|
714
|
+
const context = createMockEvmContext(
|
|
715
|
+
createMockEvmConfigInfo({
|
|
634
716
|
chainId: 1,
|
|
635
717
|
node: mkExternalNode(),
|
|
636
718
|
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
@@ -675,7 +757,7 @@ describe('getBlock', () => {
|
|
|
675
757
|
}),
|
|
676
758
|
])
|
|
677
759
|
|
|
678
|
-
const result = await getBlock(
|
|
760
|
+
const result = await getBlock(context, '', 12345)
|
|
679
761
|
|
|
680
762
|
const nativeOps = result.transactions[0].operations.filter(
|
|
681
763
|
(op) => op.type === 'transfer' && op.asset.type === 'native'
|
|
@@ -699,8 +781,8 @@ describe('getBlock', () => {
|
|
|
699
781
|
})
|
|
700
782
|
|
|
701
783
|
it('when explorer is not etherscan like, falls back to node.traceBlockErigon', async () => {
|
|
702
|
-
|
|
703
|
-
|
|
784
|
+
const context = createMockEvmContext(
|
|
785
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode(), explorer: mkLedgerExplorer() })
|
|
704
786
|
)
|
|
705
787
|
|
|
706
788
|
const amount = 240000481795678944n
|
|
@@ -727,7 +809,7 @@ describe('getBlock', () => {
|
|
|
727
809
|
|
|
728
810
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
729
811
|
|
|
730
|
-
const result = await getBlock(
|
|
812
|
+
const result = await getBlock(context, '', 12345)
|
|
731
813
|
|
|
732
814
|
expect(mockGetInternalTransactionsByBlock).not.toHaveBeenCalled()
|
|
733
815
|
expect(mockTraceBlock).toHaveBeenCalledWith(expect.anything(), 12345)
|
|
@@ -755,8 +837,8 @@ describe('getBlock', () => {
|
|
|
755
837
|
})
|
|
756
838
|
|
|
757
839
|
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 () => {
|
|
758
|
-
|
|
759
|
-
|
|
840
|
+
const context = createMockEvmContext(
|
|
841
|
+
createMockEvmConfigInfo({
|
|
760
842
|
chainId: 1,
|
|
761
843
|
node: mkExternalNode(),
|
|
762
844
|
explorer: mkLedgerExplorer(),
|
|
@@ -788,15 +870,15 @@ describe('getBlock', () => {
|
|
|
788
870
|
)
|
|
789
871
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
790
872
|
|
|
791
|
-
await expect(getBlock(
|
|
873
|
+
await expect(getBlock(context, '', 12345)).rejects.toThrow(error)
|
|
792
874
|
|
|
793
875
|
expect(mockGetInternalTransactionsByBlock).not.toHaveBeenCalled()
|
|
794
876
|
expect(mockTraceBlock).toHaveBeenCalledWith(expect.anything(), 12345)
|
|
795
877
|
})
|
|
796
878
|
|
|
797
879
|
it('when explorer.getInternalTransactionsByBlock fails and node trace methods are undefined, returns block with no internal transactions', async () => {
|
|
798
|
-
|
|
799
|
-
|
|
880
|
+
const context = createMockEvmContext(
|
|
881
|
+
createMockEvmConfigInfo({
|
|
800
882
|
chainId: 1,
|
|
801
883
|
node: mkExternalNode(),
|
|
802
884
|
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
@@ -821,7 +903,7 @@ describe('getBlock', () => {
|
|
|
821
903
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
822
904
|
mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
|
|
823
905
|
|
|
824
|
-
const result = await getBlock(
|
|
906
|
+
const result = await getBlock(context, '', 12345)
|
|
825
907
|
|
|
826
908
|
expect(result).toMatchObject({
|
|
827
909
|
info: {
|
|
@@ -837,8 +919,8 @@ describe('getBlock', () => {
|
|
|
837
919
|
})
|
|
838
920
|
|
|
839
921
|
it('when getInternalTransactionsByBlock fails and traceBlockErigon is defined, falls back to traceBlockErigon for internal transactions', async () => {
|
|
840
|
-
|
|
841
|
-
|
|
922
|
+
const context = createMockEvmContext(
|
|
923
|
+
createMockEvmConfigInfo({
|
|
842
924
|
chainId: 1,
|
|
843
925
|
node: mkExternalNode(),
|
|
844
926
|
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
@@ -870,7 +952,7 @@ describe('getBlock', () => {
|
|
|
870
952
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
871
953
|
mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
|
|
872
954
|
|
|
873
|
-
const result = await getBlock(
|
|
955
|
+
const result = await getBlock(context, '', 12345)
|
|
874
956
|
|
|
875
957
|
expect(mockTraceBlock).toHaveBeenCalledWith(expect.anything(), 12345)
|
|
876
958
|
const encodedFrom = safeEncodeEIP55(address1)
|
|
@@ -904,8 +986,8 @@ describe('getBlock', () => {
|
|
|
904
986
|
})
|
|
905
987
|
|
|
906
988
|
it('when explorer.getInternalTransactionsByBlock fails and traceBlockErigon rejects UnsupportedRpcMethodError without empty source, propagates the error', async () => {
|
|
907
|
-
|
|
908
|
-
|
|
989
|
+
const context = createMockEvmContext(
|
|
990
|
+
createMockEvmConfigInfo({
|
|
909
991
|
chainId: 1,
|
|
910
992
|
node: mkExternalNode(),
|
|
911
993
|
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
@@ -940,15 +1022,15 @@ describe('getBlock', () => {
|
|
|
940
1022
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
941
1023
|
mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
|
|
942
1024
|
|
|
943
|
-
await expect(getBlock(
|
|
1025
|
+
await expect(getBlock(context, '', 12345)).rejects.toThrow(error)
|
|
944
1026
|
|
|
945
1027
|
expect(mockGetInternalTransactionsByBlock).toHaveBeenCalledWith(expect.anything(), 12345)
|
|
946
1028
|
expect(mockTraceBlock).toHaveBeenCalledWith(expect.anything(), 12345)
|
|
947
1029
|
})
|
|
948
1030
|
|
|
949
1031
|
it('with default source list, propagates trace errors when explorer and both trace methods fail at runtime', async () => {
|
|
950
|
-
|
|
951
|
-
|
|
1032
|
+
const context = createMockEvmContext(
|
|
1033
|
+
createMockEvmConfigInfo({
|
|
952
1034
|
chainId: 1,
|
|
953
1035
|
node: mkExternalNode(),
|
|
954
1036
|
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
@@ -985,7 +1067,7 @@ describe('getBlock', () => {
|
|
|
985
1067
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
986
1068
|
mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
|
|
987
1069
|
|
|
988
|
-
await expect(getBlock(
|
|
1070
|
+
await expect(getBlock(context, '', 12345)).rejects.toMatchObject({
|
|
989
1071
|
errors: [erigonError, gethError],
|
|
990
1072
|
})
|
|
991
1073
|
expect(mockTraceBlockErigon).toHaveBeenCalledWith(expect.anything(), 12345)
|
|
@@ -993,8 +1075,8 @@ describe('getBlock', () => {
|
|
|
993
1075
|
})
|
|
994
1076
|
|
|
995
1077
|
it('with default source list, falls back from traceBlockErigon to traceBlockGeth when explorer fails', async () => {
|
|
996
|
-
|
|
997
|
-
|
|
1078
|
+
const context = createMockEvmContext(
|
|
1079
|
+
createMockEvmConfigInfo({
|
|
998
1080
|
chainId: 1,
|
|
999
1081
|
node: mkExternalNode(),
|
|
1000
1082
|
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
@@ -1027,7 +1109,7 @@ describe('getBlock', () => {
|
|
|
1027
1109
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
1028
1110
|
mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
|
|
1029
1111
|
|
|
1030
|
-
const result = await getBlock(
|
|
1112
|
+
const result = await getBlock(context, '', 12345)
|
|
1031
1113
|
|
|
1032
1114
|
expect(mockTraceBlockErigon).toHaveBeenCalledWith(expect.anything(), 12345)
|
|
1033
1115
|
expect(mockTraceBlockGeth).toHaveBeenCalledWith(expect.anything(), 12345)
|
|
@@ -1054,8 +1136,8 @@ describe('getBlock', () => {
|
|
|
1054
1136
|
})
|
|
1055
1137
|
|
|
1056
1138
|
it('with default source list, propagates traceBlockErigon error when traceBlockGeth is unavailable', async () => {
|
|
1057
|
-
|
|
1058
|
-
|
|
1139
|
+
const context = createMockEvmContext(
|
|
1140
|
+
createMockEvmConfigInfo({
|
|
1059
1141
|
chainId: 1,
|
|
1060
1142
|
node: mkExternalNode(),
|
|
1061
1143
|
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
@@ -1086,12 +1168,14 @@ describe('getBlock', () => {
|
|
|
1086
1168
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
1087
1169
|
mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
|
|
1088
1170
|
|
|
1089
|
-
await expect(getBlock(
|
|
1171
|
+
await expect(getBlock(context, '', 12345)).rejects.toThrow(erigonError)
|
|
1090
1172
|
expect(mockTraceBlockErigon).toHaveBeenCalledWith(expect.anything(), 12345)
|
|
1091
1173
|
})
|
|
1092
1174
|
|
|
1093
1175
|
it('uses prefetched tx gasPrice as fallback when Cronos receipt omits effectiveGasPrice and gasPrice', async () => {
|
|
1094
|
-
|
|
1176
|
+
const context = createMockEvmContext(
|
|
1177
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
1178
|
+
)
|
|
1095
1179
|
const gasUsed = 21000n
|
|
1096
1180
|
const txGasPrice = '568125000000'
|
|
1097
1181
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
@@ -1113,12 +1197,14 @@ describe('getBlock', () => {
|
|
|
1113
1197
|
getTransaction: jest.fn(),
|
|
1114
1198
|
})
|
|
1115
1199
|
)
|
|
1116
|
-
const result = await getBlock(
|
|
1200
|
+
const result = await getBlock(context, '', 12345)
|
|
1117
1201
|
expect(result.transactions[0].fees).toEqual(21000n * 568125000000n)
|
|
1118
1202
|
})
|
|
1119
1203
|
|
|
1120
1204
|
it('uses receipt effectiveGasPrice over prefetched tx gasPrice on mainnet-shaped receipts', async () => {
|
|
1121
|
-
|
|
1205
|
+
const context = createMockEvmContext(
|
|
1206
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
1207
|
+
)
|
|
1122
1208
|
const gasUsed = 21000n
|
|
1123
1209
|
const receiptEffectiveGasPrice = '1000000000' // 1 Gwei — resolved from effectiveGasPrice by getBlockReceipts
|
|
1124
1210
|
const txGasPrice = '568125000000' // higher value in the prefetched tx — must NOT win
|
|
@@ -1141,12 +1227,14 @@ describe('getBlock', () => {
|
|
|
1141
1227
|
getTransaction: jest.fn(),
|
|
1142
1228
|
})
|
|
1143
1229
|
)
|
|
1144
|
-
const result = await getBlock(
|
|
1230
|
+
const result = await getBlock(context, '', 12345)
|
|
1145
1231
|
expect(result.transactions[0].fees).toEqual(21000n * 1000000000n)
|
|
1146
1232
|
})
|
|
1147
1233
|
|
|
1148
1234
|
it('adds l1Fee to fees when bulk receipt includes l1Fee (OP-stack bulk path)', async () => {
|
|
1149
|
-
|
|
1235
|
+
const context = createMockEvmContext(
|
|
1236
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
1237
|
+
)
|
|
1150
1238
|
const gasUsed = 21000n
|
|
1151
1239
|
const gasPrice = '1000000000'
|
|
1152
1240
|
const l1Fee = '95394812830580'
|
|
@@ -1170,12 +1258,14 @@ describe('getBlock', () => {
|
|
|
1170
1258
|
getTransaction: jest.fn(),
|
|
1171
1259
|
})
|
|
1172
1260
|
)
|
|
1173
|
-
const result = await getBlock(
|
|
1261
|
+
const result = await getBlock(context, 'optimism', 12345)
|
|
1174
1262
|
expect(result.transactions[0].fees).toEqual(gasUsed * BigInt(gasPrice) + BigInt(l1Fee))
|
|
1175
1263
|
})
|
|
1176
1264
|
|
|
1177
1265
|
it('adds l1Fee to fees when getTransaction returns l1Fee (OP-stack per-tx fallback path)', async () => {
|
|
1178
|
-
|
|
1266
|
+
const context = createMockEvmContext(
|
|
1267
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
1268
|
+
)
|
|
1179
1269
|
const gasUsed = '21000'
|
|
1180
1270
|
const gasPrice = '1000000000'
|
|
1181
1271
|
const l1Fee = '95394812830580'
|
|
@@ -1190,7 +1280,7 @@ describe('getBlock', () => {
|
|
|
1190
1280
|
.mockResolvedValueOnce(makeNodeTxInfo({ hash: '0xtx1', gasUsed, gasPrice, l1Fee })),
|
|
1191
1281
|
})
|
|
1192
1282
|
)
|
|
1193
|
-
const result = await getBlock(
|
|
1283
|
+
const result = await getBlock(context, 'optimism', 12345)
|
|
1194
1284
|
expect(result.transactions[0].fees).toEqual(BigInt(gasUsed) * BigInt(gasPrice) + BigInt(l1Fee))
|
|
1195
1285
|
})
|
|
1196
1286
|
|
|
@@ -1203,8 +1293,10 @@ describe('getBlock', () => {
|
|
|
1203
1293
|
function buildZksyncMocks(
|
|
1204
1294
|
txOverrides: Partial<PrefetchedBlockTransaction>,
|
|
1205
1295
|
receiptOverrides: Partial<BlockReceiptInfo>
|
|
1206
|
-
):
|
|
1207
|
-
|
|
1296
|
+
): EvmContext {
|
|
1297
|
+
const context = createMockEvmContext(
|
|
1298
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
1299
|
+
)
|
|
1208
1300
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
1209
1301
|
mockGetNodeApi.mockReturnValue(
|
|
1210
1302
|
mockNodeApi({
|
|
@@ -1219,10 +1311,11 @@ describe('getBlock', () => {
|
|
|
1219
1311
|
getTransaction: jest.fn(),
|
|
1220
1312
|
})
|
|
1221
1313
|
)
|
|
1314
|
+
return context
|
|
1222
1315
|
}
|
|
1223
1316
|
|
|
1224
1317
|
it('does not modify ops when receipt type is undefined (regular L2 tx)', async () => {
|
|
1225
|
-
buildZksyncMocks(
|
|
1318
|
+
const context = buildZksyncMocks(
|
|
1226
1319
|
{ from: USER, to: USER, value: '270000000000000000' },
|
|
1227
1320
|
{
|
|
1228
1321
|
erc20Transfers: [
|
|
@@ -1235,7 +1328,7 @@ describe('getBlock', () => {
|
|
|
1235
1328
|
],
|
|
1236
1329
|
}
|
|
1237
1330
|
)
|
|
1238
|
-
const result = await getBlock(
|
|
1331
|
+
const result = await getBlock(context, ZKSYNC, 12345)
|
|
1239
1332
|
expect(result.transactions[0].operations).toEqual([
|
|
1240
1333
|
{
|
|
1241
1334
|
type: 'transfer',
|
|
@@ -1269,11 +1362,11 @@ describe('getBlock', () => {
|
|
|
1269
1362
|
})
|
|
1270
1363
|
|
|
1271
1364
|
it('does not modify ops for receipt type 2 (EIP-1559)', async () => {
|
|
1272
|
-
buildZksyncMocks(
|
|
1365
|
+
const context = buildZksyncMocks(
|
|
1273
1366
|
{ from: USER, to: USER, value: '270000000000000000' },
|
|
1274
1367
|
{ type: 2, erc20Transfers: [] }
|
|
1275
1368
|
)
|
|
1276
|
-
const result = await getBlock(
|
|
1369
|
+
const result = await getBlock(context, ZKSYNC, 12345)
|
|
1277
1370
|
expect(result.transactions[0].operations).toEqual([
|
|
1278
1371
|
{
|
|
1279
1372
|
type: 'transfer',
|
|
@@ -1293,7 +1386,7 @@ describe('getBlock', () => {
|
|
|
1293
1386
|
})
|
|
1294
1387
|
|
|
1295
1388
|
it('drops native self pair and prepends a synthesized native credit (peer=0x0)', async () => {
|
|
1296
|
-
buildZksyncMocks(
|
|
1389
|
+
const context = buildZksyncMocks(
|
|
1297
1390
|
{ from: USER, to: USER, value: '270000000000000000' },
|
|
1298
1391
|
{
|
|
1299
1392
|
type: 0xff,
|
|
@@ -1315,7 +1408,7 @@ describe('getBlock', () => {
|
|
|
1315
1408
|
],
|
|
1316
1409
|
}
|
|
1317
1410
|
)
|
|
1318
|
-
const result = await getBlock(
|
|
1411
|
+
const result = await getBlock(context, ZKSYNC, 12345)
|
|
1319
1412
|
expect(result.transactions[0].operations).toEqual([
|
|
1320
1413
|
// native credit (synthesized, replaces the native self pair)
|
|
1321
1414
|
{
|
|
@@ -1352,11 +1445,11 @@ describe('getBlock', () => {
|
|
|
1352
1445
|
})
|
|
1353
1446
|
|
|
1354
1447
|
it('prepends only a native credit when no L2BaseToken events are present (type 0xff)', async () => {
|
|
1355
|
-
buildZksyncMocks(
|
|
1448
|
+
const context = buildZksyncMocks(
|
|
1356
1449
|
{ from: USER, to: USER, value: '270000000000000000' },
|
|
1357
1450
|
{ type: 0xff, erc20Transfers: [] }
|
|
1358
1451
|
)
|
|
1359
|
-
const result = await getBlock(
|
|
1452
|
+
const result = await getBlock(context, ZKSYNC, 12345)
|
|
1360
1453
|
expect(result.transactions[0].operations).toEqual([
|
|
1361
1454
|
{
|
|
1362
1455
|
type: 'transfer',
|
|
@@ -1369,7 +1462,7 @@ describe('getBlock', () => {
|
|
|
1369
1462
|
})
|
|
1370
1463
|
|
|
1371
1464
|
it('filters mint-source ops on 0x0 even when no native self pair is found (type 0xff)', async () => {
|
|
1372
|
-
buildZksyncMocks(
|
|
1465
|
+
const context = buildZksyncMocks(
|
|
1373
1466
|
{ from: USER, to: USER, value: '0' },
|
|
1374
1467
|
{
|
|
1375
1468
|
type: 0xff,
|
|
@@ -1384,7 +1477,7 @@ describe('getBlock', () => {
|
|
|
1384
1477
|
],
|
|
1385
1478
|
}
|
|
1386
1479
|
)
|
|
1387
|
-
const result = await getBlock(
|
|
1480
|
+
const result = await getBlock(context, ZKSYNC, 12345)
|
|
1388
1481
|
// Only the to-side (on user) remains; the from-side (on 0x0) is filtered out.
|
|
1389
1482
|
expect(result.transactions[0].operations).toEqual([
|
|
1390
1483
|
{
|
|
@@ -1399,7 +1492,7 @@ describe('getBlock', () => {
|
|
|
1399
1492
|
|
|
1400
1493
|
it('leaves user ERC20 (non-800A) self transfers unchanged under type 0xff', async () => {
|
|
1401
1494
|
const usdc = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
|
|
1402
|
-
buildZksyncMocks(
|
|
1495
|
+
const context = buildZksyncMocks(
|
|
1403
1496
|
{ from: USER, to: USER, value: '0' },
|
|
1404
1497
|
{
|
|
1405
1498
|
type: 0xff,
|
|
@@ -1413,7 +1506,7 @@ describe('getBlock', () => {
|
|
|
1413
1506
|
],
|
|
1414
1507
|
}
|
|
1415
1508
|
)
|
|
1416
|
-
const result = await getBlock(
|
|
1509
|
+
const result = await getBlock(context, ZKSYNC, 12345)
|
|
1417
1510
|
expect(result.transactions[0].operations).toEqual([
|
|
1418
1511
|
{
|
|
1419
1512
|
type: 'transfer',
|
|
@@ -1434,7 +1527,7 @@ describe('getBlock', () => {
|
|
|
1434
1527
|
|
|
1435
1528
|
it('leaves 800A non-self transfers unchanged under type 0xff', async () => {
|
|
1436
1529
|
const other = '0x6cBCD73CD8e8a42844662f0A0e76D7F79Afd933d'
|
|
1437
|
-
buildZksyncMocks(
|
|
1530
|
+
const context = buildZksyncMocks(
|
|
1438
1531
|
{ from: USER, to: USER, value: '0' },
|
|
1439
1532
|
{
|
|
1440
1533
|
type: 0xff,
|
|
@@ -1448,7 +1541,7 @@ describe('getBlock', () => {
|
|
|
1448
1541
|
],
|
|
1449
1542
|
}
|
|
1450
1543
|
)
|
|
1451
|
-
const result = await getBlock(
|
|
1544
|
+
const result = await getBlock(context, ZKSYNC, 12345)
|
|
1452
1545
|
expect(result.transactions[0].operations).toEqual([
|
|
1453
1546
|
{
|
|
1454
1547
|
type: 'transfer',
|
|
@@ -1468,7 +1561,7 @@ describe('getBlock', () => {
|
|
|
1468
1561
|
})
|
|
1469
1562
|
|
|
1470
1563
|
it('does not apply zkSync corrections to other currencies (e.g. ethereum) even when receipt type is 0xff', async () => {
|
|
1471
|
-
buildZksyncMocks(
|
|
1564
|
+
const context = buildZksyncMocks(
|
|
1472
1565
|
{ from: USER, to: USER, value: '270000000000000000' },
|
|
1473
1566
|
{
|
|
1474
1567
|
type: 0xff,
|
|
@@ -1482,7 +1575,7 @@ describe('getBlock', () => {
|
|
|
1482
1575
|
],
|
|
1483
1576
|
}
|
|
1484
1577
|
)
|
|
1485
|
-
const result = await getBlock(
|
|
1578
|
+
const result = await getBlock(context, 'ethereum', 12345)
|
|
1486
1579
|
expect(result.transactions[0].operations).toEqual([
|
|
1487
1580
|
{
|
|
1488
1581
|
type: 'transfer',
|