@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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { PagingState } from '../../adapters'
|
|
5
|
-
import type { NftStandard } from '../../config'
|
|
5
|
+
import type { EvmConfigInfo, NftStandard } from '../../config'
|
|
6
6
|
import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
7
7
|
import type { AxiosRequestConfig } from 'axios'
|
|
8
8
|
import { AssertionError, fail } from 'assert'
|
|
@@ -17,13 +17,16 @@ import {
|
|
|
17
17
|
deserializePagingToken,
|
|
18
18
|
serializePagingToken,
|
|
19
19
|
} from '../../adapters'
|
|
20
|
-
import { getCoinConfig } from '../../config'
|
|
21
20
|
import {
|
|
22
21
|
EtherscanAPIError,
|
|
23
22
|
EtherscanLikeExplorerUsedIncorrectly,
|
|
24
23
|
RateLimitError,
|
|
25
24
|
} from '../../errors'
|
|
26
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
createMockEvmConfigInfo,
|
|
27
|
+
mkExternalNode,
|
|
28
|
+
testLogger,
|
|
29
|
+
} from '../../fixtures/context.fixtures'
|
|
27
30
|
import {
|
|
28
31
|
etherscanCoinOperations,
|
|
29
32
|
etherscanERC1155Operations,
|
|
@@ -39,11 +42,9 @@ jest.mocked(delay).mockImplementation(
|
|
|
39
42
|
() => new Promise((resolve) => setTimeout(resolve, 1)) // mocking the delay supposed to happen after each try
|
|
40
43
|
)
|
|
41
44
|
|
|
42
|
-
jest.mock('../../config')
|
|
43
|
-
const mockGetConfig = jest.mocked(getCoinConfig)
|
|
44
|
-
|
|
45
45
|
const currencyId = 'ethereum'
|
|
46
46
|
const address = '0x6cBCD73CD8e8a42844662f0A0e76D7F79Afd933d'
|
|
47
|
+
let config: EvmConfigInfo
|
|
47
48
|
|
|
48
49
|
// Factory to create fetch utilities for isPageFull/isDone tests
|
|
49
50
|
const createFetchWithLimit =
|
|
@@ -56,7 +57,7 @@ const createFetchWithLimit =
|
|
|
56
57
|
})
|
|
57
58
|
return apiFn({
|
|
58
59
|
currencyId: currencyId,
|
|
59
|
-
config
|
|
60
|
+
config,
|
|
60
61
|
address: address,
|
|
61
62
|
fromBlock: 0,
|
|
62
63
|
sort,
|
|
@@ -73,14 +74,12 @@ const paginationState = (result: ETHERSCAN_API.EndpointResult) => ({
|
|
|
73
74
|
|
|
74
75
|
describe('EVM Family', () => {
|
|
75
76
|
beforeEach(() => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
})
|
|
83
|
-
)
|
|
77
|
+
config = createMockEvmConfigInfo({
|
|
78
|
+
chainId: 1,
|
|
79
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
80
|
+
explorer: { type: 'etherscan', uri: 'mock' },
|
|
81
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
82
|
+
})
|
|
84
83
|
})
|
|
85
84
|
|
|
86
85
|
afterAll(() => {
|
|
@@ -193,7 +192,7 @@ describe('EVM Family', () => {
|
|
|
193
192
|
|
|
194
193
|
const response = await getOperations({
|
|
195
194
|
currencyId,
|
|
196
|
-
config
|
|
195
|
+
config,
|
|
197
196
|
address,
|
|
198
197
|
fromBlock: 0,
|
|
199
198
|
sort: 'asc',
|
|
@@ -215,9 +214,7 @@ describe('EVM Family', () => {
|
|
|
215
214
|
})
|
|
216
215
|
|
|
217
216
|
it('should throw an error if the currency is misconfigured', async () => {
|
|
218
|
-
|
|
219
|
-
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
220
|
-
)
|
|
217
|
+
config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
221
218
|
|
|
222
219
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
223
220
|
data: {
|
|
@@ -228,7 +225,7 @@ describe('EVM Family', () => {
|
|
|
228
225
|
try {
|
|
229
226
|
await ETHERSCAN_API.getCoinOperations({
|
|
230
227
|
currencyId: currencyId,
|
|
231
|
-
config
|
|
228
|
+
config,
|
|
232
229
|
address: address,
|
|
233
230
|
fromBlock: 0,
|
|
234
231
|
sort: 'desc',
|
|
@@ -251,7 +248,7 @@ describe('EVM Family', () => {
|
|
|
251
248
|
|
|
252
249
|
const response = await ETHERSCAN_API.getCoinOperations({
|
|
253
250
|
currencyId: currencyId,
|
|
254
|
-
config
|
|
251
|
+
config,
|
|
255
252
|
address: address,
|
|
256
253
|
fromBlock: 0,
|
|
257
254
|
sort: 'desc',
|
|
@@ -288,7 +285,7 @@ describe('EVM Family', () => {
|
|
|
288
285
|
|
|
289
286
|
const response = await ETHERSCAN_API.getCoinOperations({
|
|
290
287
|
currencyId: currencyId,
|
|
291
|
-
config
|
|
288
|
+
config,
|
|
292
289
|
address: address,
|
|
293
290
|
fromBlock: 50,
|
|
294
291
|
sort: 'desc',
|
|
@@ -325,7 +322,7 @@ describe('EVM Family', () => {
|
|
|
325
322
|
|
|
326
323
|
const response = await ETHERSCAN_API.getCoinOperations({
|
|
327
324
|
currencyId: currencyId,
|
|
328
|
-
config
|
|
325
|
+
config,
|
|
329
326
|
address: address,
|
|
330
327
|
fromBlock: 50,
|
|
331
328
|
toBlock: 100,
|
|
@@ -432,9 +429,7 @@ describe('EVM Family', () => {
|
|
|
432
429
|
})
|
|
433
430
|
|
|
434
431
|
it('should throw if the currency is misconfigured', async () => {
|
|
435
|
-
|
|
436
|
-
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
437
|
-
)
|
|
432
|
+
config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
438
433
|
|
|
439
434
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
440
435
|
data: {
|
|
@@ -445,7 +440,7 @@ describe('EVM Family', () => {
|
|
|
445
440
|
try {
|
|
446
441
|
await ETHERSCAN_API.getTokenOperations({
|
|
447
442
|
currencyId: currencyId,
|
|
448
|
-
config
|
|
443
|
+
config,
|
|
449
444
|
address: address,
|
|
450
445
|
fromBlock: 0,
|
|
451
446
|
sort: 'desc',
|
|
@@ -468,7 +463,7 @@ describe('EVM Family', () => {
|
|
|
468
463
|
|
|
469
464
|
const response = await ETHERSCAN_API.getTokenOperations({
|
|
470
465
|
currencyId: currencyId,
|
|
471
|
-
config
|
|
466
|
+
config,
|
|
472
467
|
address: address,
|
|
473
468
|
fromBlock: 0,
|
|
474
469
|
sort: 'desc',
|
|
@@ -507,7 +502,7 @@ describe('EVM Family', () => {
|
|
|
507
502
|
|
|
508
503
|
const response = await ETHERSCAN_API.getTokenOperations({
|
|
509
504
|
currencyId: currencyId,
|
|
510
|
-
config
|
|
505
|
+
config,
|
|
511
506
|
address: address,
|
|
512
507
|
fromBlock: 50,
|
|
513
508
|
sort: 'desc',
|
|
@@ -546,7 +541,7 @@ describe('EVM Family', () => {
|
|
|
546
541
|
|
|
547
542
|
const response = await ETHERSCAN_API.getTokenOperations({
|
|
548
543
|
currencyId: currencyId,
|
|
549
|
-
config
|
|
544
|
+
config,
|
|
550
545
|
address: address,
|
|
551
546
|
fromBlock: 50,
|
|
552
547
|
toBlock: 100,
|
|
@@ -655,16 +650,15 @@ describe('EVM Family', () => {
|
|
|
655
650
|
// The contract used by all entries in etherscanTokenOperations.
|
|
656
651
|
const FIXTURE_CONTRACT = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
|
|
657
652
|
|
|
658
|
-
const withConfig = (info: { nativeContracts?: string[] }) =>
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
)
|
|
653
|
+
const withConfig = (info: { nativeContracts?: string[] }) => {
|
|
654
|
+
config = createMockEvmConfigInfo({
|
|
655
|
+
chainId: 1,
|
|
656
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
657
|
+
explorer: { type: 'etherscan', uri: 'mock' },
|
|
658
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
659
|
+
...info,
|
|
660
|
+
})
|
|
661
|
+
}
|
|
668
662
|
|
|
669
663
|
it('drops ERC20 ops whose contract is listed in nativeContracts', async () => {
|
|
670
664
|
withConfig({ nativeContracts: [FIXTURE_CONTRACT] })
|
|
@@ -674,7 +668,7 @@ describe('EVM Family', () => {
|
|
|
674
668
|
|
|
675
669
|
const response = await ETHERSCAN_API.getTokenOperations({
|
|
676
670
|
currencyId: currencyId,
|
|
677
|
-
config
|
|
671
|
+
config,
|
|
678
672
|
address: address,
|
|
679
673
|
fromBlock: 0,
|
|
680
674
|
sort: 'desc',
|
|
@@ -691,7 +685,7 @@ describe('EVM Family', () => {
|
|
|
691
685
|
|
|
692
686
|
const response = await ETHERSCAN_API.getTokenOperations({
|
|
693
687
|
currencyId: currencyId,
|
|
694
|
-
config
|
|
688
|
+
config,
|
|
695
689
|
address: address,
|
|
696
690
|
fromBlock: 0,
|
|
697
691
|
sort: 'desc',
|
|
@@ -708,7 +702,7 @@ describe('EVM Family', () => {
|
|
|
708
702
|
|
|
709
703
|
const response = await ETHERSCAN_API.getTokenOperations({
|
|
710
704
|
currencyId: currencyId,
|
|
711
|
-
config
|
|
705
|
+
config,
|
|
712
706
|
address: address,
|
|
713
707
|
fromBlock: 0,
|
|
714
708
|
sort: 'desc',
|
|
@@ -726,7 +720,7 @@ describe('EVM Family', () => {
|
|
|
726
720
|
|
|
727
721
|
const response = await ETHERSCAN_API.getTokenOperations({
|
|
728
722
|
currencyId: currencyId,
|
|
729
|
-
config
|
|
723
|
+
config,
|
|
730
724
|
address: address,
|
|
731
725
|
fromBlock: 0,
|
|
732
726
|
sort: 'desc',
|
|
@@ -743,9 +737,7 @@ describe('EVM Family', () => {
|
|
|
743
737
|
})
|
|
744
738
|
|
|
745
739
|
it('should return an empty array if the currency is misconfigured', async () => {
|
|
746
|
-
|
|
747
|
-
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
748
|
-
)
|
|
740
|
+
config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
749
741
|
|
|
750
742
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
751
743
|
data: {
|
|
@@ -756,7 +748,7 @@ describe('EVM Family', () => {
|
|
|
756
748
|
try {
|
|
757
749
|
await ETHERSCAN_API.getERC721Operations({
|
|
758
750
|
currencyId: currencyId,
|
|
759
|
-
config
|
|
751
|
+
config,
|
|
760
752
|
address: address,
|
|
761
753
|
fromBlock: 0,
|
|
762
754
|
sort: 'desc',
|
|
@@ -779,7 +771,7 @@ describe('EVM Family', () => {
|
|
|
779
771
|
|
|
780
772
|
const response = await ETHERSCAN_API.getERC721Operations({
|
|
781
773
|
currencyId: currencyId,
|
|
782
|
-
config
|
|
774
|
+
config,
|
|
783
775
|
address: address,
|
|
784
776
|
fromBlock: 0,
|
|
785
777
|
sort: 'desc',
|
|
@@ -817,7 +809,7 @@ describe('EVM Family', () => {
|
|
|
817
809
|
|
|
818
810
|
const response = await ETHERSCAN_API.getERC721Operations({
|
|
819
811
|
currencyId: currencyId,
|
|
820
|
-
config
|
|
812
|
+
config,
|
|
821
813
|
address: address,
|
|
822
814
|
fromBlock: 50,
|
|
823
815
|
sort: 'desc',
|
|
@@ -855,7 +847,7 @@ describe('EVM Family', () => {
|
|
|
855
847
|
|
|
856
848
|
const response = await ETHERSCAN_API.getERC721Operations({
|
|
857
849
|
currencyId: currencyId,
|
|
858
|
-
config
|
|
850
|
+
config,
|
|
859
851
|
address: address,
|
|
860
852
|
fromBlock: 50,
|
|
861
853
|
toBlock: 100,
|
|
@@ -967,9 +959,7 @@ describe('EVM Family', () => {
|
|
|
967
959
|
})
|
|
968
960
|
|
|
969
961
|
it('should return an empty array if the currency is misconfigured', async () => {
|
|
970
|
-
|
|
971
|
-
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
972
|
-
)
|
|
962
|
+
config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
973
963
|
|
|
974
964
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
975
965
|
data: {
|
|
@@ -980,7 +970,7 @@ describe('EVM Family', () => {
|
|
|
980
970
|
try {
|
|
981
971
|
await ETHERSCAN_API.getERC1155Operations({
|
|
982
972
|
currencyId: currencyId,
|
|
983
|
-
config
|
|
973
|
+
config,
|
|
984
974
|
address: address,
|
|
985
975
|
fromBlock: 0,
|
|
986
976
|
sort: 'desc',
|
|
@@ -1003,7 +993,7 @@ describe('EVM Family', () => {
|
|
|
1003
993
|
|
|
1004
994
|
const response = await ETHERSCAN_API.getERC1155Operations({
|
|
1005
995
|
currencyId: currencyId,
|
|
1006
|
-
config
|
|
996
|
+
config,
|
|
1007
997
|
address: address,
|
|
1008
998
|
fromBlock: 0,
|
|
1009
999
|
sort: 'desc',
|
|
@@ -1041,7 +1031,7 @@ describe('EVM Family', () => {
|
|
|
1041
1031
|
|
|
1042
1032
|
const response = await ETHERSCAN_API.getERC1155Operations({
|
|
1043
1033
|
currencyId: currencyId,
|
|
1044
|
-
config
|
|
1034
|
+
config,
|
|
1045
1035
|
address: address,
|
|
1046
1036
|
fromBlock: 50,
|
|
1047
1037
|
sort: 'desc',
|
|
@@ -1079,7 +1069,7 @@ describe('EVM Family', () => {
|
|
|
1079
1069
|
|
|
1080
1070
|
const response = await ETHERSCAN_API.getERC1155Operations({
|
|
1081
1071
|
currencyId: currencyId,
|
|
1082
|
-
config
|
|
1072
|
+
config,
|
|
1083
1073
|
address: address,
|
|
1084
1074
|
fromBlock: 50,
|
|
1085
1075
|
toBlock: 100,
|
|
@@ -1197,7 +1187,7 @@ describe('EVM Family', () => {
|
|
|
1197
1187
|
|
|
1198
1188
|
const response = await ETHERSCAN_API.getNftOperations({
|
|
1199
1189
|
currencyId: currencyId,
|
|
1200
|
-
config
|
|
1190
|
+
config,
|
|
1201
1191
|
address: address,
|
|
1202
1192
|
fromBlock: 0,
|
|
1203
1193
|
sort: 'desc',
|
|
@@ -1230,7 +1220,7 @@ describe('EVM Family', () => {
|
|
|
1230
1220
|
}))
|
|
1231
1221
|
return ETHERSCAN_API.getNftOperations({
|
|
1232
1222
|
currencyId: currencyId,
|
|
1233
|
-
config
|
|
1223
|
+
config,
|
|
1234
1224
|
address: address,
|
|
1235
1225
|
fromBlock: 0,
|
|
1236
1226
|
sort,
|
|
@@ -1301,7 +1291,7 @@ describe('EVM Family', () => {
|
|
|
1301
1291
|
}))
|
|
1302
1292
|
return ETHERSCAN_API.getNftOperations({
|
|
1303
1293
|
currencyId: currencyId,
|
|
1304
|
-
config
|
|
1294
|
+
config,
|
|
1305
1295
|
address: address,
|
|
1306
1296
|
fromBlock: 0,
|
|
1307
1297
|
sort,
|
|
@@ -1324,9 +1314,7 @@ describe('EVM Family', () => {
|
|
|
1324
1314
|
})
|
|
1325
1315
|
|
|
1326
1316
|
it('should throw if the currency is misconfigured', async () => {
|
|
1327
|
-
|
|
1328
|
-
createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
1329
|
-
)
|
|
1317
|
+
config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode({ uri: 'mock' }) })
|
|
1330
1318
|
|
|
1331
1319
|
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
1332
1320
|
data: {
|
|
@@ -1337,7 +1325,7 @@ describe('EVM Family', () => {
|
|
|
1337
1325
|
try {
|
|
1338
1326
|
await ETHERSCAN_API.getInternalOperations({
|
|
1339
1327
|
currencyId: currencyId,
|
|
1340
|
-
config
|
|
1328
|
+
config,
|
|
1341
1329
|
address: address,
|
|
1342
1330
|
fromBlock: 0,
|
|
1343
1331
|
sort: 'desc',
|
|
@@ -1360,7 +1348,7 @@ describe('EVM Family', () => {
|
|
|
1360
1348
|
|
|
1361
1349
|
const response = await ETHERSCAN_API.getInternalOperations({
|
|
1362
1350
|
currencyId: currencyId,
|
|
1363
|
-
config
|
|
1351
|
+
config,
|
|
1364
1352
|
address: address,
|
|
1365
1353
|
fromBlock: 0,
|
|
1366
1354
|
sort: 'desc',
|
|
@@ -1399,7 +1387,7 @@ describe('EVM Family', () => {
|
|
|
1399
1387
|
|
|
1400
1388
|
const response = await ETHERSCAN_API.getInternalOperations({
|
|
1401
1389
|
currencyId: currencyId,
|
|
1402
|
-
config
|
|
1390
|
+
config,
|
|
1403
1391
|
address: address,
|
|
1404
1392
|
fromBlock: 50,
|
|
1405
1393
|
sort: 'desc',
|
|
@@ -1438,7 +1426,7 @@ describe('EVM Family', () => {
|
|
|
1438
1426
|
|
|
1439
1427
|
const response = await ETHERSCAN_API.getInternalOperations({
|
|
1440
1428
|
currencyId: currencyId,
|
|
1441
|
-
config
|
|
1429
|
+
config,
|
|
1442
1430
|
address: address,
|
|
1443
1431
|
fromBlock: 50,
|
|
1444
1432
|
toBlock: 100,
|
|
@@ -1484,7 +1472,7 @@ describe('EVM Family', () => {
|
|
|
1484
1472
|
|
|
1485
1473
|
const response = await ETHERSCAN_API.getInternalOperations({
|
|
1486
1474
|
currencyId: currencyId,
|
|
1487
|
-
config
|
|
1475
|
+
config,
|
|
1488
1476
|
address: address,
|
|
1489
1477
|
fromBlock: 0,
|
|
1490
1478
|
sort: 'desc',
|
|
@@ -1508,7 +1496,7 @@ describe('EVM Family', () => {
|
|
|
1508
1496
|
|
|
1509
1497
|
const response = await ETHERSCAN_API.getInternalOperations({
|
|
1510
1498
|
currencyId: currencyId,
|
|
1511
|
-
config
|
|
1499
|
+
config,
|
|
1512
1500
|
address: address,
|
|
1513
1501
|
fromBlock: 0,
|
|
1514
1502
|
sort: 'asc',
|
|
@@ -1613,22 +1601,17 @@ describe('EVM Family', () => {
|
|
|
1613
1601
|
]
|
|
1614
1602
|
|
|
1615
1603
|
it('calls etherscan API with correct URL and params for etherscan explorer type', async () => {
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
})
|
|
1623
|
-
)
|
|
1604
|
+
config = createMockEvmConfigInfo({
|
|
1605
|
+
chainId: 1,
|
|
1606
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1607
|
+
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1608
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
1609
|
+
})
|
|
1624
1610
|
const axiosSpy = jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1625
1611
|
data: { status: '1', message: 'OK', result: internalTxResult },
|
|
1626
1612
|
})
|
|
1627
1613
|
|
|
1628
|
-
const result = await ETHERSCAN_API.getInternalTransactionsByBlock(
|
|
1629
|
-
getCoinConfig(currencyId).info,
|
|
1630
|
-
blockHeight
|
|
1631
|
-
)
|
|
1614
|
+
const result = await ETHERSCAN_API.getInternalTransactionsByBlock(config, blockHeight)
|
|
1632
1615
|
|
|
1633
1616
|
expect(result).toHaveLength(1)
|
|
1634
1617
|
expect(result[0].hash).toBe('0xabc')
|
|
@@ -1648,22 +1631,17 @@ describe('EVM Family', () => {
|
|
|
1648
1631
|
})
|
|
1649
1632
|
|
|
1650
1633
|
it('calls API with correct params for blockscout explorer type', async () => {
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
})
|
|
1658
|
-
)
|
|
1634
|
+
config = createMockEvmConfigInfo({
|
|
1635
|
+
chainId: 1,
|
|
1636
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1637
|
+
explorer: { type: 'blockscout', uri: 'https://blockscout.com/api' },
|
|
1638
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
1639
|
+
})
|
|
1659
1640
|
const axiosSpy = jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1660
1641
|
data: { status: '1', message: 'OK', result: internalTxResult },
|
|
1661
1642
|
})
|
|
1662
1643
|
|
|
1663
|
-
await ETHERSCAN_API.getInternalTransactionsByBlock(
|
|
1664
|
-
getCoinConfig(currencyId).info,
|
|
1665
|
-
blockHeight
|
|
1666
|
-
)
|
|
1644
|
+
await ETHERSCAN_API.getInternalTransactionsByBlock(config, blockHeight)
|
|
1667
1645
|
|
|
1668
1646
|
expect(axiosSpy).toHaveBeenCalledWith(
|
|
1669
1647
|
expect.objectContaining({
|
|
@@ -1683,54 +1661,42 @@ describe('EVM Family', () => {
|
|
|
1683
1661
|
['ledger', { type: 'ledger', explorerId: 'eth' }],
|
|
1684
1662
|
['none', { type: 'none' }],
|
|
1685
1663
|
] as const)('returns empty array for %s explorer type', async (_, explorer) => {
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
})
|
|
1693
|
-
)
|
|
1664
|
+
config = createMockEvmConfigInfo({
|
|
1665
|
+
chainId: 1,
|
|
1666
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1667
|
+
explorer,
|
|
1668
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
1669
|
+
})
|
|
1694
1670
|
|
|
1695
|
-
const result = await ETHERSCAN_API.getInternalTransactionsByBlock(
|
|
1696
|
-
getCoinConfig(currencyId).info,
|
|
1697
|
-
blockHeight
|
|
1698
|
-
)
|
|
1671
|
+
const result = await ETHERSCAN_API.getInternalTransactionsByBlock(config, blockHeight)
|
|
1699
1672
|
|
|
1700
1673
|
expect(result).toEqual([])
|
|
1701
1674
|
expect(axios.request).not.toHaveBeenCalled()
|
|
1702
1675
|
})
|
|
1703
1676
|
|
|
1704
1677
|
it('returns empty array when API returns non-array result', async () => {
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
})
|
|
1712
|
-
)
|
|
1678
|
+
config = createMockEvmConfigInfo({
|
|
1679
|
+
chainId: 1,
|
|
1680
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1681
|
+
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1682
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
1683
|
+
})
|
|
1713
1684
|
jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1714
1685
|
data: { status: '1', message: 'OK', result: 'No transactions found' },
|
|
1715
1686
|
})
|
|
1716
1687
|
|
|
1717
|
-
const result = await ETHERSCAN_API.getInternalTransactionsByBlock(
|
|
1718
|
-
getCoinConfig(currencyId).info,
|
|
1719
|
-
blockHeight
|
|
1720
|
-
)
|
|
1688
|
+
const result = await ETHERSCAN_API.getInternalTransactionsByBlock(config, blockHeight)
|
|
1721
1689
|
|
|
1722
1690
|
expect(result).toEqual([])
|
|
1723
1691
|
})
|
|
1724
1692
|
|
|
1725
1693
|
it('throws when API returns blockscout-style no internal transactions response', async () => {
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
})
|
|
1733
|
-
)
|
|
1694
|
+
config = createMockEvmConfigInfo({
|
|
1695
|
+
chainId: 1,
|
|
1696
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1697
|
+
explorer: { type: 'blockscout', uri: 'https://blockscout.com/api' },
|
|
1698
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
1699
|
+
})
|
|
1734
1700
|
jest.spyOn(axios, 'request').mockResolvedValueOnce({
|
|
1735
1701
|
data: {
|
|
1736
1702
|
status: '0',
|
|
@@ -1740,19 +1706,17 @@ describe('EVM Family', () => {
|
|
|
1740
1706
|
})
|
|
1741
1707
|
|
|
1742
1708
|
await expect(
|
|
1743
|
-
ETHERSCAN_API.getInternalTransactionsByBlock(
|
|
1709
|
+
ETHERSCAN_API.getInternalTransactionsByBlock(config, blockHeight)
|
|
1744
1710
|
).rejects.toThrow(EtherscanAPIError)
|
|
1745
1711
|
})
|
|
1746
1712
|
|
|
1747
1713
|
it('loops over pagination until all internal txs are drained', async () => {
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
})
|
|
1755
|
-
)
|
|
1714
|
+
config = createMockEvmConfigInfo({
|
|
1715
|
+
chainId: 1,
|
|
1716
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1717
|
+
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1718
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
1719
|
+
})
|
|
1756
1720
|
|
|
1757
1721
|
const PAGE_SIZE = 10000
|
|
1758
1722
|
const fullPage = Array.from({ length: PAGE_SIZE }, (_, i) => ({
|
|
@@ -1774,10 +1738,7 @@ describe('EVM Family', () => {
|
|
|
1774
1738
|
data: { status: '1', message: 'OK', result: lastPage },
|
|
1775
1739
|
})
|
|
1776
1740
|
|
|
1777
|
-
const result = await ETHERSCAN_API.getInternalTransactionsByBlock(
|
|
1778
|
-
getCoinConfig(currencyId).info,
|
|
1779
|
-
blockHeight
|
|
1780
|
-
)
|
|
1741
|
+
const result = await ETHERSCAN_API.getInternalTransactionsByBlock(config, blockHeight)
|
|
1781
1742
|
|
|
1782
1743
|
expect(result).toHaveLength(PAGE_SIZE + lastPage.length)
|
|
1783
1744
|
expect(axiosSpy).toHaveBeenCalledTimes(2)
|
|
@@ -1801,38 +1762,34 @@ describe('EVM Family', () => {
|
|
|
1801
1762
|
})
|
|
1802
1763
|
|
|
1803
1764
|
it('propagates errors from explorer API call', async () => {
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
})
|
|
1811
|
-
)
|
|
1765
|
+
config = createMockEvmConfigInfo({
|
|
1766
|
+
chainId: 1,
|
|
1767
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1768
|
+
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io' },
|
|
1769
|
+
supportedTokens: ['erc721', 'erc1155'],
|
|
1770
|
+
})
|
|
1812
1771
|
jest.mocked(axios.request).mockReset()
|
|
1813
1772
|
jest.mocked(axios.request).mockRejectedValue(new Error('network error'))
|
|
1814
1773
|
|
|
1815
1774
|
await expect(
|
|
1816
|
-
ETHERSCAN_API.getInternalTransactionsByBlock(
|
|
1775
|
+
ETHERSCAN_API.getInternalTransactionsByBlock(config, blockHeight)
|
|
1817
1776
|
).rejects.toThrow('network error')
|
|
1818
1777
|
})
|
|
1819
1778
|
})
|
|
1820
1779
|
|
|
1821
1780
|
describe('getNftOperations without nft', () => {
|
|
1822
1781
|
beforeEach(() => {
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
})
|
|
1829
|
-
)
|
|
1782
|
+
config = createMockEvmConfigInfo({
|
|
1783
|
+
chainId: 1,
|
|
1784
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1785
|
+
explorer: { type: 'etherscan', uri: 'mock' },
|
|
1786
|
+
})
|
|
1830
1787
|
})
|
|
1831
1788
|
|
|
1832
1789
|
it('should not return NFT operation', async () => {
|
|
1833
1790
|
const response = await ETHERSCAN_API.getNftOperations({
|
|
1834
1791
|
currencyId: currencyId,
|
|
1835
|
-
config
|
|
1792
|
+
config,
|
|
1836
1793
|
address: address,
|
|
1837
1794
|
fromBlock: 0,
|
|
1838
1795
|
sort: 'desc',
|
|
@@ -1848,14 +1805,12 @@ describe('EVM Family', () => {
|
|
|
1848
1805
|
|
|
1849
1806
|
describe('getNftOperations supportedTokens atomicity', () => {
|
|
1850
1807
|
const withSupportedTokens = (supportedTokens: NftStandard[]) => {
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
})
|
|
1858
|
-
)
|
|
1808
|
+
config = createMockEvmConfigInfo({
|
|
1809
|
+
chainId: 1,
|
|
1810
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1811
|
+
explorer: { type: 'etherscan', uri: 'mock' },
|
|
1812
|
+
supportedTokens,
|
|
1813
|
+
})
|
|
1859
1814
|
}
|
|
1860
1815
|
|
|
1861
1816
|
// ERC721 ops are fetched from the `tokennfttx` endpoint, ERC1155 ops from `token1155tx`.
|
|
@@ -1871,7 +1826,7 @@ describe('EVM Family', () => {
|
|
|
1871
1826
|
requestSpy.mockClear()
|
|
1872
1827
|
const response = await ETHERSCAN_API.getNftOperations({
|
|
1873
1828
|
currencyId,
|
|
1874
|
-
config
|
|
1829
|
+
config,
|
|
1875
1830
|
address: '0x6cBCD73CD8e8a42844662f0A0e76D7F79Afd933d',
|
|
1876
1831
|
fromBlock: 0,
|
|
1877
1832
|
sort: 'desc',
|
|
@@ -1937,13 +1892,11 @@ describe('EVM Family', () => {
|
|
|
1937
1892
|
// getOperations wraps everything its outer catch sees into InvalidExplorerResponse. A rate
|
|
1938
1893
|
// limit must escape that wrapping, otherwise the caller loses the 429 status.
|
|
1939
1894
|
it('propagates a RateLimitError instead of wrapping it in InvalidExplorerResponse', async () => {
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
})
|
|
1946
|
-
)
|
|
1895
|
+
config = createMockEvmConfigInfo({
|
|
1896
|
+
chainId: 1,
|
|
1897
|
+
node: mkExternalNode({ uri: 'mock' }),
|
|
1898
|
+
explorer: { type: 'etherscan', uri: 'https://api.etherscan.io', retries: 0 },
|
|
1899
|
+
})
|
|
1947
1900
|
const rateLimitError = Object.assign(new Error('Request failed with status code 429'), {
|
|
1948
1901
|
isAxiosError: true,
|
|
1949
1902
|
response: { status: 429 },
|
|
@@ -1958,14 +1911,15 @@ describe('EVM Family', () => {
|
|
|
1958
1911
|
|
|
1959
1912
|
await expect(
|
|
1960
1913
|
ETHERSCAN_API.getOperations.force(
|
|
1961
|
-
|
|
1914
|
+
config,
|
|
1962
1915
|
currencyId,
|
|
1963
1916
|
address,
|
|
1964
1917
|
0,
|
|
1965
1918
|
undefined,
|
|
1966
1919
|
undefined,
|
|
1967
1920
|
1,
|
|
1968
|
-
'asc'
|
|
1921
|
+
'asc',
|
|
1922
|
+
testLogger
|
|
1969
1923
|
)
|
|
1970
1924
|
).rejects.toBeInstanceOf(RateLimitError)
|
|
1971
1925
|
})
|
|
@@ -2071,9 +2025,9 @@ describe('EVM Family', () => {
|
|
|
2071
2025
|
const pageCounts: Record<string, number> = {}
|
|
2072
2026
|
const indexedOps = identify(allOps)
|
|
2073
2027
|
|
|
2074
|
-
return async (
|
|
2075
|
-
const url: string =
|
|
2076
|
-
const params =
|
|
2028
|
+
return async (requestConfig: AxiosRequestConfig) => {
|
|
2029
|
+
const url: string = requestConfig.url ?? ''
|
|
2030
|
+
const params = requestConfig.params
|
|
2077
2031
|
const startBlock = params.startblock ?? 0
|
|
2078
2032
|
const endBlock = params.endblock ?? Infinity
|
|
2079
2033
|
const pageLimit = params.offset ?? limit
|
|
@@ -2136,14 +2090,15 @@ describe('EVM Family', () => {
|
|
|
2136
2090
|
: undefined
|
|
2137
2091
|
jest.spyOn(axios, 'request').mockImplementation(createBlockchainMock(allOps, limit, order))
|
|
2138
2092
|
return ETHERSCAN_API.getOperations.force(
|
|
2139
|
-
|
|
2093
|
+
config,
|
|
2140
2094
|
currencyId,
|
|
2141
2095
|
address,
|
|
2142
2096
|
fromBlock,
|
|
2143
2097
|
toBlock,
|
|
2144
2098
|
pagingToken,
|
|
2145
2099
|
limit,
|
|
2146
|
-
order
|
|
2100
|
+
order,
|
|
2101
|
+
testLogger
|
|
2147
2102
|
)
|
|
2148
2103
|
}
|
|
2149
2104
|
|
|
@@ -2970,6 +2925,184 @@ describe('EVM Family', () => {
|
|
|
2970
2925
|
)
|
|
2971
2926
|
}
|
|
2972
2927
|
|
|
2928
|
+
// `isPageFull` / `isDone` are computed from the raw rows the API returned, but the boundary
|
|
2929
|
+
// exhaustion loop works on the ADAPTED operations. `etherscanInternalTransactionToOperations`
|
|
2930
|
+
// drops `delegatecall` / `staticcall` / `callcode` rows, so a full raw page of
|
|
2931
|
+
// `txlistinternal` can adapt to zero operations. The loop must not treat that as
|
|
2932
|
+
// "every operation is at the boundary block" and keep paging.
|
|
2933
|
+
describe('when raw rows are dropped by the adapter', () => {
|
|
2934
|
+
// A full raw page adapting to `operations`. `boundBlock` comes from the adapted operations,
|
|
2935
|
+
// exactly as the real endpoints derive it via `boundBlockFromOperations`.
|
|
2936
|
+
const fullRawPage = (
|
|
2937
|
+
operations: Array<Operation<MemoNotSupported>>
|
|
2938
|
+
): ETHERSCAN_API.EndpointResult => ({
|
|
2939
|
+
operations,
|
|
2940
|
+
isDone: false,
|
|
2941
|
+
boundBlock: operations.length > 0 ? operations[operations.length - 1].tx.block.height! : 0,
|
|
2942
|
+
isPageFull: true,
|
|
2943
|
+
})
|
|
2944
|
+
|
|
2945
|
+
const lastRawPage: ETHERSCAN_API.EndpointResult = {
|
|
2946
|
+
operations: [],
|
|
2947
|
+
isDone: true,
|
|
2948
|
+
boundBlock: 0,
|
|
2949
|
+
isPageFull: false,
|
|
2950
|
+
}
|
|
2951
|
+
|
|
2952
|
+
// An address whose `txlistinternal` rows are all `delegatecall`: `TOTAL_PAGES` full raw
|
|
2953
|
+
// pages that every one of them adapt to nothing, then the end of the result set.
|
|
2954
|
+
const TOTAL_PAGES = 50
|
|
2955
|
+
const allRowsDropped = (firstPageOps: Array<Operation<MemoNotSupported>> = []) =>
|
|
2956
|
+
jest
|
|
2957
|
+
.fn<Promise<ETHERSCAN_API.EndpointResult>, [ETHERSCAN_API.FetchOperationsParams]>()
|
|
2958
|
+
.mockImplementation((params) => {
|
|
2959
|
+
const page = params.page ?? 1
|
|
2960
|
+
if (page > TOTAL_PAGES) return Promise.resolve(lastRawPage)
|
|
2961
|
+
return Promise.resolve(fullRawPage(page === 1 ? firstPageOps : []))
|
|
2962
|
+
})
|
|
2963
|
+
|
|
2964
|
+
it('stops after one request when the first page adapts to no operations', async () => {
|
|
2965
|
+
const mockFetch = allRowsDropped()
|
|
2966
|
+
|
|
2967
|
+
const result = await ETHERSCAN_API.exhaustEndpoint(
|
|
2968
|
+
mockFetch,
|
|
2969
|
+
{
|
|
2970
|
+
currencyId,
|
|
2971
|
+
config,
|
|
2972
|
+
address,
|
|
2973
|
+
fromBlock: 0,
|
|
2974
|
+
limit: LIMIT,
|
|
2975
|
+
sort: 'desc',
|
|
2976
|
+
},
|
|
2977
|
+
testLogger
|
|
2978
|
+
)
|
|
2979
|
+
|
|
2980
|
+
// There is no boundary block to exhaust: `boundBlock` is 0, so every extra page is
|
|
2981
|
+
// filtered against block 0 and can only ever contribute nothing.
|
|
2982
|
+
expect(mockFetch).toHaveBeenCalledTimes(1)
|
|
2983
|
+
expect(result.operations).toEqual([])
|
|
2984
|
+
})
|
|
2985
|
+
|
|
2986
|
+
// The early return above changes how many requests are made, not what comes back. These
|
|
2987
|
+
// two cases pin that: `main` returns the same operations, having paid for extra pages to
|
|
2988
|
+
// reach the same answer. Operations dropped here were already dropped before the change —
|
|
2989
|
+
// the loop only ever collected ops matching `firstPage.boundBlock`, which is 0.
|
|
2990
|
+
it('returns what the unbounded loop returned when a real op follows the dropped rows', async () => {
|
|
2991
|
+
const mockFetch = jest
|
|
2992
|
+
.fn<Promise<ETHERSCAN_API.EndpointResult>, [ETHERSCAN_API.FetchOperationsParams]>()
|
|
2993
|
+
.mockImplementation((params) =>
|
|
2994
|
+
Promise.resolve(
|
|
2995
|
+
(params.page ?? 1) === 1
|
|
2996
|
+
? fullRawPage([])
|
|
2997
|
+
: { operations: createOps([500]), isDone: true, boundBlock: 500, isPageFull: false }
|
|
2998
|
+
)
|
|
2999
|
+
)
|
|
3000
|
+
|
|
3001
|
+
const result = await ETHERSCAN_API.exhaustEndpoint(
|
|
3002
|
+
mockFetch,
|
|
3003
|
+
{
|
|
3004
|
+
currencyId,
|
|
3005
|
+
config,
|
|
3006
|
+
address,
|
|
3007
|
+
fromBlock: 0,
|
|
3008
|
+
limit: LIMIT,
|
|
3009
|
+
sort: 'desc',
|
|
3010
|
+
},
|
|
3011
|
+
testLogger
|
|
3012
|
+
)
|
|
3013
|
+
|
|
3014
|
+
// Identical to the pre-change result, which reached it in 2 requests instead of 1:
|
|
3015
|
+
// the op at block 500 is not at `firstPage.boundBlock` (0), so the loop never kept it.
|
|
3016
|
+
expect(result.operations).toEqual([])
|
|
3017
|
+
expect(result.isDone).toBe(false)
|
|
3018
|
+
expect(mockFetch).toHaveBeenCalledTimes(1)
|
|
3019
|
+
})
|
|
3020
|
+
|
|
3021
|
+
it('leaves the endpoint not-done so the caller re-queries it', async () => {
|
|
3022
|
+
const mockFetch = allRowsDropped()
|
|
3023
|
+
|
|
3024
|
+
const result = await ETHERSCAN_API.exhaustEndpoint(
|
|
3025
|
+
mockFetch,
|
|
3026
|
+
{
|
|
3027
|
+
currencyId,
|
|
3028
|
+
config,
|
|
3029
|
+
address,
|
|
3030
|
+
fromBlock: 0,
|
|
3031
|
+
limit: LIMIT,
|
|
3032
|
+
sort: 'desc',
|
|
3033
|
+
},
|
|
3034
|
+
testLogger
|
|
3035
|
+
)
|
|
3036
|
+
|
|
3037
|
+
// Before the change this walked to the end of the result set and reported isDone=true,
|
|
3038
|
+
// which let `getOperations` mark the endpoint permanently done. Not-done is the safer
|
|
3039
|
+
// answer: `internalIsDone` stays false and the next page re-queries the endpoint.
|
|
3040
|
+
expect(result.isDone).toBe(false)
|
|
3041
|
+
})
|
|
3042
|
+
|
|
3043
|
+
it('bounds the number of requests when later pages adapt to no operations', async () => {
|
|
3044
|
+
const mockFetch = allRowsDropped(createOps([7]))
|
|
3045
|
+
|
|
3046
|
+
await ETHERSCAN_API.exhaustEndpoint(
|
|
3047
|
+
mockFetch,
|
|
3048
|
+
{
|
|
3049
|
+
currencyId,
|
|
3050
|
+
config,
|
|
3051
|
+
address,
|
|
3052
|
+
fromBlock: 0,
|
|
3053
|
+
limit: LIMIT,
|
|
3054
|
+
sort: 'desc',
|
|
3055
|
+
},
|
|
3056
|
+
testLogger
|
|
3057
|
+
)
|
|
3058
|
+
|
|
3059
|
+
expect(mockFetch.mock.calls.length).toBeLessThanOrEqual(
|
|
3060
|
+
ETHERSCAN_API.DEFAULT_MAX_BOUNDARY_EXHAUSTION_PAGES + 1
|
|
3061
|
+
)
|
|
3062
|
+
})
|
|
3063
|
+
|
|
3064
|
+
it('takes the page budget from the explorer config when set', async () => {
|
|
3065
|
+
const mockFetch = allRowsDropped(createOps([7]))
|
|
3066
|
+
|
|
3067
|
+
await ETHERSCAN_API.exhaustEndpoint(
|
|
3068
|
+
mockFetch,
|
|
3069
|
+
{
|
|
3070
|
+
currencyId,
|
|
3071
|
+
config: createMockEvmConfigInfo({
|
|
3072
|
+
chainId: 1,
|
|
3073
|
+
node: mkExternalNode(),
|
|
3074
|
+
explorer: { type: 'etherscan', uri: 'mock', maxBoundaryExhaustionPages: 2 },
|
|
3075
|
+
}),
|
|
3076
|
+
address,
|
|
3077
|
+
fromBlock: 0,
|
|
3078
|
+
limit: LIMIT,
|
|
3079
|
+
sort: 'desc',
|
|
3080
|
+
},
|
|
3081
|
+
testLogger
|
|
3082
|
+
)
|
|
3083
|
+
|
|
3084
|
+
// first page + 2 extra pages
|
|
3085
|
+
expect(mockFetch).toHaveBeenCalledTimes(3)
|
|
3086
|
+
})
|
|
3087
|
+
|
|
3088
|
+
it('reports hitting the page budget through the injected logger', async () => {
|
|
3089
|
+
const mockFetch = allRowsDropped(createOps([7]))
|
|
3090
|
+
const logger = jest.fn()
|
|
3091
|
+
|
|
3092
|
+
await ETHERSCAN_API.exhaustEndpoint(
|
|
3093
|
+
mockFetch,
|
|
3094
|
+
{ currencyId, config, address, fromBlock: 0, limit: LIMIT, sort: 'desc' },
|
|
3095
|
+
logger
|
|
3096
|
+
)
|
|
3097
|
+
|
|
3098
|
+
expect(logger).toHaveBeenCalledWith(
|
|
3099
|
+
'warn',
|
|
3100
|
+
expect.stringContaining('page budget'),
|
|
3101
|
+
expect.objectContaining({ boundBlock: 7, limit: LIMIT })
|
|
3102
|
+
)
|
|
3103
|
+
})
|
|
3104
|
+
})
|
|
3105
|
+
|
|
2973
3106
|
it('always uses limit + 1 as probe', async () => {
|
|
2974
3107
|
const mockFetch = jest
|
|
2975
3108
|
.fn<Promise<ETHERSCAN_API.EndpointResult>, [ETHERSCAN_API.FetchOperationsParams]>()
|
|
@@ -2980,14 +3113,18 @@ describe('EVM Family', () => {
|
|
|
2980
3113
|
isPageFull: false,
|
|
2981
3114
|
})
|
|
2982
3115
|
|
|
2983
|
-
await ETHERSCAN_API.exhaustEndpoint(
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
3116
|
+
await ETHERSCAN_API.exhaustEndpoint(
|
|
3117
|
+
mockFetch,
|
|
3118
|
+
{
|
|
3119
|
+
currencyId: currencyId,
|
|
3120
|
+
config,
|
|
3121
|
+
address: address,
|
|
3122
|
+
fromBlock: 0,
|
|
3123
|
+
limit: 100,
|
|
3124
|
+
sort: 'desc',
|
|
3125
|
+
},
|
|
3126
|
+
testLogger
|
|
3127
|
+
)
|
|
2991
3128
|
|
|
2992
3129
|
expect(mockFetch).toHaveBeenCalledTimes(1)
|
|
2993
3130
|
expect(mockFetch.mock.calls[0]?.[0]).toEqual(
|
|
@@ -3055,14 +3192,18 @@ describe('EVM Family', () => {
|
|
|
3055
3192
|
])('ops $ops', async ({ ops, expected }) => {
|
|
3056
3193
|
const mockFetch = createPaginatedMock(ops)
|
|
3057
3194
|
|
|
3058
|
-
const result = await ETHERSCAN_API.exhaustEndpoint(
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3195
|
+
const result = await ETHERSCAN_API.exhaustEndpoint(
|
|
3196
|
+
mockFetch,
|
|
3197
|
+
{
|
|
3198
|
+
currencyId: currencyId,
|
|
3199
|
+
config,
|
|
3200
|
+
address: address,
|
|
3201
|
+
fromBlock: 0,
|
|
3202
|
+
limit: LIMIT,
|
|
3203
|
+
sort: 'desc',
|
|
3204
|
+
},
|
|
3205
|
+
testLogger
|
|
3206
|
+
)
|
|
3066
3207
|
|
|
3067
3208
|
expect({
|
|
3068
3209
|
isPageFull: result.isPageFull,
|
|
@@ -3072,4 +3213,71 @@ describe('EVM Family', () => {
|
|
|
3072
3213
|
}).toEqual(expected)
|
|
3073
3214
|
})
|
|
3074
3215
|
})
|
|
3216
|
+
|
|
3217
|
+
describe('discoverTokenAssets', () => {
|
|
3218
|
+
afterEach(() => {
|
|
3219
|
+
jest.clearAllMocks()
|
|
3220
|
+
})
|
|
3221
|
+
|
|
3222
|
+
it('returns the same asset references as the existing getOperations -> lastTokenOperations path, deduplicated', async () => {
|
|
3223
|
+
jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
3224
|
+
data: { result: etherscanTokenOperations },
|
|
3225
|
+
}))
|
|
3226
|
+
|
|
3227
|
+
const assets = await ETHERSCAN_API.discoverTokenAssets.force(config, currencyId, address, 0)
|
|
3228
|
+
|
|
3229
|
+
const expectedOperations = [
|
|
3230
|
+
etherscanERC20EventToOperations(address, etherscanTokenOperations[0], 0),
|
|
3231
|
+
etherscanERC20EventToOperations(address, etherscanTokenOperations[1], 0),
|
|
3232
|
+
etherscanERC20EventToOperations(address, etherscanTokenOperations[2], 1),
|
|
3233
|
+
].flat()
|
|
3234
|
+
const expectedReferences = new Set(
|
|
3235
|
+
expectedOperations
|
|
3236
|
+
.filter(
|
|
3237
|
+
(op): op is typeof op & { asset: { assetReference: string } } =>
|
|
3238
|
+
'assetReference' in op.asset
|
|
3239
|
+
)
|
|
3240
|
+
.map((op) => op.asset.assetReference)
|
|
3241
|
+
)
|
|
3242
|
+
|
|
3243
|
+
const discoveredReferences = new Set(
|
|
3244
|
+
assets
|
|
3245
|
+
.filter(
|
|
3246
|
+
(asset): asset is typeof asset & { assetReference: string } => 'assetReference' in asset
|
|
3247
|
+
)
|
|
3248
|
+
.map((asset) => asset.assetReference)
|
|
3249
|
+
)
|
|
3250
|
+
|
|
3251
|
+
expect(discoveredReferences).toEqual(expectedReferences)
|
|
3252
|
+
expect(assets).toHaveLength(expectedReferences.size)
|
|
3253
|
+
})
|
|
3254
|
+
|
|
3255
|
+
it('only requests the token endpoint, never the coin, internal or NFT endpoints', async () => {
|
|
3256
|
+
const requestSpy = jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
3257
|
+
data: { result: etherscanTokenOperations },
|
|
3258
|
+
}))
|
|
3259
|
+
|
|
3260
|
+
await ETHERSCAN_API.discoverTokenAssets.force(config, currencyId, address, 0)
|
|
3261
|
+
|
|
3262
|
+
expect(requestSpy).toHaveBeenCalledTimes(1)
|
|
3263
|
+
expect(requestSpy).toHaveBeenCalledWith(
|
|
3264
|
+
expect.objectContaining({ url: expect.stringContaining('action=tokentx') })
|
|
3265
|
+
)
|
|
3266
|
+
})
|
|
3267
|
+
|
|
3268
|
+
it('serves a second identical call from cache; .force bypasses it', async () => {
|
|
3269
|
+
const requestSpy = jest.spyOn(axios, 'request').mockImplementation(async () => ({
|
|
3270
|
+
data: { result: etherscanTokenOperations },
|
|
3271
|
+
}))
|
|
3272
|
+
|
|
3273
|
+
await ETHERSCAN_API.discoverTokenAssets(config, currencyId, address, 999)
|
|
3274
|
+
await ETHERSCAN_API.discoverTokenAssets(config, currencyId, address, 999)
|
|
3275
|
+
|
|
3276
|
+
expect(requestSpy).toHaveBeenCalledTimes(1)
|
|
3277
|
+
|
|
3278
|
+
await ETHERSCAN_API.discoverTokenAssets.force(config, currencyId, address, 999)
|
|
3279
|
+
|
|
3280
|
+
expect(requestSpy).toHaveBeenCalledTimes(2)
|
|
3281
|
+
})
|
|
3282
|
+
})
|
|
3075
3283
|
})
|