@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
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import axios from 'axios'
|
|
5
|
+
import { BigNumber } from 'bignumber.js'
|
|
6
|
+
import {
|
|
7
|
+
createMockEvmConfigInfo,
|
|
8
|
+
mkExternalNode,
|
|
9
|
+
testLogger,
|
|
10
|
+
} from '../../fixtures/context.fixtures'
|
|
11
|
+
import {
|
|
12
|
+
createExplorerProxyNodeApi,
|
|
13
|
+
getBlockFromExplorerProxy,
|
|
14
|
+
getTransactionFromExplorerProxy,
|
|
15
|
+
} from './explorerProxy'
|
|
16
|
+
|
|
17
|
+
jest.mock('axios')
|
|
18
|
+
const mockAxiosGet = jest.mocked(axios.get)
|
|
19
|
+
|
|
20
|
+
const EXPLORER_URI = 'http://explorer.test'
|
|
21
|
+
const TX_HASH = '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890ab'
|
|
22
|
+
|
|
23
|
+
describe('createExplorerProxyNodeApi', () => {
|
|
24
|
+
let api: ReturnType<typeof createExplorerProxyNodeApi>
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
jest.clearAllMocks()
|
|
27
|
+
api = createExplorerProxyNodeApi(EXPLORER_URI, 0, testLogger)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
describe('unsupported methods', () => {
|
|
31
|
+
it.each([
|
|
32
|
+
['call', () => api.call('eth', { to: '0x', data: '0x' })],
|
|
33
|
+
['getCoinBalance', () => api.getCoinBalance('eth', '0x')],
|
|
34
|
+
['getTokenBalance', () => api.getTokenBalance('eth', '0x', '0x')],
|
|
35
|
+
['getTokenAllowance', () => api.getTokenAllowance('eth', '0x', '0x', '0x')],
|
|
36
|
+
['getTransactionCount', () => api.getTransactionCount('eth', '0x')],
|
|
37
|
+
[
|
|
38
|
+
'getGasEstimation',
|
|
39
|
+
() => api.getGasEstimation('eth', '0x', { amount: new BigNumber(0), recipient: '0x' }),
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
'getFeeData',
|
|
43
|
+
() =>
|
|
44
|
+
api.getFeeData(
|
|
45
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
|
|
46
|
+
'eth',
|
|
47
|
+
{}
|
|
48
|
+
),
|
|
49
|
+
],
|
|
50
|
+
['broadcastTransaction', () => api.broadcastTransaction('eth', '0x')],
|
|
51
|
+
['getOptimismAdditionalFees', () => api.getOptimismAdditionalFees('eth', '0x')],
|
|
52
|
+
['getScrollAdditionalFees', () => api.getScrollAdditionalFees('eth', '0x')],
|
|
53
|
+
] as const)(
|
|
54
|
+
'%s rejects immediately with "not supported by explorer proxy"',
|
|
55
|
+
async (_name, invoke) => {
|
|
56
|
+
await expect(invoke()).rejects.toThrow('not supported by explorer proxy')
|
|
57
|
+
expect(mockAxiosGet).not.toHaveBeenCalled()
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('getBlockByHeight', () => {
|
|
63
|
+
it('throws before hitting the network when height is a BlockFinalizationTag', async () => {
|
|
64
|
+
await expect(api.getBlockByHeight('eth', 'latest')).rejects.toThrow(
|
|
65
|
+
'explorer proxy only supports numeric heights'
|
|
66
|
+
)
|
|
67
|
+
expect(mockAxiosGet).not.toHaveBeenCalled()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('throws when the proxy returns null (block not found or malformed)', async () => {
|
|
71
|
+
mockAxiosGet.mockResolvedValueOnce({ data: { result: null } })
|
|
72
|
+
await expect(api.getBlockByHeight('eth', 1)).rejects.toThrow(
|
|
73
|
+
'explorer proxy returned no result for block 1'
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('returns the block when the proxy succeeds', async () => {
|
|
78
|
+
mockAxiosGet.mockResolvedValueOnce({
|
|
79
|
+
data: {
|
|
80
|
+
result: {
|
|
81
|
+
hash: '0xdeadbeef',
|
|
82
|
+
number: '0x1',
|
|
83
|
+
timestamp: '0x6849e2a5',
|
|
84
|
+
parentHash: '0xparent',
|
|
85
|
+
transactions: ['0xhash1'],
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
const result = await api.getBlockByHeight('eth', 1)
|
|
90
|
+
expect(result.hash).toBe('0xdeadbeef')
|
|
91
|
+
expect(result.height).toBe(1)
|
|
92
|
+
expect(result.transactionHashes).toEqual(['0xhash1'])
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('propagates network errors as a throw (via the null path)', async () => {
|
|
96
|
+
mockAxiosGet.mockRejectedValueOnce(new Error('ECONNREFUSED'))
|
|
97
|
+
await expect(api.getBlockByHeight('eth', 1)).rejects.toThrow(
|
|
98
|
+
'explorer proxy returned no result for block 1'
|
|
99
|
+
)
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
describe('getTransaction', () => {
|
|
104
|
+
it('throws when the proxy returns null (tx not found)', async () => {
|
|
105
|
+
mockAxiosGet
|
|
106
|
+
.mockResolvedValueOnce({ data: { result: null } })
|
|
107
|
+
.mockResolvedValueOnce({ data: { result: null } })
|
|
108
|
+
await expect(api.getTransaction('eth', TX_HASH)).rejects.toThrow(
|
|
109
|
+
`explorer proxy returned no result for tx ${TX_HASH}`
|
|
110
|
+
)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('returns the transaction when the proxy succeeds', async () => {
|
|
114
|
+
mockAxiosGet
|
|
115
|
+
.mockResolvedValueOnce({
|
|
116
|
+
data: {
|
|
117
|
+
result: {
|
|
118
|
+
hash: TX_HASH,
|
|
119
|
+
blockNumber: '0x1',
|
|
120
|
+
blockHash: '0xblockhash',
|
|
121
|
+
nonce: '0x1',
|
|
122
|
+
gasPrice: '0x3b9aca00',
|
|
123
|
+
value: '0x0',
|
|
124
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
125
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
126
|
+
input: '0x',
|
|
127
|
+
type: '0x2',
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
})
|
|
131
|
+
.mockResolvedValueOnce({
|
|
132
|
+
data: {
|
|
133
|
+
result: {
|
|
134
|
+
transactionHash: TX_HASH,
|
|
135
|
+
gasUsed: '0x5208',
|
|
136
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
137
|
+
status: '0x1',
|
|
138
|
+
logs: [],
|
|
139
|
+
type: '0x2',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
const result = await api.getTransaction('eth', TX_HASH)
|
|
144
|
+
expect(result.hash).toBe(TX_HASH)
|
|
145
|
+
expect(result.status).toBe(1)
|
|
146
|
+
expect(result.erc20Transfers).toEqual([])
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('propagates network errors as a throw (via the null path)', async () => {
|
|
150
|
+
mockAxiosGet.mockRejectedValue(new Error('ECONNREFUSED'))
|
|
151
|
+
await expect(api.getTransaction('eth', TX_HASH)).rejects.toThrow(
|
|
152
|
+
`explorer proxy returned no result for tx ${TX_HASH}`
|
|
153
|
+
)
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
describe('getBlockFromExplorerProxy', () => {
|
|
159
|
+
const HEIGHT = 14817811
|
|
160
|
+
const HEIGHT_HEX = '0x' + HEIGHT.toString(16)
|
|
161
|
+
|
|
162
|
+
beforeEach(() => jest.clearAllMocks())
|
|
163
|
+
|
|
164
|
+
it('parses hex fields and populates transactionHashes from the hash array', async () => {
|
|
165
|
+
mockAxiosGet.mockResolvedValueOnce({
|
|
166
|
+
data: {
|
|
167
|
+
result: {
|
|
168
|
+
hash: '0xdeadbeef',
|
|
169
|
+
number: HEIGHT_HEX,
|
|
170
|
+
timestamp: '0x6849e2a5',
|
|
171
|
+
parentHash: '0xparent',
|
|
172
|
+
transactions: ['0xhash1', '0xhash2'],
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
const result = await getBlockFromExplorerProxy(EXPLORER_URI, HEIGHT)
|
|
178
|
+
|
|
179
|
+
expect(result).toMatchObject({ hash: '0xdeadbeef', height: HEIGHT, parentHash: '0xparent' })
|
|
180
|
+
expect(result?.timestamp).toBe(Number(BigInt('0x6849e2a5')) * 1000)
|
|
181
|
+
expect(result?.transactionHashes).toEqual(['0xhash1', '0xhash2'])
|
|
182
|
+
expect(result?.transactions).toBeUndefined()
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it('accepts a decimal block number (some explorer implementations omit the 0x prefix)', async () => {
|
|
186
|
+
mockAxiosGet.mockResolvedValueOnce({
|
|
187
|
+
data: {
|
|
188
|
+
result: {
|
|
189
|
+
hash: '0xdeadbeef',
|
|
190
|
+
number: '1',
|
|
191
|
+
timestamp: '0x6849e2a5',
|
|
192
|
+
parentHash: '0xparent',
|
|
193
|
+
transactions: [],
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
})
|
|
197
|
+
const result = await getBlockFromExplorerProxy(EXPLORER_URI, 1)
|
|
198
|
+
expect(result?.height).toBe(1)
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
it('returns null when block number does not match the requested height', async () => {
|
|
202
|
+
mockAxiosGet.mockResolvedValueOnce({
|
|
203
|
+
data: {
|
|
204
|
+
result: {
|
|
205
|
+
hash: '0xdeadbeef',
|
|
206
|
+
number: '0x2',
|
|
207
|
+
timestamp: '0x6849e2a5',
|
|
208
|
+
parentHash: '0xparent',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('returns null when block number is absent', async () => {
|
|
216
|
+
mockAxiosGet.mockResolvedValueOnce({
|
|
217
|
+
data: {
|
|
218
|
+
result: {
|
|
219
|
+
hash: '0xdeadbeef',
|
|
220
|
+
timestamp: '0x6849e2a5',
|
|
221
|
+
parentHash: '0xparent',
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
})
|
|
225
|
+
expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('returns null when timestamp or parentHash are missing', async () => {
|
|
229
|
+
mockAxiosGet.mockResolvedValueOnce({
|
|
230
|
+
data: {
|
|
231
|
+
result: {
|
|
232
|
+
hash: '0xdeadbeef',
|
|
233
|
+
number: '0x1',
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
})
|
|
237
|
+
expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
it('returns null when result hash is all zeros', async () => {
|
|
241
|
+
mockAxiosGet.mockResolvedValueOnce({
|
|
242
|
+
data: {
|
|
243
|
+
result: { hash: '0x' + '0'.repeat(64), number: '0x1', timestamp: '0x1', parentHash: '0x0' },
|
|
244
|
+
},
|
|
245
|
+
})
|
|
246
|
+
expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
it('returns null when transactions field is not an array', async () => {
|
|
250
|
+
mockAxiosGet.mockResolvedValueOnce({
|
|
251
|
+
data: {
|
|
252
|
+
result: {
|
|
253
|
+
hash: '0xdeadbeef',
|
|
254
|
+
number: '0x1',
|
|
255
|
+
timestamp: '0x6849e2a5',
|
|
256
|
+
parentHash: '0xparent',
|
|
257
|
+
transactions: 'not-an-array',
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
})
|
|
261
|
+
expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
it('returns null when the transactions array contains a non-string entry', async () => {
|
|
265
|
+
mockAxiosGet.mockResolvedValueOnce({
|
|
266
|
+
data: {
|
|
267
|
+
result: {
|
|
268
|
+
hash: '0xdeadbeef',
|
|
269
|
+
number: '0x1',
|
|
270
|
+
timestamp: '0x6849e2a5',
|
|
271
|
+
parentHash: '0xparent',
|
|
272
|
+
transactions: ['0xhash1', 123],
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
})
|
|
276
|
+
expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
it('returns null on network error', async () => {
|
|
280
|
+
mockAxiosGet.mockRejectedValueOnce(new Error('ECONNREFUSED'))
|
|
281
|
+
expect(await getBlockFromExplorerProxy(EXPLORER_URI, 1)).toBeNull()
|
|
282
|
+
})
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
describe('getTransactionFromExplorerProxy', () => {
|
|
286
|
+
beforeEach(() => jest.clearAllMocks())
|
|
287
|
+
|
|
288
|
+
it('returns a parsed TransactionInfo on success', async () => {
|
|
289
|
+
mockAxiosGet
|
|
290
|
+
.mockResolvedValueOnce({
|
|
291
|
+
data: {
|
|
292
|
+
result: {
|
|
293
|
+
hash: TX_HASH,
|
|
294
|
+
blockNumber: '0x1',
|
|
295
|
+
blockHash: '0xblockhash',
|
|
296
|
+
nonce: '0x1',
|
|
297
|
+
gasPrice: '0x3b9aca00',
|
|
298
|
+
value: '0xde0b6b3a7640000',
|
|
299
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
300
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
301
|
+
input: '0x',
|
|
302
|
+
type: '0x2',
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
})
|
|
306
|
+
.mockResolvedValueOnce({
|
|
307
|
+
data: {
|
|
308
|
+
result: {
|
|
309
|
+
transactionHash: TX_HASH,
|
|
310
|
+
gasUsed: '0x5208',
|
|
311
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
312
|
+
status: '0x1',
|
|
313
|
+
logs: [],
|
|
314
|
+
type: '0x2',
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
const result = await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)
|
|
320
|
+
|
|
321
|
+
expect(result?.hash).toBe(TX_HASH)
|
|
322
|
+
expect(result?.blockHeight).toBe(1)
|
|
323
|
+
expect(result?.gasUsed).toBe('21000')
|
|
324
|
+
expect(result?.status).toBe(1)
|
|
325
|
+
expect(result?.erc20Transfers).toEqual([])
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
it('includes l1Fee from receipt when present (OP-stack chains)', async () => {
|
|
329
|
+
mockAxiosGet
|
|
330
|
+
.mockResolvedValueOnce({
|
|
331
|
+
data: {
|
|
332
|
+
result: {
|
|
333
|
+
hash: TX_HASH,
|
|
334
|
+
blockNumber: '0x1',
|
|
335
|
+
blockHash: '0xblockhash',
|
|
336
|
+
nonce: '0x1',
|
|
337
|
+
gasPrice: '0x3b9aca00',
|
|
338
|
+
value: '0x0',
|
|
339
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
340
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
341
|
+
input: '0x',
|
|
342
|
+
type: '0x0',
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
})
|
|
346
|
+
.mockResolvedValueOnce({
|
|
347
|
+
data: {
|
|
348
|
+
result: {
|
|
349
|
+
transactionHash: TX_HASH,
|
|
350
|
+
gasUsed: '0x5208',
|
|
351
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
352
|
+
status: '0x1',
|
|
353
|
+
logs: [],
|
|
354
|
+
type: '0x0',
|
|
355
|
+
l1Fee: '0x1234',
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
const result = await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)
|
|
361
|
+
|
|
362
|
+
expect(result?.l1Fee).toBe(String(BigInt('0x1234')))
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
it('falls back to receipt.gasPrice when effectiveGasPrice is absent', async () => {
|
|
366
|
+
mockAxiosGet
|
|
367
|
+
.mockResolvedValueOnce({
|
|
368
|
+
data: {
|
|
369
|
+
result: {
|
|
370
|
+
hash: TX_HASH,
|
|
371
|
+
blockNumber: '0x1',
|
|
372
|
+
blockHash: '0xblockhash',
|
|
373
|
+
nonce: '0x1',
|
|
374
|
+
gasPrice: '0xdeadbeef',
|
|
375
|
+
value: '0x0',
|
|
376
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
377
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
378
|
+
input: '0x',
|
|
379
|
+
type: '0x0',
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
})
|
|
383
|
+
.mockResolvedValueOnce({
|
|
384
|
+
data: {
|
|
385
|
+
result: {
|
|
386
|
+
transactionHash: TX_HASH,
|
|
387
|
+
gasUsed: '0x5208',
|
|
388
|
+
gasPrice: '0xcafebabe',
|
|
389
|
+
status: '0x1',
|
|
390
|
+
logs: [],
|
|
391
|
+
type: '0x0',
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
const result = await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)
|
|
397
|
+
|
|
398
|
+
expect(result?.gasPrice).toBe(String(BigInt('0xcafebabe')))
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
it('handles contract-creation txs (to is null, contractAddress present)', async () => {
|
|
402
|
+
mockAxiosGet
|
|
403
|
+
.mockResolvedValueOnce({
|
|
404
|
+
data: {
|
|
405
|
+
result: {
|
|
406
|
+
hash: TX_HASH,
|
|
407
|
+
blockNumber: '0x1',
|
|
408
|
+
nonce: '0x0',
|
|
409
|
+
gasPrice: '0x3b9aca00',
|
|
410
|
+
value: '0x0',
|
|
411
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
412
|
+
to: null,
|
|
413
|
+
input: '0x6080',
|
|
414
|
+
type: '0x0',
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
})
|
|
418
|
+
.mockResolvedValueOnce({
|
|
419
|
+
data: {
|
|
420
|
+
result: {
|
|
421
|
+
transactionHash: TX_HASH,
|
|
422
|
+
gasUsed: '0x5208',
|
|
423
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
424
|
+
status: '0x1',
|
|
425
|
+
logs: [],
|
|
426
|
+
type: '0x0',
|
|
427
|
+
contractAddress: '0xaabbcc0000000000000000000000000000000099',
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
const result = await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)
|
|
433
|
+
|
|
434
|
+
expect(result?.to).toBeUndefined()
|
|
435
|
+
expect(result?.contractAddress).toBe('0xaabbcc0000000000000000000000000000000099')
|
|
436
|
+
})
|
|
437
|
+
|
|
438
|
+
it('returns null when proxy returns a tx hash that does not match the request', async () => {
|
|
439
|
+
mockAxiosGet
|
|
440
|
+
.mockResolvedValueOnce({
|
|
441
|
+
data: {
|
|
442
|
+
result: {
|
|
443
|
+
hash: '0x' + 'a'.repeat(64),
|
|
444
|
+
blockNumber: '0x1',
|
|
445
|
+
blockHash: '0xblockhash',
|
|
446
|
+
nonce: '0x1',
|
|
447
|
+
gasPrice: '0x3b9aca00',
|
|
448
|
+
value: '0x0',
|
|
449
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
450
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
451
|
+
input: '0x',
|
|
452
|
+
type: '0x2',
|
|
453
|
+
},
|
|
454
|
+
},
|
|
455
|
+
})
|
|
456
|
+
.mockResolvedValueOnce({ data: { result: null } })
|
|
457
|
+
|
|
458
|
+
expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
|
|
459
|
+
})
|
|
460
|
+
|
|
461
|
+
it('returns null when a required field (gasUsed) is absent from the receipt', async () => {
|
|
462
|
+
mockAxiosGet
|
|
463
|
+
.mockResolvedValueOnce({
|
|
464
|
+
data: {
|
|
465
|
+
result: {
|
|
466
|
+
hash: TX_HASH,
|
|
467
|
+
blockNumber: '0x1',
|
|
468
|
+
blockHash: '0xblockhash',
|
|
469
|
+
nonce: '0x1',
|
|
470
|
+
gasPrice: '0x3b9aca00',
|
|
471
|
+
value: '0x0',
|
|
472
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
473
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
474
|
+
input: '0x',
|
|
475
|
+
type: '0x2',
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
})
|
|
479
|
+
.mockResolvedValueOnce({
|
|
480
|
+
data: {
|
|
481
|
+
result: {
|
|
482
|
+
transactionHash: TX_HASH,
|
|
483
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
484
|
+
status: '0x1',
|
|
485
|
+
logs: [],
|
|
486
|
+
type: '0x2',
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
})
|
|
490
|
+
|
|
491
|
+
expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
it('returns null when the receipt contains a malformed hex quantity', async () => {
|
|
495
|
+
mockAxiosGet
|
|
496
|
+
.mockResolvedValueOnce({
|
|
497
|
+
data: {
|
|
498
|
+
result: {
|
|
499
|
+
hash: TX_HASH,
|
|
500
|
+
blockNumber: '0x1',
|
|
501
|
+
blockHash: '0xblockhash',
|
|
502
|
+
nonce: '0x1',
|
|
503
|
+
gasPrice: '0x3b9aca00',
|
|
504
|
+
value: '0x0',
|
|
505
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
506
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
507
|
+
input: '0x',
|
|
508
|
+
type: '0x2',
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
})
|
|
512
|
+
.mockResolvedValueOnce({
|
|
513
|
+
data: {
|
|
514
|
+
result: {
|
|
515
|
+
transactionHash: TX_HASH,
|
|
516
|
+
gasUsed: 'invalid',
|
|
517
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
518
|
+
status: '0x1',
|
|
519
|
+
logs: [],
|
|
520
|
+
type: '0x2',
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
})
|
|
524
|
+
|
|
525
|
+
expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
|
|
526
|
+
})
|
|
527
|
+
|
|
528
|
+
it('returns null when logs is absent from the receipt', async () => {
|
|
529
|
+
mockAxiosGet
|
|
530
|
+
.mockResolvedValueOnce({
|
|
531
|
+
data: {
|
|
532
|
+
result: {
|
|
533
|
+
hash: TX_HASH,
|
|
534
|
+
blockNumber: '0x1',
|
|
535
|
+
blockHash: '0xblockhash',
|
|
536
|
+
nonce: '0x1',
|
|
537
|
+
gasPrice: '0x3b9aca00',
|
|
538
|
+
value: '0x0',
|
|
539
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
540
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
541
|
+
input: '0x',
|
|
542
|
+
type: '0x2',
|
|
543
|
+
},
|
|
544
|
+
},
|
|
545
|
+
})
|
|
546
|
+
.mockResolvedValueOnce({
|
|
547
|
+
data: {
|
|
548
|
+
result: {
|
|
549
|
+
transactionHash: TX_HASH,
|
|
550
|
+
gasUsed: '0x5208',
|
|
551
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
552
|
+
status: '0x1',
|
|
553
|
+
type: '0x2',
|
|
554
|
+
},
|
|
555
|
+
},
|
|
556
|
+
})
|
|
557
|
+
|
|
558
|
+
expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
|
|
559
|
+
})
|
|
560
|
+
|
|
561
|
+
it('returns null when a log entry has a malformed field (missing address)', async () => {
|
|
562
|
+
mockAxiosGet
|
|
563
|
+
.mockResolvedValueOnce({
|
|
564
|
+
data: {
|
|
565
|
+
result: {
|
|
566
|
+
hash: TX_HASH,
|
|
567
|
+
blockNumber: '0x1',
|
|
568
|
+
nonce: '0x1',
|
|
569
|
+
gasPrice: '0x3b9aca00',
|
|
570
|
+
value: '0x0',
|
|
571
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
572
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
573
|
+
input: '0x',
|
|
574
|
+
type: '0x2',
|
|
575
|
+
},
|
|
576
|
+
},
|
|
577
|
+
})
|
|
578
|
+
.mockResolvedValueOnce({
|
|
579
|
+
data: {
|
|
580
|
+
result: {
|
|
581
|
+
transactionHash: TX_HASH,
|
|
582
|
+
gasUsed: '0x5208',
|
|
583
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
584
|
+
status: '0x1',
|
|
585
|
+
logs: [{ topics: [], data: '0x' }],
|
|
586
|
+
type: '0x2',
|
|
587
|
+
},
|
|
588
|
+
},
|
|
589
|
+
})
|
|
590
|
+
|
|
591
|
+
expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
|
|
592
|
+
})
|
|
593
|
+
|
|
594
|
+
it('returns null when from is absent from the transaction', async () => {
|
|
595
|
+
mockAxiosGet
|
|
596
|
+
.mockResolvedValueOnce({
|
|
597
|
+
data: {
|
|
598
|
+
result: {
|
|
599
|
+
hash: TX_HASH,
|
|
600
|
+
blockNumber: '0x1',
|
|
601
|
+
blockHash: '0xblockhash',
|
|
602
|
+
nonce: '0x1',
|
|
603
|
+
gasPrice: '0x3b9aca00',
|
|
604
|
+
value: '0x0',
|
|
605
|
+
to: '0xaabbcc0000000000000000000000000000000002',
|
|
606
|
+
input: '0x',
|
|
607
|
+
type: '0x2',
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
})
|
|
611
|
+
.mockResolvedValueOnce({
|
|
612
|
+
data: {
|
|
613
|
+
result: {
|
|
614
|
+
transactionHash: TX_HASH,
|
|
615
|
+
gasUsed: '0x5208',
|
|
616
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
617
|
+
status: '0x1',
|
|
618
|
+
logs: [],
|
|
619
|
+
type: '0x2',
|
|
620
|
+
},
|
|
621
|
+
},
|
|
622
|
+
})
|
|
623
|
+
|
|
624
|
+
expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
|
|
625
|
+
})
|
|
626
|
+
|
|
627
|
+
it('returns null when to is a malformed type (neither string nor null)', async () => {
|
|
628
|
+
mockAxiosGet
|
|
629
|
+
.mockResolvedValueOnce({
|
|
630
|
+
data: {
|
|
631
|
+
result: {
|
|
632
|
+
hash: TX_HASH,
|
|
633
|
+
blockNumber: '0x1',
|
|
634
|
+
blockHash: '0xblockhash',
|
|
635
|
+
nonce: '0x1',
|
|
636
|
+
gasPrice: '0x3b9aca00',
|
|
637
|
+
value: '0x0',
|
|
638
|
+
from: '0xaabbcc0000000000000000000000000000000001',
|
|
639
|
+
to: 12345,
|
|
640
|
+
input: '0x',
|
|
641
|
+
type: '0x2',
|
|
642
|
+
},
|
|
643
|
+
},
|
|
644
|
+
})
|
|
645
|
+
.mockResolvedValueOnce({
|
|
646
|
+
data: {
|
|
647
|
+
result: {
|
|
648
|
+
transactionHash: TX_HASH,
|
|
649
|
+
gasUsed: '0x5208',
|
|
650
|
+
effectiveGasPrice: '0x3b9aca00',
|
|
651
|
+
status: '0x1',
|
|
652
|
+
logs: [],
|
|
653
|
+
type: '0x2',
|
|
654
|
+
},
|
|
655
|
+
},
|
|
656
|
+
})
|
|
657
|
+
|
|
658
|
+
expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
|
|
659
|
+
})
|
|
660
|
+
|
|
661
|
+
it('returns null when tx is not found', async () => {
|
|
662
|
+
mockAxiosGet
|
|
663
|
+
.mockResolvedValueOnce({ data: { result: null } })
|
|
664
|
+
.mockResolvedValueOnce({ data: { result: null } })
|
|
665
|
+
|
|
666
|
+
expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
|
|
667
|
+
})
|
|
668
|
+
|
|
669
|
+
it('returns null on network error', async () => {
|
|
670
|
+
mockAxiosGet.mockRejectedValue(new Error('ECONNREFUSED'))
|
|
671
|
+
expect(await getTransactionFromExplorerProxy(EXPLORER_URI, TX_HASH)).toBeNull()
|
|
672
|
+
})
|
|
673
|
+
})
|