@ledgerhq/coin-evm 5.4.1 → 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 +191 -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.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,17 +1,13 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { EvmConfigInfo } from '../../config'
|
|
4
5
|
import type { PerformActionRequest } from 'ethers'
|
|
5
6
|
import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
6
7
|
import BigNumber from 'bignumber.js'
|
|
7
8
|
import { FeeData, FetchRequest, JsonRpcProvider, Network, Transaction } from 'ethers'
|
|
8
|
-
import { getCoinConfig } from '../../config'
|
|
9
9
|
import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors'
|
|
10
|
-
import {
|
|
11
|
-
createMockEvmCoinConfig,
|
|
12
|
-
createMockEvmConfigInfo,
|
|
13
|
-
mkExternalNode,
|
|
14
|
-
} from '../../fixtures/context.fixtures'
|
|
10
|
+
import { createMockEvmConfigInfo, mkExternalNode } from '../../fixtures/context.fixtures'
|
|
15
11
|
import {
|
|
16
12
|
mkBlock,
|
|
17
13
|
mkTransactionReceipt,
|
|
@@ -44,9 +40,6 @@ const nodeApi = createNodeApi(evmConfig, {
|
|
|
44
40
|
|
|
45
41
|
jest.useFakeTimers()
|
|
46
42
|
|
|
47
|
-
jest.mock('../../config')
|
|
48
|
-
const mockGetConfig = jest.mocked(getCoinConfig)
|
|
49
|
-
|
|
50
43
|
const now = Math.floor(Date.now() / 1000)
|
|
51
44
|
|
|
52
45
|
const address = '0x6cBCD73CD8e8a42844662f0A0e76D7F79Afd933d'
|
|
@@ -57,6 +50,8 @@ jest.mocked(delay).mockImplementation(
|
|
|
57
50
|
)
|
|
58
51
|
|
|
59
52
|
describe('EVM Family', () => {
|
|
53
|
+
let config: EvmConfigInfo
|
|
54
|
+
|
|
60
55
|
afterEach(() => {
|
|
61
56
|
destroyAllRpcProviders()
|
|
62
57
|
})
|
|
@@ -65,9 +60,7 @@ describe('EVM Family', () => {
|
|
|
65
60
|
jest.resetAllMocks()
|
|
66
61
|
jest.spyOn(JsonRpcProvider.prototype, '_detectNetwork').mockResolvedValue(Network.from(1))
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'my-rpc.com' }) })
|
|
70
|
-
)
|
|
63
|
+
config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'my-rpc.com' }) })
|
|
71
64
|
|
|
72
65
|
jest
|
|
73
66
|
.spyOn(JsonRpcProvider.prototype, 'getFeeData')
|
|
@@ -798,9 +791,7 @@ describe('EVM Family', () => {
|
|
|
798
791
|
}
|
|
799
792
|
})
|
|
800
793
|
|
|
801
|
-
expect(
|
|
802
|
-
await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, eip1559Tx)
|
|
803
|
-
).toEqual({
|
|
794
|
+
expect(await nodeApi.getFeeData(config, currencyId, eip1559Tx)).toEqual({
|
|
804
795
|
maxFeePerGas: new BigNumber('6000000014'),
|
|
805
796
|
maxPriorityFeePerGas: new BigNumber('5999999988'),
|
|
806
797
|
gasPrice: null,
|
|
@@ -818,9 +809,7 @@ describe('EVM Family', () => {
|
|
|
818
809
|
}
|
|
819
810
|
})
|
|
820
811
|
|
|
821
|
-
expect(
|
|
822
|
-
await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, eip1559Tx)
|
|
823
|
-
).toEqual({
|
|
812
|
+
expect(await nodeApi.getFeeData(config, currencyId, eip1559Tx)).toEqual({
|
|
824
813
|
maxFeePerGas: new BigNumber('25000246'),
|
|
825
814
|
maxPriorityFeePerGas: new BigNumber('25000000'),
|
|
826
815
|
gasPrice: null,
|
|
@@ -843,9 +832,9 @@ describe('EVM Family', () => {
|
|
|
843
832
|
}
|
|
844
833
|
})
|
|
845
834
|
|
|
846
|
-
await expect(
|
|
847
|
-
|
|
848
|
-
)
|
|
835
|
+
await expect(nodeApi.getFeeData(config, currencyId, eip1559Tx)).rejects.toThrow(
|
|
836
|
+
feeHistoryError.message
|
|
837
|
+
)
|
|
849
838
|
expect(sendSpy).not.toHaveBeenCalledWith('eth_maxPriorityFeePerGas', expect.anything())
|
|
850
839
|
})
|
|
851
840
|
|
|
@@ -864,9 +853,7 @@ describe('EVM Family', () => {
|
|
|
864
853
|
}
|
|
865
854
|
})
|
|
866
855
|
|
|
867
|
-
await expect(
|
|
868
|
-
nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, eip1559Tx)
|
|
869
|
-
).rejects.toThrow('timeout')
|
|
856
|
+
await expect(nodeApi.getFeeData(config, currencyId, eip1559Tx)).rejects.toThrow('timeout')
|
|
870
857
|
})
|
|
871
858
|
|
|
872
859
|
it('should return the expected payload for an EIP1559 tx when network returns 0 priority fee', async () => {
|
|
@@ -885,9 +872,7 @@ describe('EVM Family', () => {
|
|
|
885
872
|
}
|
|
886
873
|
})
|
|
887
874
|
|
|
888
|
-
expect(
|
|
889
|
-
await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, eip1559Tx)
|
|
890
|
-
).toEqual({
|
|
875
|
+
expect(await nodeApi.getFeeData(config, currencyId, eip1559Tx)).toEqual({
|
|
891
876
|
maxFeePerGas: new BigNumber('1000000026'),
|
|
892
877
|
maxPriorityFeePerGas: new BigNumber(1e9),
|
|
893
878
|
gasPrice: null,
|
|
@@ -910,7 +895,7 @@ describe('EVM Family', () => {
|
|
|
910
895
|
it('defaults to 5 blocks (0x5) when not configured', async () => {
|
|
911
896
|
const sendSpy = stubFeeHistory()
|
|
912
897
|
|
|
913
|
-
await nodeApi.getFeeData(
|
|
898
|
+
await nodeApi.getFeeData(config, currencyId, eip1559Tx)
|
|
914
899
|
|
|
915
900
|
expect(sendSpy).toHaveBeenCalledWith('eth_feeHistory', ['0x5', 'latest', [50]])
|
|
916
901
|
})
|
|
@@ -918,7 +903,7 @@ describe('EVM Family', () => {
|
|
|
918
903
|
it('defaults to the 50th percentile when feeHistoryRewardPercentile is not configured', async () => {
|
|
919
904
|
const sendSpy = stubFeeHistory()
|
|
920
905
|
|
|
921
|
-
await nodeApi.getFeeData(
|
|
906
|
+
await nodeApi.getFeeData(config, currencyId, eip1559Tx)
|
|
922
907
|
|
|
923
908
|
expect(sendSpy).toHaveBeenCalledWith('eth_feeHistory', ['0x5', 'latest', [50]])
|
|
924
909
|
})
|
|
@@ -932,33 +917,29 @@ describe('EVM Family', () => {
|
|
|
932
917
|
])(
|
|
933
918
|
'forwards feeHistoryRewardPercentile %i to eth_feeHistory',
|
|
934
919
|
async (configured, expected) => {
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
})
|
|
941
|
-
)
|
|
920
|
+
config = createMockEvmConfigInfo({
|
|
921
|
+
chainId: 1,
|
|
922
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
923
|
+
feeHistoryRewardPercentile: configured,
|
|
924
|
+
})
|
|
942
925
|
const sendSpy = stubFeeHistory()
|
|
943
926
|
|
|
944
|
-
await nodeApi.getFeeData(
|
|
927
|
+
await nodeApi.getFeeData(config, currencyId, eip1559Tx)
|
|
945
928
|
|
|
946
929
|
expect(sendSpy).toHaveBeenCalledWith('eth_feeHistory', ['0x5', 'latest', [expected]])
|
|
947
930
|
}
|
|
948
931
|
)
|
|
949
932
|
|
|
950
933
|
it('combines feeHistoryBlockCount and feeHistoryRewardPercentile when both configured', async () => {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
})
|
|
958
|
-
)
|
|
934
|
+
config = createMockEvmConfigInfo({
|
|
935
|
+
chainId: 1,
|
|
936
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
937
|
+
feeHistoryBlockCount: 20,
|
|
938
|
+
feeHistoryRewardPercentile: 75,
|
|
939
|
+
})
|
|
959
940
|
const sendSpy = stubFeeHistory()
|
|
960
941
|
|
|
961
|
-
await nodeApi.getFeeData(
|
|
942
|
+
await nodeApi.getFeeData(config, currencyId, eip1559Tx)
|
|
962
943
|
|
|
963
944
|
expect(sendSpy).toHaveBeenCalledWith('eth_feeHistory', ['0x14', 'latest', [75]])
|
|
964
945
|
})
|
|
@@ -972,29 +953,25 @@ describe('EVM Family', () => {
|
|
|
972
953
|
])(
|
|
973
954
|
'forwards block count %i to eth_feeHistory as %s (hex-encoded)',
|
|
974
955
|
async (blockCount, expectedHex) => {
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
})
|
|
981
|
-
)
|
|
956
|
+
config = createMockEvmConfigInfo({
|
|
957
|
+
chainId: 1,
|
|
958
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
959
|
+
feeHistoryBlockCount: blockCount,
|
|
960
|
+
})
|
|
982
961
|
const sendSpy = stubFeeHistory()
|
|
983
962
|
|
|
984
|
-
await nodeApi.getFeeData(
|
|
963
|
+
await nodeApi.getFeeData(config, currencyId, eip1559Tx)
|
|
985
964
|
|
|
986
965
|
expect(sendSpy).toHaveBeenCalledWith('eth_feeHistory', [expectedHex, 'latest', [50]])
|
|
987
966
|
}
|
|
988
967
|
)
|
|
989
968
|
|
|
990
969
|
it('is not used on the legacy path (eth_feeHistory is never called)', async () => {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
})
|
|
997
|
-
)
|
|
970
|
+
config = createMockEvmConfigInfo({
|
|
971
|
+
chainId: 1,
|
|
972
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
973
|
+
feeHistoryBlockCount: 50,
|
|
974
|
+
})
|
|
998
975
|
const sendSpy = jest
|
|
999
976
|
.spyOn(JsonRpcProvider.prototype, 'send')
|
|
1000
977
|
.mockImplementation(async (method) => {
|
|
@@ -1011,20 +988,18 @@ describe('EVM Family', () => {
|
|
|
1011
988
|
}
|
|
1012
989
|
})
|
|
1013
990
|
|
|
1014
|
-
await nodeApi.getFeeData(
|
|
991
|
+
await nodeApi.getFeeData(config, currencyId, legacyTx)
|
|
1015
992
|
|
|
1016
993
|
expect(sendSpy).not.toHaveBeenCalledWith('eth_feeHistory', expect.anything())
|
|
1017
994
|
})
|
|
1018
995
|
|
|
1019
996
|
it('combines block count and minGasPrice floor correctly', async () => {
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
})
|
|
1027
|
-
)
|
|
997
|
+
config = createMockEvmConfigInfo({
|
|
998
|
+
chainId: 1,
|
|
999
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
1000
|
+
feeHistoryBlockCount: 20,
|
|
1001
|
+
minGasPrice: '20000000000', // 20 Gwei
|
|
1002
|
+
})
|
|
1028
1003
|
const sendSpy = jest
|
|
1029
1004
|
.spyOn(JsonRpcProvider.prototype, 'send')
|
|
1030
1005
|
.mockImplementation(async (method) => {
|
|
@@ -1038,11 +1013,7 @@ describe('EVM Family', () => {
|
|
|
1038
1013
|
}
|
|
1039
1014
|
})
|
|
1040
1015
|
|
|
1041
|
-
const result = await nodeApi.getFeeData(
|
|
1042
|
-
getCoinConfig(currencyId).info,
|
|
1043
|
-
currencyId,
|
|
1044
|
-
eip1559Tx
|
|
1045
|
-
)
|
|
1016
|
+
const result = await nodeApi.getFeeData(config, currencyId, eip1559Tx)
|
|
1046
1017
|
|
|
1047
1018
|
expect(sendSpy).toHaveBeenCalledWith('eth_feeHistory', ['0x14', 'latest', [50]])
|
|
1048
1019
|
expect(result.maxPriorityFeePerGas).toEqual(new BigNumber('20000000000'))
|
|
@@ -1050,13 +1021,11 @@ describe('EVM Family', () => {
|
|
|
1050
1021
|
})
|
|
1051
1022
|
|
|
1052
1023
|
it('applies minGasPrice floor to maxPriorityFeePerGas (EIP-1559) when feeHistory reports a lower value', async () => {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
})
|
|
1059
|
-
)
|
|
1024
|
+
config = createMockEvmConfigInfo({
|
|
1025
|
+
chainId: 1,
|
|
1026
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
1027
|
+
minGasPrice: '20000000000', // 20 Gwei floor
|
|
1028
|
+
})
|
|
1060
1029
|
|
|
1061
1030
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1062
1031
|
if (method === 'eth_feeHistory') {
|
|
@@ -1069,7 +1038,7 @@ describe('EVM Family', () => {
|
|
|
1069
1038
|
}
|
|
1070
1039
|
})
|
|
1071
1040
|
|
|
1072
|
-
const result = await nodeApi.getFeeData(
|
|
1041
|
+
const result = await nodeApi.getFeeData(config, currencyId, eip1559Tx)
|
|
1073
1042
|
|
|
1074
1043
|
expect(result.maxPriorityFeePerGas).toEqual(new BigNumber('20000000000'))
|
|
1075
1044
|
// maxFeePerGas = nextBaseFee * 2 + floored priority = 13*2 + 20e9
|
|
@@ -1077,13 +1046,11 @@ describe('EVM Family', () => {
|
|
|
1077
1046
|
})
|
|
1078
1047
|
|
|
1079
1048
|
it('does not lower the priority fee when feeHistory already reports above the configured floor', async () => {
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
})
|
|
1086
|
-
)
|
|
1049
|
+
config = createMockEvmConfigInfo({
|
|
1050
|
+
chainId: 1,
|
|
1051
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
1052
|
+
minGasPrice: '1000000000', // 1 Gwei floor
|
|
1053
|
+
})
|
|
1087
1054
|
|
|
1088
1055
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1089
1056
|
if (method === 'eth_feeHistory') {
|
|
@@ -1096,19 +1063,17 @@ describe('EVM Family', () => {
|
|
|
1096
1063
|
}
|
|
1097
1064
|
})
|
|
1098
1065
|
|
|
1099
|
-
const result = await nodeApi.getFeeData(
|
|
1066
|
+
const result = await nodeApi.getFeeData(config, currencyId, eip1559Tx)
|
|
1100
1067
|
|
|
1101
1068
|
expect(result.maxPriorityFeePerGas).toEqual(new BigNumber('5000000000'))
|
|
1102
1069
|
})
|
|
1103
1070
|
|
|
1104
1071
|
it('applies minGasPrice floor from coin config for legacy txs when node reports lower', async () => {
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
})
|
|
1111
|
-
)
|
|
1072
|
+
config = createMockEvmConfigInfo({
|
|
1073
|
+
chainId: 1,
|
|
1074
|
+
node: mkExternalNode({ uri: 'my-rpc.com' }),
|
|
1075
|
+
minGasPrice: '20000000000', // 20 Gwei
|
|
1076
|
+
})
|
|
1112
1077
|
|
|
1113
1078
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1114
1079
|
if (method === 'eth_getBlockByNumber') {
|
|
@@ -1129,7 +1094,7 @@ describe('EVM Family', () => {
|
|
|
1129
1094
|
new FeeData(BigInt('1000000000'), 0n, 0n) // 1 Gwei
|
|
1130
1095
|
)
|
|
1131
1096
|
|
|
1132
|
-
const result = await nodeApi.getFeeData(
|
|
1097
|
+
const result = await nodeApi.getFeeData(config, currencyId, legacyTx)
|
|
1133
1098
|
|
|
1134
1099
|
expect(result.gasPrice).toEqual(new BigNumber('20000000000'))
|
|
1135
1100
|
})
|
|
@@ -1150,9 +1115,7 @@ describe('EVM Family', () => {
|
|
|
1150
1115
|
}
|
|
1151
1116
|
})
|
|
1152
1117
|
|
|
1153
|
-
expect(
|
|
1154
|
-
await nodeApi.getFeeData(getCoinConfig('zero_gravity').info, 'zero_gravity', eip1559Tx)
|
|
1155
|
-
).toEqual({
|
|
1118
|
+
expect(await nodeApi.getFeeData(config, 'zero_gravity', eip1559Tx)).toEqual({
|
|
1156
1119
|
maxFeePerGas: new BigNumber('2000000026'),
|
|
1157
1120
|
maxPriorityFeePerGas: new BigNumber(2e9),
|
|
1158
1121
|
gasPrice: null,
|
|
@@ -1191,9 +1154,7 @@ describe('EVM Family', () => {
|
|
|
1191
1154
|
}
|
|
1192
1155
|
})
|
|
1193
1156
|
|
|
1194
|
-
expect(
|
|
1195
|
-
await nodeApi.getFeeData(getCoinConfig('optimism').info, 'optimism', legacyTx)
|
|
1196
|
-
).toEqual({
|
|
1157
|
+
expect(await nodeApi.getFeeData(config, 'optimism', legacyTx)).toEqual({
|
|
1197
1158
|
maxFeePerGas: null,
|
|
1198
1159
|
maxPriorityFeePerGas: null,
|
|
1199
1160
|
gasPrice: new BigNumber('666'),
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import axios from 'axios'
|
|
5
|
+
import {
|
|
6
|
+
createMockEvmConfigInfo,
|
|
7
|
+
mkEtherscanExplorer,
|
|
8
|
+
mkExternalNode,
|
|
9
|
+
testLogger,
|
|
10
|
+
} from '../../fixtures/context.fixtures'
|
|
11
|
+
import { nodeSourcesFromList } from '../../nodeSources'
|
|
12
|
+
import { mockNodeApi } from './node.fixtures'
|
|
13
|
+
import { withNodeSources } from './withNodeSources'
|
|
14
|
+
|
|
15
|
+
jest.mock('axios')
|
|
16
|
+
const mockAxiosGet = jest.mocked(axios.get)
|
|
17
|
+
|
|
18
|
+
const node = mkExternalNode()
|
|
19
|
+
const PRUNED_HEIGHT = 14817811
|
|
20
|
+
const PRUNED_HEIGHT_HEX = '0x' + PRUNED_HEIGHT.toString(16)
|
|
21
|
+
const TX_HASH = '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890ab'
|
|
22
|
+
|
|
23
|
+
describe('withNodeSources', () => {
|
|
24
|
+
let api: ReturnType<typeof mockNodeApi>
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
jest.clearAllMocks()
|
|
28
|
+
api = mockNodeApi()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('returns the original api unchanged when nodeSources is default (node only)', () => {
|
|
32
|
+
const config = createMockEvmConfigInfo({ chainId: 1, node, explorer: mkEtherscanExplorer() })
|
|
33
|
+
expect(withNodeSources(api, config, testLogger)).toBe(api)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('returns the original api unchanged when explorer is not etherscan-like', () => {
|
|
37
|
+
const config = createMockEvmConfigInfo({
|
|
38
|
+
chainId: 1,
|
|
39
|
+
node,
|
|
40
|
+
explorer: { type: 'none' },
|
|
41
|
+
nodeSources: nodeSourcesFromList(['explorer-proxy']),
|
|
42
|
+
})
|
|
43
|
+
expect(withNodeSources(api, config, testLogger)).toBe(api)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('returns a wrapped api when nodeSources includes explorer-proxy and an etherscan-like explorer is configured', () => {
|
|
47
|
+
const config = createMockEvmConfigInfo({
|
|
48
|
+
chainId: 1,
|
|
49
|
+
node,
|
|
50
|
+
explorer: mkEtherscanExplorer(),
|
|
51
|
+
nodeSources: nodeSourcesFromList(['node', 'explorer-proxy']),
|
|
52
|
+
})
|
|
53
|
+
expect(withNodeSources(api, config, testLogger)).not.toBe(api)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
describe('getBlockByHeight', () => {
|
|
57
|
+
it('forwards successful calls unchanged', async () => {
|
|
58
|
+
const config = createMockEvmConfigInfo({
|
|
59
|
+
chainId: 1,
|
|
60
|
+
node,
|
|
61
|
+
explorer: mkEtherscanExplorer(),
|
|
62
|
+
nodeSources: nodeSourcesFromList(['node', 'explorer-proxy']),
|
|
63
|
+
})
|
|
64
|
+
const block = { hash: '0xabc', height: 100, timestamp: 1000, parentHash: '0xparent' }
|
|
65
|
+
api.getBlockByHeight.mockResolvedValueOnce(block)
|
|
66
|
+
|
|
67
|
+
const wrapped = withNodeSources(api, config, testLogger)
|
|
68
|
+
await expect(wrapped.getBlockByHeight('eth', 100)).resolves.toEqual(block)
|
|
69
|
+
expect(mockAxiosGet).not.toHaveBeenCalled()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('falls back to explorer proxy when RPC throws block not found', async () => {
|
|
73
|
+
const config = createMockEvmConfigInfo({
|
|
74
|
+
chainId: 1,
|
|
75
|
+
node,
|
|
76
|
+
explorer: mkEtherscanExplorer({ uri: 'http://explorer.test' }),
|
|
77
|
+
nodeSources: nodeSourcesFromList(['node', 'explorer-proxy']),
|
|
78
|
+
})
|
|
79
|
+
api.getBlockByHeight.mockRejectedValueOnce(new Error(`Block ${PRUNED_HEIGHT} not found`))
|
|
80
|
+
mockAxiosGet.mockResolvedValueOnce({
|
|
81
|
+
data: {
|
|
82
|
+
result: {
|
|
83
|
+
hash: '0xdeadbeef',
|
|
84
|
+
number: PRUNED_HEIGHT_HEX,
|
|
85
|
+
timestamp: '0x6849e2a5',
|
|
86
|
+
parentHash: '0xparent',
|
|
87
|
+
transactions: ['0xhash1', '0xhash2'],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const wrapped = withNodeSources(api, config, testLogger)
|
|
93
|
+
const result = await wrapped.getBlockByHeight('monad_testnet', PRUNED_HEIGHT)
|
|
94
|
+
|
|
95
|
+
expect(result.hash).toBe('0xdeadbeef')
|
|
96
|
+
// Always populates transactionHashes (never transactions) so callers go through
|
|
97
|
+
// individual getTransaction calls (which are wrapped) rather than getBlockReceipts
|
|
98
|
+
// (which hits the pruned primary node).
|
|
99
|
+
expect(result.transactionHashes).toEqual(['0xhash1', '0xhash2'])
|
|
100
|
+
expect(result.transactions).toBeUndefined()
|
|
101
|
+
expect(mockAxiosGet).toHaveBeenCalledWith(
|
|
102
|
+
'http://explorer.test',
|
|
103
|
+
expect.objectContaining({
|
|
104
|
+
params: expect.objectContaining({
|
|
105
|
+
module: 'proxy',
|
|
106
|
+
action: 'eth_getBlockByNumber',
|
|
107
|
+
tag: PRUNED_HEIGHT_HEX,
|
|
108
|
+
boolean: 'false',
|
|
109
|
+
}),
|
|
110
|
+
})
|
|
111
|
+
)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('re-throws the original error when explorer also fails', async () => {
|
|
115
|
+
const config = createMockEvmConfigInfo({
|
|
116
|
+
chainId: 1,
|
|
117
|
+
node,
|
|
118
|
+
explorer: mkEtherscanExplorer({ retries: 0 }),
|
|
119
|
+
nodeSources: nodeSourcesFromList(['node', 'explorer-proxy']),
|
|
120
|
+
})
|
|
121
|
+
api.getBlockByHeight.mockRejectedValueOnce(new Error(`Block ${PRUNED_HEIGHT} not found`))
|
|
122
|
+
mockAxiosGet.mockRejectedValueOnce(new Error('Explorer unreachable'))
|
|
123
|
+
|
|
124
|
+
const wrapped = withNodeSources(api, config, testLogger)
|
|
125
|
+
await expect(wrapped.getBlockByHeight('monad_testnet', PRUNED_HEIGHT)).rejects.toThrow(
|
|
126
|
+
`Block ${PRUNED_HEIGHT} not found`
|
|
127
|
+
)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('tries explorer proxy on any node error, re-throws original error if explorer also fails', async () => {
|
|
131
|
+
const config = createMockEvmConfigInfo({
|
|
132
|
+
chainId: 1,
|
|
133
|
+
node,
|
|
134
|
+
explorer: mkEtherscanExplorer({ retries: 0 }),
|
|
135
|
+
nodeSources: nodeSourcesFromList(['node', 'explorer-proxy']),
|
|
136
|
+
})
|
|
137
|
+
api.getBlockByHeight.mockRejectedValueOnce(new Error('RPC connection timeout'))
|
|
138
|
+
mockAxiosGet.mockRejectedValueOnce(new Error('Explorer unreachable'))
|
|
139
|
+
|
|
140
|
+
const wrapped = withNodeSources(api, config, testLogger)
|
|
141
|
+
await expect(wrapped.getBlockByHeight('monad_testnet', PRUNED_HEIGHT)).rejects.toThrow(
|
|
142
|
+
'RPC connection timeout'
|
|
143
|
+
)
|
|
144
|
+
expect(mockAxiosGet).toHaveBeenCalled()
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
describe('getTransaction', () => {
|
|
149
|
+
const txResponse = {
|
|
150
|
+
data: {
|
|
151
|
+
result: {
|
|
152
|
+
hash: TX_HASH,
|
|
153
|
+
blockNumber: '0xe21953',
|
|
154
|
+
blockHash: '0xblockhash',
|
|
155
|
+
nonce: '0x1',
|
|
156
|
+
gasPrice: '0x3b9aca00',
|
|
157
|
+
value: '0xde0b6b3a7640000',
|
|
158
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
159
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
160
|
+
input: '0x',
|
|
161
|
+
type: '0x2',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
const receiptResponse = {
|
|
166
|
+
data: {
|
|
167
|
+
result: {
|
|
168
|
+
transactionHash: TX_HASH,
|
|
169
|
+
gasUsed: '0x5208',
|
|
170
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
171
|
+
status: '0x1',
|
|
172
|
+
logs: [],
|
|
173
|
+
type: '0x2',
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
it('forwards successful calls unchanged', async () => {
|
|
179
|
+
const config = createMockEvmConfigInfo({
|
|
180
|
+
chainId: 1,
|
|
181
|
+
node,
|
|
182
|
+
explorer: mkEtherscanExplorer(),
|
|
183
|
+
nodeSources: nodeSourcesFromList(['node', 'explorer-proxy']),
|
|
184
|
+
})
|
|
185
|
+
const txInfo = {
|
|
186
|
+
hash: TX_HASH,
|
|
187
|
+
blockHeight: 1,
|
|
188
|
+
blockHash: '0xbh',
|
|
189
|
+
nonce: 0,
|
|
190
|
+
gasUsed: '21000',
|
|
191
|
+
gasPrice: '1000000000',
|
|
192
|
+
status: 1,
|
|
193
|
+
value: '1000000000000000000',
|
|
194
|
+
from: '0xfrom',
|
|
195
|
+
to: '0xto',
|
|
196
|
+
erc20Transfers: [],
|
|
197
|
+
}
|
|
198
|
+
api.getTransaction.mockResolvedValueOnce(txInfo)
|
|
199
|
+
|
|
200
|
+
const wrapped = withNodeSources(api, config, testLogger)
|
|
201
|
+
await expect(wrapped.getTransaction('eth', TX_HASH)).resolves.toEqual(txInfo)
|
|
202
|
+
expect(mockAxiosGet).not.toHaveBeenCalled()
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
it('falls back to explorer proxy when RPC fails', async () => {
|
|
206
|
+
const config = createMockEvmConfigInfo({
|
|
207
|
+
chainId: 1,
|
|
208
|
+
node,
|
|
209
|
+
explorer: mkEtherscanExplorer({ uri: 'http://explorer.test' }),
|
|
210
|
+
nodeSources: nodeSourcesFromList(['node', 'explorer-proxy']),
|
|
211
|
+
})
|
|
212
|
+
api.getTransaction.mockRejectedValueOnce(new Error('Transaction not found'))
|
|
213
|
+
mockAxiosGet.mockResolvedValueOnce(txResponse).mockResolvedValueOnce(receiptResponse)
|
|
214
|
+
|
|
215
|
+
const wrapped = withNodeSources(api, config, testLogger)
|
|
216
|
+
const result = await wrapped.getTransaction('monad_testnet', TX_HASH)
|
|
217
|
+
|
|
218
|
+
expect(result.hash).toBe(TX_HASH)
|
|
219
|
+
expect(result.status).toBe(1)
|
|
220
|
+
expect(result.erc20Transfers).toEqual([])
|
|
221
|
+
expect(mockAxiosGet).toHaveBeenCalledTimes(2)
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('re-throws the original error when explorer also fails', async () => {
|
|
225
|
+
const config = createMockEvmConfigInfo({
|
|
226
|
+
chainId: 1,
|
|
227
|
+
node,
|
|
228
|
+
explorer: mkEtherscanExplorer({ retries: 0 }),
|
|
229
|
+
nodeSources: nodeSourcesFromList(['node', 'explorer-proxy']),
|
|
230
|
+
})
|
|
231
|
+
api.getTransaction.mockRejectedValueOnce(new Error('Transaction not found'))
|
|
232
|
+
mockAxiosGet.mockRejectedValue(new Error('Explorer unreachable'))
|
|
233
|
+
|
|
234
|
+
const wrapped = withNodeSources(api, config, testLogger)
|
|
235
|
+
await expect(wrapped.getTransaction('monad_testnet', TX_HASH)).rejects.toThrow(
|
|
236
|
+
'Transaction not found'
|
|
237
|
+
)
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
})
|