@ledgerhq/coin-evm 5.4.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +197 -0
- package/docs/evm-family-integration-process/README.md +1 -1
- package/knip.json +2 -3
- package/lib/adapters/blockOperations.js +6 -6
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/adapters/etherscan.js +23 -23
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.js +17 -17
- package/lib/adapters/ledger.js.map +1 -1
- package/lib/api/index.js +4 -4
- package/lib/api/index.js.map +1 -1
- package/lib/config.d.ts +21 -15
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +5 -25
- package/lib/config.js.map +1 -1
- package/lib/errors.d.ts +9 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +15 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/broadcast.js +1 -1
- package/lib/logic/broadcast.js.map +1 -1
- package/lib/logic/common.d.ts +2 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js +4 -4
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +2 -2
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +9 -9
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js +50 -16
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +19 -11
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getBlockInfo.js +1 -1
- package/lib/logic/getBlockInfo.js.map +1 -1
- package/lib/logic/getNextSequence.d.ts.map +1 -1
- package/lib/logic/getNextSequence.js +1 -1
- package/lib/logic/getNextSequence.js.map +1 -1
- package/lib/logic/index.d.ts +2 -0
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +4 -0
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/lastBlock.js +1 -1
- package/lib/logic/lastBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +10 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js +12 -12
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic-public/index.d.ts +3 -0
- package/lib/logic-public/index.d.ts.map +1 -0
- package/lib/logic-public/index.js +19 -0
- package/lib/logic-public/index.js.map +1 -0
- package/lib/{utils.d.ts → logic-public/utils.d.ts} +0 -44
- package/lib/logic-public/utils.d.ts.map +1 -0
- package/lib/logic-public/utils.js +166 -0
- package/lib/logic-public/utils.js.map +1 -0
- package/lib/logic.d.ts +2 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/logic.js +3 -3
- package/lib/logic.js.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +16 -3
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js +61 -6
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts +50 -4
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js +286 -37
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/none.d.ts +1 -0
- package/lib/network/explorer/none.d.ts.map +1 -1
- package/lib/network/explorer/none.js +4 -1
- package/lib/network/explorer/none.js.map +1 -1
- package/lib/network/explorer/types.d.ts +15 -2
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/index.d.ts +5 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +23 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/node/explorerProxy.d.ts +27 -0
- package/lib/network/node/explorerProxy.d.ts.map +1 -0
- package/lib/network/node/explorerProxy.js +262 -0
- package/lib/network/node/explorerProxy.js.map +1 -0
- package/lib/network/node/index.d.ts +2 -1
- package/lib/network/node/index.d.ts.map +1 -1
- package/lib/network/node/index.js +11 -10
- package/lib/network/node/index.js.map +1 -1
- package/lib/network/node/ledger.js +7 -7
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +2 -2
- package/lib/network/node/rpc.common.js +19 -19
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/withNodeSources.d.ts +21 -0
- package/lib/network/node/withNodeSources.d.ts.map +1 -0
- package/lib/network/node/withNodeSources.js +78 -0
- package/lib/network/node/withNodeSources.js.map +1 -0
- package/lib/nodeSources.d.ts +15 -0
- package/lib/nodeSources.d.ts.map +1 -0
- package/lib/nodeSources.js +33 -0
- package/lib/nodeSources.js.map +1 -0
- package/lib/staking/contracts.js +1 -1
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/fetchers.js +1 -1
- package/lib/staking/fetchers.js.map +1 -1
- package/lib/staking/operations/sei.js +1 -1
- package/lib/staking/operations/sei.js.map +1 -1
- package/lib/staking/prepareIntents.js +3 -3
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/rewards.js +1 -1
- package/lib/staking/rewards.js.map +1 -1
- package/lib/staking/transactionData.js +2 -2
- package/lib/staking/transactionData.js.map +1 -1
- package/lib/staking/utils.d.ts +45 -0
- package/lib/staking/utils.d.ts.map +1 -0
- package/lib/{utils.js → staking/utils.js} +5 -164
- package/lib/staking/utils.js.map +1 -0
- package/lib/staking/validators/sei.js +1 -1
- package/lib/staking/validators/sei.js.map +1 -1
- package/lib/types/staking.d.ts +2 -2
- package/lib-es/adapters/blockOperations.js +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/adapters/etherscan.js +1 -1
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/adapters/ledger.js +1 -1
- package/lib-es/adapters/ledger.js.map +1 -1
- package/lib-es/api/index.js +2 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/config.d.ts +21 -15
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +1 -21
- package/lib-es/config.js.map +1 -1
- package/lib-es/errors.d.ts +9 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +13 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/broadcast.js +1 -1
- package/lib-es/logic/broadcast.js.map +1 -1
- package/lib-es/logic/common.d.ts +2 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +3 -3
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +2 -2
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +6 -6
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js +50 -16
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +16 -8
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getBlockInfo.js +1 -1
- package/lib-es/logic/getBlockInfo.js.map +1 -1
- package/lib-es/logic/getNextSequence.d.ts.map +1 -1
- package/lib-es/logic/getNextSequence.js +1 -1
- package/lib-es/logic/getNextSequence.js.map +1 -1
- package/lib-es/logic/index.d.ts +2 -0
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +4 -0
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/lastBlock.js +1 -1
- package/lib-es/logic/lastBlock.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +10 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js +4 -4
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic-public/index.d.ts +3 -0
- package/lib-es/logic-public/index.d.ts.map +1 -0
- package/lib-es/logic-public/index.js +4 -0
- package/lib-es/logic-public/index.js.map +1 -0
- package/lib-es/{utils.d.ts → logic-public/utils.d.ts} +0 -44
- package/lib-es/logic-public/utils.d.ts.map +1 -0
- package/lib-es/logic-public/utils.js +150 -0
- package/lib-es/logic-public/utils.js.map +1 -0
- package/lib-es/logic.d.ts +2 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/logic.js +3 -3
- package/lib-es/logic.js.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +16 -3
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js +60 -5
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts +50 -4
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js +283 -37
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/none.d.ts +1 -0
- package/lib-es/network/explorer/none.d.ts.map +1 -1
- package/lib-es/network/explorer/none.js +2 -0
- package/lib-es/network/explorer/none.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +15 -2
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/explorer/types.js.map +1 -1
- package/lib-es/network/index.d.ts +5 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +7 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/node/explorerProxy.d.ts +27 -0
- package/lib-es/network/node/explorerProxy.d.ts.map +1 -0
- package/lib-es/network/node/explorerProxy.js +254 -0
- package/lib-es/network/node/explorerProxy.js.map +1 -0
- package/lib-es/network/node/index.d.ts +2 -1
- package/lib-es/network/node/index.d.ts.map +1 -1
- package/lib-es/network/node/index.js +11 -10
- package/lib-es/network/node/index.js.map +1 -1
- package/lib-es/network/node/ledger.js +1 -1
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +2 -2
- package/lib-es/network/node/rpc.common.js +3 -3
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/withNodeSources.d.ts +21 -0
- package/lib-es/network/node/withNodeSources.d.ts.map +1 -0
- package/lib-es/network/node/withNodeSources.js +74 -0
- package/lib-es/network/node/withNodeSources.js.map +1 -0
- package/lib-es/nodeSources.d.ts +15 -0
- package/lib-es/nodeSources.d.ts.map +1 -0
- package/lib-es/nodeSources.js +28 -0
- package/lib-es/nodeSources.js.map +1 -0
- package/lib-es/staking/contracts.js +1 -1
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/fetchers.js +1 -1
- package/lib-es/staking/fetchers.js.map +1 -1
- package/lib-es/staking/operations/sei.js +1 -1
- package/lib-es/staking/operations/sei.js.map +1 -1
- package/lib-es/staking/prepareIntents.js +1 -1
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/rewards.js +1 -1
- package/lib-es/staking/rewards.js.map +1 -1
- package/lib-es/staking/transactionData.js +1 -1
- package/lib-es/staking/transactionData.js.map +1 -1
- package/lib-es/staking/utils.d.ts +45 -0
- package/lib-es/staking/utils.d.ts.map +1 -0
- package/lib-es/{utils.js → staking/utils.js} +1 -147
- package/lib-es/staking/utils.js.map +1 -0
- package/lib-es/staking/validators/sei.js +1 -1
- package/lib-es/staking/validators/sei.js.map +1 -1
- package/lib-es/types/staking.d.ts +2 -2
- package/package.json +72 -7
- package/src/adapters/blockOperations.ts +1 -1
- package/src/adapters/etherscan.ts +1 -1
- package/src/adapters/ledger.ts +1 -1
- package/src/api/{index.arc_testnet.integ.test.ts → index.arc.integ.test.ts} +15 -12
- package/src/api/index.monad_testnet.integ.test.ts +95 -4
- package/src/api/index.ts +2 -2
- package/src/config.ts +22 -34
- package/src/errors.ts +13 -0
- package/src/fixtures/context.fixtures.ts +6 -1
- package/src/logic/broadcast.ts +1 -1
- package/src/logic/common.ts +4 -2
- package/src/logic/craftTransaction.ts +2 -1
- package/src/logic/estimateFees.ts +20 -6
- package/src/logic/getBalance.ts +72 -26
- package/src/logic/getBlock.ts +26 -14
- package/src/logic/getBlockInfo.ts +1 -1
- package/src/logic/getNextSequence.ts +4 -1
- package/src/logic/index.ts +4 -0
- package/src/logic/lastBlock.ts +1 -1
- package/src/logic/listOperations.ts +14 -1
- package/src/logic/tests/broadcast.integ.test.ts +53 -0
- package/src/logic/{broadcast.test.ts → tests/broadcast.test.ts} +7 -7
- package/src/logic/{broadcastSource.test.ts → tests/broadcastSource.test.ts} +6 -6
- package/src/logic/{combine.test.ts → tests/combine.test.ts} +1 -1
- package/src/logic/{common.test.ts → tests/common.test.ts} +45 -21
- package/src/logic/{computeGasLimit.test.ts → tests/computeGasLimit.test.ts} +2 -2
- package/src/logic/{craftTransaction.test.ts → tests/craftTransaction.test.ts} +7 -7
- package/src/logic/{craftTransactionData.test.ts → tests/craftTransactionData.test.ts} +4 -4
- package/src/logic/{estimateFees.test.ts → tests/estimateFees.test.ts} +12 -12
- package/src/logic/tests/getBalance.test.ts +602 -0
- package/src/logic/{getBlock.test.ts → tests/getBlock.test.ts} +182 -89
- package/src/logic/{getBlockInfo.test.ts → tests/getBlockInfo.test.ts} +8 -8
- package/src/logic/{getErc20Data.test.ts → tests/getErc20Data.test.ts} +1 -1
- package/src/logic/{getNextSequence.test.ts → tests/getNextSequence.test.ts} +7 -7
- package/src/logic/{getStakes.test.ts → tests/getStakes.test.ts} +13 -13
- package/src/logic/{internalTransactionsFetcher.test.ts → tests/internalTransactionsFetcher.test.ts} +8 -8
- package/src/logic/{lastBlock.test.ts → tests/lastBlock.test.ts} +7 -7
- package/src/logic/{listOperations.test.ts → tests/listOperations.test.ts} +125 -6
- package/src/logic/{validateAddress.test.ts → tests/validateAddress.test.ts} +1 -1
- package/src/logic/{validateIntent.test.ts → tests/validateIntent.test.ts} +80 -78
- package/src/logic/validateIntent.ts +7 -4
- package/src/logic-public/index.ts +18 -0
- package/src/{utils.test.ts → logic-public/tests/utils.test.ts} +1 -27
- package/src/logic-public/utils.ts +184 -0
- package/src/logic.test.ts +5 -59
- package/src/logic.ts +5 -3
- package/src/network/explorer/etherscan.test.ts +403 -195
- package/src/network/explorer/etherscan.ts +99 -10
- package/src/network/explorer/index.test.ts +27 -0
- package/src/network/explorer/ledger.test.ts +791 -62
- package/src/network/explorer/ledger.ts +426 -54
- package/src/network/explorer/none.ts +3 -0
- package/src/network/explorer/types.ts +29 -5
- package/src/network/index.ts +7 -0
- package/src/network/node/explorerProxy.test.ts +673 -0
- package/src/network/node/explorerProxy.ts +308 -0
- package/src/network/node/index.memoization.test.ts +22 -10
- package/src/network/node/index.test.ts +6 -3
- package/src/network/node/index.ts +11 -7
- package/src/network/node/ledger.ts +1 -1
- package/src/network/node/rpc.common.ts +3 -3
- package/src/network/node/rpc.test.ts +66 -105
- package/src/network/node/withNodeSources.test.ts +240 -0
- package/src/network/node/withNodeSources.ts +95 -0
- package/src/nodeSources.ts +38 -0
- package/src/staking/contracts.ts +1 -1
- package/src/staking/encoder.test.ts +1 -1
- package/src/staking/fetchers.ts +1 -1
- package/src/staking/operations/sei.ts +1 -1
- package/src/staking/prepareIntents.ts +1 -1
- package/src/staking/redelegations.test.ts +1 -1
- package/src/staking/rewards.test.ts +1 -1
- package/src/staking/rewards.ts +1 -1
- package/src/staking/transactionData.ts +1 -1
- package/src/staking/unbondings.test.ts +1 -1
- package/src/staking/utils.test.ts +25 -0
- package/src/{utils.ts → staking/utils.ts} +2 -182
- package/src/staking/validators/sei.ts +1 -1
- package/src/types/staking.ts +2 -2
- package/lib/constants.d.ts +0 -2
- package/lib/constants.d.ts.map +0 -1
- package/lib/constants.js +0 -11
- package/lib/constants.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
- package/lib-es/constants.d.ts +0 -2
- package/lib-es/constants.d.ts.map +0 -1
- package/lib-es/constants.js +0 -7
- package/lib-es/constants.js.map +0 -1
- package/lib-es/utils.d.ts.map +0 -1
- package/lib-es/utils.js.map +0 -1
- package/src/constants.ts +0 -9
- package/src/logic/broadcast.integ.test.ts +0 -46
- package/src/logic/getBalance.test.ts +0 -362
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { Wallet } from 'ethers'
|
|
5
|
-
import { createContext, setCoinConfig } from '../config'
|
|
6
|
-
import { createMockEvmCoinConfig, mkExternalNode, mkLedgerNode } from '../fixtures/context.fixtures'
|
|
7
|
-
import broadcast from './broadcast'
|
|
8
|
-
|
|
9
|
-
describe('Broadcast', () => {
|
|
10
|
-
beforeAll(() => {
|
|
11
|
-
setCoinConfig((currency) => {
|
|
12
|
-
switch (currency) {
|
|
13
|
-
case 'ethereum':
|
|
14
|
-
return createMockEvmCoinConfig({ chainId: 1, node: mkLedgerNode({ explorerId: 'eth' }) })
|
|
15
|
-
case 'sonic':
|
|
16
|
-
return createMockEvmCoinConfig({
|
|
17
|
-
chainId: 146,
|
|
18
|
-
node: mkExternalNode({ uri: 'https://sonic.coin.ledger.com' }),
|
|
19
|
-
})
|
|
20
|
-
default:
|
|
21
|
-
throw new Error('Unhandled currency')
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it.each([
|
|
27
|
-
['ethereum', 1],
|
|
28
|
-
['sonic', 146],
|
|
29
|
-
])('throws on insufficient funds on %s', async (network, chainId) => {
|
|
30
|
-
const wallet = Wallet.createRandom()
|
|
31
|
-
const tx = {
|
|
32
|
-
to: wallet.address,
|
|
33
|
-
value: 1n,
|
|
34
|
-
nonce: 0,
|
|
35
|
-
gasLimit: 21000n,
|
|
36
|
-
maxFeePerGas: 10000000000000n,
|
|
37
|
-
maxPriorityFeePerGas: 1000000000n,
|
|
38
|
-
chainId,
|
|
39
|
-
}
|
|
40
|
-
const signature = await wallet.signTransaction(tx)
|
|
41
|
-
|
|
42
|
-
await expect(broadcast(createContext(), network, { signature })).rejects.toThrow(
|
|
43
|
-
/insufficient funds for gas \* price \+ value|InsufficientFunds/
|
|
44
|
-
)
|
|
45
|
-
})
|
|
46
|
-
})
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { EvmContext } from '../config'
|
|
5
|
-
import type { AssetInfo } from '@ledgerhq/coin-module-framework/api/types'
|
|
6
|
-
import BigNumber from 'bignumber.js'
|
|
7
|
-
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
8
|
-
import { getExplorerApi } from '../network/explorer'
|
|
9
|
-
import { getNodeApi } from '../network/node'
|
|
10
|
-
import { mockNodeApi } from '../network/node/node.fixtures'
|
|
11
|
-
import { getStakes } from './getStakes'
|
|
12
|
-
import { getBalance } from '.'
|
|
13
|
-
|
|
14
|
-
jest.mock('../network/node', () => ({
|
|
15
|
-
...jest.requireActual('../network/node'),
|
|
16
|
-
getNodeApi: jest.fn(),
|
|
17
|
-
}))
|
|
18
|
-
|
|
19
|
-
jest.mock('../network/explorer', () => ({
|
|
20
|
-
getExplorerApi: jest.fn(),
|
|
21
|
-
}))
|
|
22
|
-
|
|
23
|
-
jest.mock('./getStakes', () => ({
|
|
24
|
-
getStakes: jest.fn(),
|
|
25
|
-
}))
|
|
26
|
-
|
|
27
|
-
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
28
|
-
const mockGetExplorerApi = jest.mocked(getExplorerApi)
|
|
29
|
-
const mockGetStakes = jest.mocked(getStakes)
|
|
30
|
-
|
|
31
|
-
describe('getBalance', () => {
|
|
32
|
-
const nodeApiMock = mockNodeApi()
|
|
33
|
-
let context: EvmContext
|
|
34
|
-
const setNativeContracts = (nativeContracts?: string[]) => {
|
|
35
|
-
context = createMockEvmContext(Array.isArray(nativeContracts) ? { nativeContracts } : {})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
jest.clearAllMocks()
|
|
40
|
-
mockGetNodeApi.mockReturnValue(nodeApiMock)
|
|
41
|
-
setNativeContracts()
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it.each([
|
|
45
|
-
[
|
|
46
|
-
'native balance only', // test description
|
|
47
|
-
{ lastTokenOperations: [], nextPagingToken: '' }, // operation
|
|
48
|
-
{}, // token balances (empty)
|
|
49
|
-
[
|
|
50
|
-
{
|
|
51
|
-
value: BigInt('10000000000000000000000'),
|
|
52
|
-
asset: { type: 'native' },
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
value: BigInt('10000000000000000000000'),
|
|
56
|
-
asset: { type: 'native' },
|
|
57
|
-
stake: {
|
|
58
|
-
uid: 'address',
|
|
59
|
-
address: 'address',
|
|
60
|
-
state: 'active',
|
|
61
|
-
asset: { type: 'native' },
|
|
62
|
-
amount: BigInt('10000000000000000000000'),
|
|
63
|
-
actions: [],
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
], // expected
|
|
67
|
-
],
|
|
68
|
-
[
|
|
69
|
-
'native and token balances', // test description
|
|
70
|
-
{
|
|
71
|
-
lastTokenOperations: [
|
|
72
|
-
{ asset: { type: 'erc20', assetReference: '0x123' } },
|
|
73
|
-
{ asset: { type: 'erc20', assetReference: '0x123' } },
|
|
74
|
-
{ asset: { type: 'erc20', assetReference: '0x456' } },
|
|
75
|
-
],
|
|
76
|
-
nextPagingToken: '',
|
|
77
|
-
}, // operations
|
|
78
|
-
{ '0x123': '1000000', '0x456': '2000000' }, // token balances
|
|
79
|
-
[
|
|
80
|
-
{
|
|
81
|
-
value: BigInt('10000000000000000000000'),
|
|
82
|
-
asset: { type: 'native' },
|
|
83
|
-
}, // native balance
|
|
84
|
-
{
|
|
85
|
-
value: BigInt('10000000000000000000000'),
|
|
86
|
-
asset: { type: 'native' },
|
|
87
|
-
stake: {
|
|
88
|
-
uid: 'address',
|
|
89
|
-
address: 'address',
|
|
90
|
-
state: 'active',
|
|
91
|
-
asset: { type: 'native' },
|
|
92
|
-
amount: BigInt('10000000000000000000000'),
|
|
93
|
-
actions: [],
|
|
94
|
-
},
|
|
95
|
-
}, // stake
|
|
96
|
-
{
|
|
97
|
-
value: BigInt('1000000'),
|
|
98
|
-
asset: { type: 'erc20', assetReference: '0x123', assetOwner: 'address' },
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
value: BigInt('2000000'),
|
|
102
|
-
asset: { type: 'erc20', assetReference: '0x456', assetOwner: 'address' },
|
|
103
|
-
},
|
|
104
|
-
], // expected
|
|
105
|
-
],
|
|
106
|
-
])('returns %s', async (_, operations, tokenBalances: Record<string, string>, expected) => {
|
|
107
|
-
nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('10000000000000000000000'))
|
|
108
|
-
nodeApiMock.getTokenBalance.mockImplementation(
|
|
109
|
-
(_currency: unknown, _address: string, contractAddress: string) =>
|
|
110
|
-
Promise.resolve(new BigNumber(tokenBalances[contractAddress] || '0'))
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
mockGetExplorerApi.mockReturnValue({
|
|
114
|
-
getOperations: jest.fn().mockResolvedValue(operations),
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
// Mock getStakes to return the expected stake data
|
|
118
|
-
mockGetStakes.mockResolvedValue({
|
|
119
|
-
items: [
|
|
120
|
-
{
|
|
121
|
-
uid: 'address',
|
|
122
|
-
address: 'address',
|
|
123
|
-
state: 'active',
|
|
124
|
-
asset: { type: 'native' },
|
|
125
|
-
amount: BigInt('10000000000000000000000'),
|
|
126
|
-
actions: [],
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
expect(await getBalance(context, '', 'address')).toEqual(expected)
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it.each([
|
|
135
|
-
{
|
|
136
|
-
title: 'only one token',
|
|
137
|
-
operations: {
|
|
138
|
-
lastTokenOperations: [
|
|
139
|
-
{ asset: { type: 'erc20', assetReference: '0x123' } },
|
|
140
|
-
{ asset: { type: 'erc20', assetReference: '0x456' } },
|
|
141
|
-
],
|
|
142
|
-
nextPagingToken: '',
|
|
143
|
-
},
|
|
144
|
-
includeAssets: (assetInfo: AssetInfo) => {
|
|
145
|
-
return Promise.resolve(
|
|
146
|
-
'assetReference' in assetInfo && assetInfo.assetReference === '0x123'
|
|
147
|
-
)
|
|
148
|
-
},
|
|
149
|
-
expected: [
|
|
150
|
-
{
|
|
151
|
-
value: BigInt('1000000'),
|
|
152
|
-
asset: { type: 'erc20', assetReference: '0x123', assetOwner: '0x000' },
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
title: 'all tokens except one',
|
|
158
|
-
operations: {
|
|
159
|
-
lastTokenOperations: [
|
|
160
|
-
{ asset: { type: 'erc20', assetReference: '0x123' } },
|
|
161
|
-
{ asset: { type: 'erc20', assetReference: '0x456' } },
|
|
162
|
-
{ asset: { type: 'erc20', assetReference: '0x789' } },
|
|
163
|
-
],
|
|
164
|
-
nextPagingToken: '',
|
|
165
|
-
},
|
|
166
|
-
includeAssets: (assetInfo: AssetInfo) => {
|
|
167
|
-
return Promise.resolve(
|
|
168
|
-
'assetReference' in assetInfo && assetInfo.assetReference !== '0x789'
|
|
169
|
-
)
|
|
170
|
-
},
|
|
171
|
-
expected: [
|
|
172
|
-
{
|
|
173
|
-
value: BigInt('1'),
|
|
174
|
-
asset: { type: 'erc20', assetReference: '0x123', assetOwner: '0x000' },
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
value: BigInt('2'),
|
|
178
|
-
asset: { type: 'erc20', assetReference: '0x456', assetOwner: '0x000' },
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
},
|
|
182
|
-
])(
|
|
183
|
-
'should fetch balance only for tokens filtered by options: $title',
|
|
184
|
-
async ({ operations, includeAssets, expected }) => {
|
|
185
|
-
nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('0'))
|
|
186
|
-
mockGetStakes.mockResolvedValue({ items: [] })
|
|
187
|
-
|
|
188
|
-
mockGetExplorerApi.mockReturnValue({
|
|
189
|
-
getOperations: jest.fn().mockResolvedValue(operations),
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
const currency = ''
|
|
193
|
-
const userAddress = '0x000'
|
|
194
|
-
|
|
195
|
-
await getBalance(context, currency, userAddress, { includeAssets })
|
|
196
|
-
|
|
197
|
-
expect(nodeApiMock.getTokenBalance).toHaveBeenCalledTimes(expected.length)
|
|
198
|
-
for (const balance of expected) {
|
|
199
|
-
expect(nodeApiMock.getTokenBalance).toHaveBeenCalledWith(
|
|
200
|
-
currency,
|
|
201
|
-
userAddress,
|
|
202
|
-
balance.asset.assetReference
|
|
203
|
-
)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const notSupportedTokens = operations.lastTokenOperations.filter(
|
|
207
|
-
(token) =>
|
|
208
|
-
!expected.some((item) => item.asset.assetReference === token.asset.assetReference)
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
expect(notSupportedTokens).not.toHaveLength(0)
|
|
212
|
-
for (const token of notSupportedTokens) {
|
|
213
|
-
expect(nodeApiMock.getTokenBalance).not.toHaveBeenCalledWith(
|
|
214
|
-
currency,
|
|
215
|
-
userAddress,
|
|
216
|
-
token.asset.assetReference
|
|
217
|
-
)
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
)
|
|
221
|
-
|
|
222
|
-
it('is resilient when failing to fetch token balances', async () => {
|
|
223
|
-
nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber(10))
|
|
224
|
-
nodeApiMock.getTokenBalance.mockImplementation(
|
|
225
|
-
(_currency: unknown, _address: string, contract: string) => {
|
|
226
|
-
if (contract === 'contract2') {
|
|
227
|
-
return Promise.reject(new Error('Scam token'))
|
|
228
|
-
}
|
|
229
|
-
return Promise.resolve(new BigNumber(2))
|
|
230
|
-
}
|
|
231
|
-
)
|
|
232
|
-
mockGetExplorerApi.mockReturnValue({
|
|
233
|
-
getOperations: jest.fn().mockResolvedValue({
|
|
234
|
-
lastCoinOperations: [],
|
|
235
|
-
lastTokenOperations: [
|
|
236
|
-
{ asset: { type: 'erc20', assetReference: 'contract1' } },
|
|
237
|
-
{ asset: { type: 'erc20', assetReference: 'contract1' } },
|
|
238
|
-
{ asset: { type: 'erc20', assetReference: 'contract2' } },
|
|
239
|
-
],
|
|
240
|
-
lastNftOperations: [],
|
|
241
|
-
lastInternalOperations: [],
|
|
242
|
-
nextPagingToken: '',
|
|
243
|
-
}),
|
|
244
|
-
})
|
|
245
|
-
mockGetStakes.mockResolvedValue({
|
|
246
|
-
items: [],
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
const result = await getBalance(context, '', 'address')
|
|
250
|
-
|
|
251
|
-
expect(result).toEqual([
|
|
252
|
-
{ asset: { type: 'native' }, value: 10n },
|
|
253
|
-
{
|
|
254
|
-
asset: {
|
|
255
|
-
type: 'erc20',
|
|
256
|
-
assetReference: 'contract1',
|
|
257
|
-
assetOwner: 'address',
|
|
258
|
-
},
|
|
259
|
-
value: 2n,
|
|
260
|
-
},
|
|
261
|
-
])
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
describe('nativeContracts', () => {
|
|
265
|
-
const NATIVE_CONTRACT = '0x3600000000000000000000000000000000000000'
|
|
266
|
-
const REGULAR_CONTRACT = '0x123'
|
|
267
|
-
|
|
268
|
-
it('skips fetching ERC20 balance for contracts listed in nativeContracts', async () => {
|
|
269
|
-
setNativeContracts([NATIVE_CONTRACT])
|
|
270
|
-
nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('42'))
|
|
271
|
-
nodeApiMock.getTokenBalance.mockResolvedValue(new BigNumber('999'))
|
|
272
|
-
mockGetStakes.mockResolvedValue({ items: [] })
|
|
273
|
-
mockGetExplorerApi.mockReturnValue({
|
|
274
|
-
getOperations: jest.fn().mockResolvedValue({
|
|
275
|
-
lastTokenOperations: [
|
|
276
|
-
{ asset: { type: 'erc20', assetReference: NATIVE_CONTRACT } },
|
|
277
|
-
{ asset: { type: 'erc20', assetReference: REGULAR_CONTRACT } },
|
|
278
|
-
],
|
|
279
|
-
nextPagingToken: '',
|
|
280
|
-
}),
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
const result = await getBalance(context, '', 'address')
|
|
284
|
-
|
|
285
|
-
expect(nodeApiMock.getTokenBalance).toHaveBeenCalledTimes(1)
|
|
286
|
-
expect(nodeApiMock.getTokenBalance).toHaveBeenCalledWith(
|
|
287
|
-
expect.anything(),
|
|
288
|
-
'address',
|
|
289
|
-
REGULAR_CONTRACT
|
|
290
|
-
)
|
|
291
|
-
expect(nodeApiMock.getTokenBalance).not.toHaveBeenCalledWith(
|
|
292
|
-
expect.anything(),
|
|
293
|
-
expect.anything(),
|
|
294
|
-
NATIVE_CONTRACT
|
|
295
|
-
)
|
|
296
|
-
expect(result).toEqual([
|
|
297
|
-
{ asset: { type: 'native' }, value: 42n },
|
|
298
|
-
{
|
|
299
|
-
asset: { type: 'erc20', assetReference: REGULAR_CONTRACT, assetOwner: 'address' },
|
|
300
|
-
value: 999n,
|
|
301
|
-
},
|
|
302
|
-
])
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
it('matches nativeContracts case-insensitively', async () => {
|
|
306
|
-
setNativeContracts([NATIVE_CONTRACT.toUpperCase()])
|
|
307
|
-
nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('0'))
|
|
308
|
-
mockGetStakes.mockResolvedValue({ items: [] })
|
|
309
|
-
mockGetExplorerApi.mockReturnValue({
|
|
310
|
-
getOperations: jest.fn().mockResolvedValue({
|
|
311
|
-
lastTokenOperations: [
|
|
312
|
-
{ asset: { type: 'erc20', assetReference: NATIVE_CONTRACT.toLowerCase() } },
|
|
313
|
-
],
|
|
314
|
-
nextPagingToken: '',
|
|
315
|
-
}),
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
await getBalance(context, '', 'address')
|
|
319
|
-
|
|
320
|
-
expect(nodeApiMock.getTokenBalance).not.toHaveBeenCalled()
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
it('does not skip any contract when nativeContracts is undefined', async () => {
|
|
324
|
-
setNativeContracts(undefined)
|
|
325
|
-
nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('0'))
|
|
326
|
-
nodeApiMock.getTokenBalance.mockResolvedValue(new BigNumber('1'))
|
|
327
|
-
mockGetStakes.mockResolvedValue({ items: [] })
|
|
328
|
-
mockGetExplorerApi.mockReturnValue({
|
|
329
|
-
getOperations: jest.fn().mockResolvedValue({
|
|
330
|
-
lastTokenOperations: [
|
|
331
|
-
{ asset: { type: 'erc20', assetReference: NATIVE_CONTRACT } },
|
|
332
|
-
{ asset: { type: 'erc20', assetReference: REGULAR_CONTRACT } },
|
|
333
|
-
],
|
|
334
|
-
nextPagingToken: '',
|
|
335
|
-
}),
|
|
336
|
-
})
|
|
337
|
-
|
|
338
|
-
await getBalance(context, '', 'address')
|
|
339
|
-
|
|
340
|
-
expect(nodeApiMock.getTokenBalance).toHaveBeenCalledTimes(2)
|
|
341
|
-
})
|
|
342
|
-
})
|
|
343
|
-
|
|
344
|
-
it('returns empty stake when balance is zero', async () => {
|
|
345
|
-
nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber(0))
|
|
346
|
-
|
|
347
|
-
mockGetExplorerApi.mockReturnValue({
|
|
348
|
-
getOperations: jest.fn().mockResolvedValue({ lastTokenOperations: [], nextPagingToken: '' }),
|
|
349
|
-
})
|
|
350
|
-
|
|
351
|
-
// Mock getStakes to return empty stakes
|
|
352
|
-
mockGetStakes.mockResolvedValue({
|
|
353
|
-
items: [],
|
|
354
|
-
})
|
|
355
|
-
|
|
356
|
-
const result = await getBalance(context, '', 'address')
|
|
357
|
-
expect(result[0]).toEqual({
|
|
358
|
-
value: BigInt('0'),
|
|
359
|
-
asset: { type: 'native' },
|
|
360
|
-
})
|
|
361
|
-
})
|
|
362
|
-
})
|