@ledgerhq/coin-evm 5.3.1 → 5.3.3
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/.oxlintrc.json +3 -13
- package/CHANGELOG.md +13 -0
- package/lib/adapters/blockOperations.d.ts +2 -2
- package/lib/adapters/blockOperations.d.ts.map +1 -1
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/logic/combine.d.ts +2 -1
- package/lib/logic/combine.d.ts.map +1 -1
- package/lib/logic/combine.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.map +1 -1
- package/lib/logic/craftTransaction.d.ts +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransactionData.d.ts +1 -1
- package/lib/logic/craftTransactionData.d.ts.map +1 -1
- package/lib/logic/estimateFees.d.ts +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.d.ts +1 -1
- package/lib/logic/getBalance.d.ts.map +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getBlock.d.ts +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/getStakes.d.ts +1 -1
- package/lib/logic/getStakes.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +1 -1
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/logic.d.ts +1 -1
- package/lib/logic.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.d.ts +4 -4
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/index.d.ts +2 -2
- package/lib/network/explorer/index.d.ts.map +1 -1
- package/lib/network/explorer/index.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts +2 -2
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/none.d.ts +1 -1
- package/lib/network/explorer/none.d.ts.map +1 -1
- package/lib/network/explorer/none.js.map +1 -1
- package/lib/network/explorer/types.d.ts +1 -1
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/gasTracker/index.d.ts +2 -2
- package/lib/network/gasTracker/index.d.ts.map +1 -1
- package/lib/network/gasTracker/index.js.map +1 -1
- package/lib/network/gasTracker/ledger.d.ts +3 -3
- package/lib/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib/network/gasTracker/ledger.js.map +1 -1
- package/lib/network/gasTracker/types.d.ts +2 -2
- package/lib/network/gasTracker/types.d.ts.map +1 -1
- package/lib/network/node/ledger.d.ts +2 -2
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +3 -3
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/staking/validators/monad.d.ts +2 -1
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts +2 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib/types/assets.d.ts +1 -1
- package/lib/types/assets.d.ts.map +1 -1
- package/lib/types/transaction.d.ts +1 -1
- package/lib/types/transaction.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.d.ts +2 -2
- package/lib-es/adapters/blockOperations.d.ts.map +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/api/index.d.ts +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/config.d.ts +1 -1
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/logic/combine.d.ts +2 -1
- package/lib-es/logic/combine.d.ts.map +1 -1
- package/lib-es/logic/combine.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 +1 -1
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransactionData.d.ts +1 -1
- package/lib-es/logic/craftTransactionData.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.d.ts +1 -1
- package/lib-es/logic/getBalance.d.ts.map +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts +1 -1
- package/lib-es/logic/getStakes.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +1 -1
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/logic.d.ts +1 -1
- package/lib-es/logic.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts +4 -4
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/index.d.ts +2 -2
- package/lib-es/network/explorer/index.d.ts.map +1 -1
- package/lib-es/network/explorer/index.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts +2 -2
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/none.d.ts +1 -1
- package/lib-es/network/explorer/none.d.ts.map +1 -1
- package/lib-es/network/explorer/none.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts +1 -1
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.d.ts +2 -2
- package/lib-es/network/gasTracker/index.d.ts.map +1 -1
- package/lib-es/network/gasTracker/index.js.map +1 -1
- package/lib-es/network/gasTracker/ledger.d.ts +3 -3
- package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib-es/network/gasTracker/ledger.js +1 -1
- package/lib-es/network/gasTracker/ledger.js.map +1 -1
- package/lib-es/network/gasTracker/types.d.ts +2 -2
- package/lib-es/network/gasTracker/types.d.ts.map +1 -1
- package/lib-es/network/node/ledger.d.ts +2 -2
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +1 -1
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +3 -3
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.d.ts +2 -1
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts +2 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/types/assets.d.ts +1 -1
- package/lib-es/types/assets.d.ts.map +1 -1
- package/lib-es/types/transaction.d.ts +1 -1
- package/lib-es/types/transaction.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/adapters/blockOperations.test.ts +29 -31
- package/src/adapters/blockOperations.ts +3 -2
- package/src/adapters/etherscan.test.ts +7 -7
- package/src/adapters/ledger.test.ts +2 -2
- package/src/api/getBlock.integ.test.ts +1 -1
- package/src/api/index.fantom.integ.test.ts +1 -1
- package/src/api/index.flare.integ.test.ts +2 -14
- package/src/api/index.integ.test.ts +330 -246
- package/src/api/index.linea.integ.test.ts +1 -1
- package/src/api/index.optimism.integ.test.ts +1 -1
- package/src/api/index.shape.integ.test.ts +1 -1
- package/src/api/index.ts +1 -1
- package/src/config.ts +1 -1
- package/src/fixtures/context.fixtures.ts +79 -1
- package/src/fixtures/ethers.fixtures.ts +26 -0
- package/src/fixtures/ledger.fixtures.ts +1 -1
- package/src/internalTxSources.test.ts +3 -6
- package/src/logic/broadcast.integ.test.ts +6 -18
- package/src/logic/broadcast.test.ts +19 -31
- package/src/logic/broadcastSource.test.ts +6 -7
- package/src/logic/combine.test.ts +2 -2
- package/src/logic/combine.ts +2 -1
- package/src/logic/common.test.ts +120 -112
- package/src/logic/common.ts +2 -7
- package/src/logic/craftTransaction.test.ts +163 -200
- package/src/logic/craftTransaction.ts +3 -2
- package/src/logic/craftTransactionData.test.ts +6 -6
- package/src/logic/craftTransactionData.ts +1 -1
- package/src/logic/estimateFees.test.ts +19 -15
- package/src/logic/estimateFees.ts +6 -3
- package/src/logic/getBalance.test.ts +16 -15
- package/src/logic/getBalance.ts +4 -3
- package/src/logic/getBlock.test.ts +379 -388
- package/src/logic/getBlock.ts +3 -2
- package/src/logic/getBlockInfo.test.ts +7 -9
- package/src/logic/getNextSequence.test.ts +5 -5
- package/src/logic/getStakes.test.ts +35 -35
- package/src/logic/getStakes.ts +1 -1
- package/src/logic/internalTransactionsFetcher.test.ts +26 -24
- package/src/logic/internalTransactionsFetcher.ts +1 -1
- package/src/logic/lastBlock.test.ts +29 -20
- package/src/logic/listOperations.test.ts +44 -40
- package/src/logic/validateIntent.test.ts +152 -101
- package/src/logic/validateIntent.ts +4 -2
- package/src/logic.test.ts +13 -18
- package/src/logic.ts +1 -1
- package/src/network/explorer/etherscan.test.ts +6 -6
- package/src/network/explorer/etherscan.ts +12 -10
- package/src/network/explorer/index.test.ts +52 -22
- package/src/network/explorer/index.ts +2 -2
- package/src/network/explorer/ledger.test.ts +17 -5
- package/src/network/explorer/ledger.ts +3 -2
- package/src/network/explorer/none.ts +2 -1
- package/src/network/explorer/types.ts +1 -1
- package/src/network/gasTracker/index.test.ts +14 -8
- package/src/network/gasTracker/index.ts +2 -2
- package/src/network/gasTracker/ledger.test.ts +34 -29
- package/src/network/gasTracker/ledger.ts +5 -7
- package/src/network/gasTracker/types.ts +2 -2
- package/src/network/node/index.memoization.test.ts +25 -31
- package/src/network/node/index.test.ts +14 -25
- package/src/network/node/ledger.test.ts +45 -60
- package/src/network/node/ledger.ts +6 -5
- package/src/network/node/node.fixtures.ts +0 -2
- package/src/network/node/rpc.common.ts +14 -14
- package/src/network/node/rpc.test.ts +153 -184
- package/src/network/node/types.ts +3 -3
- package/src/staking/detectOperationType.test.ts +1 -1
- package/src/staking/encoder.test.ts +14 -22
- package/src/staking/logic.test.ts +20 -14
- package/src/staking/operations/index.test.ts +29 -29
- package/src/staking/prepareIntents.test.ts +26 -20
- package/src/staking/redelegations.test.ts +50 -33
- package/src/staking/rewards.test.ts +29 -17
- package/src/staking/rewardsFromReceipt.test.ts +20 -21
- package/src/staking/transactionData.test.ts +23 -23
- package/src/staking/validators/monad.test.ts +65 -24
- package/src/staking/validators/monad.ts +2 -1
- package/src/staking/validators/monadResolver.ts +2 -1
- package/src/staking/validators/somnia.test.ts +21 -13
- package/src/staking/validators/somnia.ts +2 -1
- package/src/staking/validators/zero_gravity.test.ts +118 -48
- package/src/staking/validators/zero_gravity.ts +2 -1
- package/src/staking/validators.integ.test.ts +13 -25
- package/src/staking/validators.test.ts +7 -2
- package/src/types/assets.ts +1 -1
- package/src/types/transaction.ts +1 -1
package/src/logic/getBlock.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { EvmContext } from '../config'
|
|
5
|
+
import type { BlockReceiptInfo, PrefetchedBlockTransaction } from '../network/node/types'
|
|
4
6
|
import type {
|
|
5
7
|
Block,
|
|
6
8
|
BlockInfo,
|
|
@@ -11,10 +13,9 @@ import type {
|
|
|
11
13
|
import { promiseAllBatched } from '@ledgerhq/coin-module-framework/promises'
|
|
12
14
|
import { log } from '@ledgerhq/logs'
|
|
13
15
|
import { rpcTransactionToBlockOperations } from '../adapters/blockOperations'
|
|
14
|
-
import { DEFAULT_INTERNAL_TX_SOURCES
|
|
16
|
+
import { DEFAULT_INTERNAL_TX_SOURCES } from '../config'
|
|
15
17
|
import { UnsupportedRpcMethodError } from '../errors'
|
|
16
18
|
import { getNodeApi } from '../network/node'
|
|
17
|
-
import { BlockReceiptInfo, PrefetchedBlockTransaction } from '../network/node/types'
|
|
18
19
|
import { buildSmartContractDetails, safeEncodeEIP55 } from '../utils'
|
|
19
20
|
import { createInternalTransactionsFetcher } from './internalTransactionsFetcher'
|
|
20
21
|
import { dropRootTraceDuplicates } from './rootTraceDedup'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { EvmConfigInfo
|
|
5
|
-
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
4
|
+
import type { EvmConfigInfo } from '../config'
|
|
5
|
+
import { createMockEvmContext, mkExternalNode, mkLedgerNode } from '../fixtures/context.fixtures'
|
|
6
6
|
import { getNodeApi } from '../network/node'
|
|
7
7
|
import { mockNodeApi } from '../network/node/node.fixtures'
|
|
8
8
|
import { getBlockInfo } from './getBlockInfo'
|
|
@@ -26,10 +26,10 @@ describe('getBlockInfo', () => {
|
|
|
26
26
|
})
|
|
27
27
|
|
|
28
28
|
describe.each([
|
|
29
|
-
['an external node',
|
|
30
|
-
['a ledger node',
|
|
31
|
-
])('using %s', (_,
|
|
32
|
-
const context
|
|
29
|
+
['an external node', mkExternalNode(), externalMocks],
|
|
30
|
+
['a ledger node', mkLedgerNode(), ledgerMocks],
|
|
31
|
+
])('using %s', (_, node, nodeApiMock) => {
|
|
32
|
+
const context = createMockEvmContext({ node })
|
|
33
33
|
|
|
34
34
|
it('returns block info', async () => {
|
|
35
35
|
nodeApiMock.getBlockByHeight.mockResolvedValueOnce({
|
|
@@ -114,9 +114,7 @@ describe('getBlockInfo', () => {
|
|
|
114
114
|
const result = await getBlockInfo(context, '', 100)
|
|
115
115
|
|
|
116
116
|
expect(result.time).toBeInstanceOf(Date)
|
|
117
|
-
expect(result.parent).
|
|
118
|
-
expect(result.parent?.height).toBe(99)
|
|
119
|
-
expect(result.parent?.hash).toBe('0xparent')
|
|
117
|
+
expect(result.parent).toMatchObject({ height: 99, hash: '0xparent' })
|
|
120
118
|
})
|
|
121
119
|
})
|
|
122
120
|
})
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { EvmConfigInfo } from '../config'
|
|
5
|
-
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
5
|
+
import { createMockEvmContext, mkExternalNode, mkLedgerNode } from '../fixtures/context.fixtures'
|
|
6
6
|
import { getNodeApi } from '../network/node'
|
|
7
7
|
import { mockNodeApi } from '../network/node/node.fixtures'
|
|
8
8
|
import { getNextSequence } from './getNextSequence'
|
|
@@ -26,10 +26,10 @@ describe('getNextSequence', () => {
|
|
|
26
26
|
})
|
|
27
27
|
|
|
28
28
|
it.each([
|
|
29
|
-
['an external node',
|
|
30
|
-
['a ledger node',
|
|
31
|
-
])('returns next sequence for an address using %s', async (_,
|
|
32
|
-
const context = createMockEvmContext({ node
|
|
29
|
+
['an external node', mkExternalNode(), externalMocks],
|
|
30
|
+
['a ledger node', mkLedgerNode(), ledgerMocks],
|
|
31
|
+
])('returns next sequence for an address using %s', async (_, node, nodeApiMock) => {
|
|
32
|
+
const context = createMockEvmContext({ node })
|
|
33
33
|
nodeApiMock.getTransactionCount.mockResolvedValue(42)
|
|
34
34
|
|
|
35
35
|
expect(await getNextSequence(context, '', '')).toEqual(42n)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { EvmConfigInfo } from '../config'
|
|
5
|
-
import { JsonRpcProvider } from 'ethers'
|
|
6
4
|
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
5
|
+
import { mkJsonRpcProvider, mkResult } from '../fixtures/ethers.fixtures'
|
|
7
6
|
import { withApi } from '../network/node/rpc.common'
|
|
8
7
|
import { encodeStakingData, decodeStakingResult } from '../staking/encoder'
|
|
9
8
|
import { getValidators } from '../staking/validators'
|
|
@@ -23,16 +22,16 @@ jest.mock('../staking/validators', () => ({
|
|
|
23
22
|
getValidators: jest.fn(),
|
|
24
23
|
}))
|
|
25
24
|
|
|
26
|
-
const mockWithApi =
|
|
27
|
-
const mockEncodeStakingData =
|
|
28
|
-
const mockDecodeStakingResult =
|
|
29
|
-
const mockGetValidators =
|
|
25
|
+
const mockWithApi = jest.mocked(withApi)
|
|
26
|
+
const mockEncodeStakingData = jest.mocked(encodeStakingData)
|
|
27
|
+
const mockDecodeStakingResult = jest.mocked(decodeStakingResult)
|
|
28
|
+
const mockGetValidators = jest.mocked(getValidators)
|
|
30
29
|
|
|
31
30
|
const externalNodeConfig = { type: 'external' as const, uri: 'https://test' }
|
|
32
31
|
const context = createMockEvmContext({
|
|
33
32
|
node: externalNodeConfig,
|
|
34
33
|
name: 'Celo',
|
|
35
|
-
}
|
|
34
|
+
})
|
|
36
35
|
const makeValidator = (validatorAddress: string) => ({
|
|
37
36
|
id: validatorAddress,
|
|
38
37
|
address: validatorAddress,
|
|
@@ -44,17 +43,18 @@ describe('EVM Staking - getStakes', () => {
|
|
|
44
43
|
|
|
45
44
|
beforeEach(() => {
|
|
46
45
|
jest.clearAllMocks()
|
|
47
|
-
jest.spyOn(console, 'error').mockImplementation(() =>
|
|
46
|
+
jest.spyOn(console, 'error').mockImplementation(() => undefined)
|
|
48
47
|
})
|
|
49
48
|
|
|
50
49
|
it('should return stake objects with positive amounts for supported currencies', async () => {
|
|
51
50
|
mockWithApi.mockImplementation(async (_cur, _currencyId, fn) => {
|
|
52
|
-
const api =
|
|
51
|
+
const api = mkJsonRpcProvider()
|
|
52
|
+
jest.spyOn(api, 'call').mockResolvedValue('0x')
|
|
53
53
|
return fn(api)
|
|
54
54
|
})
|
|
55
55
|
|
|
56
56
|
mockEncodeStakingData.mockReturnValue('0xdeadbeef')
|
|
57
|
-
mockDecodeStakingResult.mockReturnValue(
|
|
57
|
+
mockDecodeStakingResult.mockReturnValue(mkResult({ toString: (): string => '1000000' }))
|
|
58
58
|
|
|
59
59
|
const result = await getStakes(context, 'celo', address)
|
|
60
60
|
|
|
@@ -81,11 +81,12 @@ describe('EVM Staking - getStakes', () => {
|
|
|
81
81
|
|
|
82
82
|
it('should filter out stakes with zero amounts', async () => {
|
|
83
83
|
mockWithApi.mockImplementation(async (_cur, _currencyId, fn) => {
|
|
84
|
-
const api =
|
|
84
|
+
const api = mkJsonRpcProvider()
|
|
85
|
+
jest.spyOn(api, 'call').mockResolvedValue('0x')
|
|
85
86
|
return fn(api)
|
|
86
87
|
})
|
|
87
88
|
mockEncodeStakingData.mockReturnValue('0xdeadbeef')
|
|
88
|
-
mockDecodeStakingResult.mockReturnValue(
|
|
89
|
+
mockDecodeStakingResult.mockReturnValue(mkResult({ toString: (): string => '0' }))
|
|
89
90
|
|
|
90
91
|
const result = await getStakes(context, 'celo', address)
|
|
91
92
|
|
|
@@ -101,24 +102,25 @@ describe('EVM Staking - getStakes', () => {
|
|
|
101
102
|
})
|
|
102
103
|
|
|
103
104
|
mockWithApi.mockImplementation(async (_cur, _currencyId, fn) => {
|
|
104
|
-
const api =
|
|
105
|
+
const api = mkJsonRpcProvider()
|
|
106
|
+
jest.spyOn(api, 'call').mockResolvedValue('0x')
|
|
105
107
|
return fn(api)
|
|
106
108
|
})
|
|
107
109
|
|
|
108
110
|
mockEncodeStakingData.mockReturnValue('0xdeadbeef')
|
|
109
111
|
|
|
110
|
-
mockDecodeStakingResult.mockReturnValueOnce(
|
|
111
|
-
{
|
|
112
|
+
mockDecodeStakingResult.mockReturnValueOnce(
|
|
113
|
+
mkResult({
|
|
112
114
|
balance: { amount: '0', denom: 'usei' },
|
|
113
115
|
delegation: { delegator_address: address, validator_address: 'seivaloper1abc' },
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
mockDecodeStakingResult.mockReturnValueOnce(
|
|
117
|
-
{
|
|
116
|
+
})
|
|
117
|
+
)
|
|
118
|
+
mockDecodeStakingResult.mockReturnValueOnce(
|
|
119
|
+
mkResult({
|
|
118
120
|
balance: { amount: '42', denom: 'usei' },
|
|
119
121
|
delegation: { delegator_address: address, validator_address: 'seivaloper1def' },
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
+
})
|
|
123
|
+
)
|
|
122
124
|
|
|
123
125
|
const result = await getStakes(context, 'sei_evm', address)
|
|
124
126
|
|
|
@@ -148,9 +150,8 @@ describe('EVM Staking - getStakes', () => {
|
|
|
148
150
|
|
|
149
151
|
it('should handle RPC call failures gracefully without crashing', async () => {
|
|
150
152
|
mockWithApi.mockImplementation(async (_cur, _currencyId, fn) => {
|
|
151
|
-
const api =
|
|
152
|
-
|
|
153
|
-
} as unknown as JsonRpcProvider
|
|
153
|
+
const api = mkJsonRpcProvider()
|
|
154
|
+
jest.spyOn(api, 'call').mockRejectedValue(new Error('rpc error'))
|
|
154
155
|
return fn(api)
|
|
155
156
|
})
|
|
156
157
|
mockEncodeStakingData.mockReturnValue('0xdeadbeef')
|
|
@@ -168,17 +169,16 @@ describe('EVM Staking - getStakes', () => {
|
|
|
168
169
|
next: undefined,
|
|
169
170
|
})
|
|
170
171
|
mockWithApi.mockImplementation(async (_cur, _currencyId, fn) => {
|
|
171
|
-
const api =
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
172
|
+
const api = mkJsonRpcProvider()
|
|
173
|
+
jest.spyOn(api, 'call').mockRejectedValue(
|
|
174
|
+
Object.assign(new Error('missing revert data'), {
|
|
175
|
+
code: 'CALL_EXCEPTION',
|
|
176
|
+
data: null,
|
|
177
|
+
reason: null,
|
|
178
|
+
revert: null,
|
|
179
|
+
shortMessage: 'missing revert data',
|
|
180
|
+
})
|
|
181
|
+
)
|
|
182
182
|
return fn(api)
|
|
183
183
|
})
|
|
184
184
|
mockEncodeStakingData.mockReturnValue('0xdeadbeef')
|
package/src/logic/getStakes.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { EvmContext } from '../config'
|
|
5
|
-
import { Page, Stake, StakesOptions } from '@ledgerhq/coin-module-framework/api/types'
|
|
5
|
+
import type { Page, Stake, StakesOptions } from '@ledgerhq/coin-module-framework/api/types'
|
|
6
6
|
import { STAKING_CONTRACTS, STAKING_CONFIG } from '../staking'
|
|
7
7
|
|
|
8
8
|
export const getStakes = async (
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { SourceFetcher } from './internalTransactionsFetcher'
|
|
4
5
|
import type { BlockOperation } from '@ledgerhq/coin-module-framework/api/index'
|
|
5
|
-
import {
|
|
6
|
+
import { internalTxSourcesFromList } from '../config'
|
|
6
7
|
import { SourceUnavailableError } from '../errors'
|
|
8
|
+
import {
|
|
9
|
+
createMockEvmConfigInfo,
|
|
10
|
+
mkEtherscanExplorer,
|
|
11
|
+
mkExternalNode,
|
|
12
|
+
mkLedgerExplorer,
|
|
13
|
+
} from '../fixtures/context.fixtures'
|
|
7
14
|
import { getInternalTransactionsByBlock } from '../network/explorer/etherscan'
|
|
8
15
|
import { mockNodeApi } from '../network/node/node.fixtures'
|
|
9
|
-
import {
|
|
10
|
-
composeInternalTxsFetcher,
|
|
11
|
-
makeSourceFetchers,
|
|
12
|
-
type SourceFetcher,
|
|
13
|
-
} from './internalTransactionsFetcher'
|
|
16
|
+
import { composeInternalTxsFetcher, makeSourceFetchers } from './internalTransactionsFetcher'
|
|
14
17
|
|
|
15
18
|
jest.mock('../network/explorer/etherscan', () => ({
|
|
16
19
|
getInternalTransactionsByBlock: jest.fn().mockResolvedValue([]),
|
|
@@ -166,19 +169,18 @@ describe('makeSourceFetchers', () => {
|
|
|
166
169
|
})
|
|
167
170
|
|
|
168
171
|
it('rejects explorer when explorer config is not etherscan-like', async () => {
|
|
169
|
-
const config = {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
const config = createMockEvmConfigInfo({
|
|
173
|
+
chainId: 1,
|
|
174
|
+
node: mkExternalNode(),
|
|
175
|
+
explorer: mkLedgerExplorer(),
|
|
176
|
+
})
|
|
173
177
|
|
|
174
178
|
const fetchers = makeSourceFetchers(config, mockNodeApi(), '')
|
|
175
179
|
await expect(fetchers.explorer(1)).rejects.toBeInstanceOf(SourceUnavailableError)
|
|
176
180
|
})
|
|
177
181
|
|
|
178
182
|
it('rejects trace_block when traceBlockErigon is undefined', async () => {
|
|
179
|
-
const config = {
|
|
180
|
-
node: { type: 'external' as const, retries: 0 },
|
|
181
|
-
} as unknown as EvmConfigInfo
|
|
183
|
+
const config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
182
184
|
|
|
183
185
|
const { traceBlockErigon: _traceBlockErigon, ...nodeApiWithoutErigon } = mockNodeApi()
|
|
184
186
|
const fetchers = makeSourceFetchers(config, nodeApiWithoutErigon, '')
|
|
@@ -186,10 +188,11 @@ describe('makeSourceFetchers', () => {
|
|
|
186
188
|
})
|
|
187
189
|
|
|
188
190
|
it('wraps explorer runtime failures as SourceUnavailableError', async () => {
|
|
189
|
-
const config = {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
const config = createMockEvmConfigInfo({
|
|
192
|
+
chainId: 1,
|
|
193
|
+
node: mkExternalNode(),
|
|
194
|
+
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
195
|
+
})
|
|
193
196
|
|
|
194
197
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
195
198
|
mockGetInternalTransactionsByBlock.mockRejectedValueOnce(new Error('explorer error'))
|
|
@@ -199,10 +202,11 @@ describe('makeSourceFetchers', () => {
|
|
|
199
202
|
})
|
|
200
203
|
|
|
201
204
|
it('calls getInternalTransactionsByBlock for explorer when configured', async () => {
|
|
202
|
-
const config = {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
const config = createMockEvmConfigInfo({
|
|
206
|
+
chainId: 1,
|
|
207
|
+
node: mkExternalNode(),
|
|
208
|
+
explorer: mkEtherscanExplorer({ uri: 'https://api.etherscan.io' }),
|
|
209
|
+
})
|
|
206
210
|
|
|
207
211
|
const mockGetInternalTransactionsByBlock = jest.mocked(getInternalTransactionsByBlock)
|
|
208
212
|
mockGetInternalTransactionsByBlock.mockResolvedValueOnce([])
|
|
@@ -214,9 +218,7 @@ describe('makeSourceFetchers', () => {
|
|
|
214
218
|
})
|
|
215
219
|
|
|
216
220
|
it('empty always resolves to an empty map', async () => {
|
|
217
|
-
const config = {
|
|
218
|
-
node: { type: 'external' as const, retries: 0 },
|
|
219
|
-
} as unknown as EvmConfigInfo
|
|
221
|
+
const config = createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
220
222
|
|
|
221
223
|
const fetchers = makeSourceFetchers(config, mockNodeApi(), '')
|
|
222
224
|
await expect(fetchers.empty(1)).resolves.toEqual(new Map<string, BlockOperation[]>())
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { EvmConfigInfo } from '../config'
|
|
5
5
|
import type { InternalTxSource } from '../internalTxSources'
|
|
6
|
+
import type { NodeApi } from '../network/node/types'
|
|
6
7
|
import type { BlockOperation } from '@ledgerhq/coin-module-framework/api/index'
|
|
7
8
|
import { log } from '@ledgerhq/logs'
|
|
8
9
|
import { traceBlockItemsToOperationsByHash } from '../adapters/blockOperations'
|
|
@@ -10,7 +11,6 @@ import { internalTxsToOperationsByHash } from '../adapters/etherscan'
|
|
|
10
11
|
import { SourceUnavailableError } from '../errors'
|
|
11
12
|
import { getInternalTransactionsByBlock } from '../network/explorer/etherscan'
|
|
12
13
|
import { isEtherscanLikeExplorerConfig } from '../network/explorer/types'
|
|
13
|
-
import { NodeApi } from '../network/node/types'
|
|
14
14
|
|
|
15
15
|
export type InternalTxsByHash = Map<string, BlockOperation[]>
|
|
16
16
|
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import type {
|
|
5
|
+
BlockFinalizationTag,
|
|
6
|
+
EvmConfigInfo,
|
|
7
|
+
ExternalNodeConfig,
|
|
8
|
+
LedgerNodeConfig,
|
|
9
|
+
} from '../config'
|
|
10
|
+
import { createMockEvmContext, mkExternalNode, mkLedgerNode } from '../fixtures/context.fixtures'
|
|
6
11
|
import { getNodeApi } from '../network/node'
|
|
7
12
|
import { mockNodeApi } from '../network/node/node.fixtures'
|
|
8
13
|
import { lastBlock } from './lastBlock'
|
|
@@ -26,9 +31,9 @@ describe('lastBlock', () => {
|
|
|
26
31
|
})
|
|
27
32
|
|
|
28
33
|
it.each([
|
|
29
|
-
['an external node',
|
|
30
|
-
['a ledger node',
|
|
31
|
-
])('returns last block info using %s', async (_,
|
|
34
|
+
['an external node', mkExternalNode(), externalMocks],
|
|
35
|
+
['a ledger node', mkLedgerNode(), ledgerMocks],
|
|
36
|
+
])('returns last block info using %s', async (_, node, nodeApiMock) => {
|
|
32
37
|
const blockResult = {
|
|
33
38
|
hash: 'hash',
|
|
34
39
|
parentHash: 'parentHash',
|
|
@@ -37,16 +42,16 @@ describe('lastBlock', () => {
|
|
|
37
42
|
}
|
|
38
43
|
const expectedInfo = { hash: 'hash', height: 33, time: new Date('2025-12-31') }
|
|
39
44
|
|
|
40
|
-
const context = createMockEvmContext({ node
|
|
45
|
+
const context = createMockEvmContext({ node })
|
|
41
46
|
nodeApiMock.getBlockByHeight.mockResolvedValue(blockResult)
|
|
42
47
|
|
|
43
48
|
expect(await lastBlock(context, '')).toEqual(expectedInfo)
|
|
44
49
|
})
|
|
45
50
|
|
|
46
51
|
it.each([
|
|
47
|
-
['an external node',
|
|
48
|
-
['a ledger node',
|
|
49
|
-
])("passes 'latest' by default to getBlockByHeight using %s", async (_,
|
|
52
|
+
['an external node', mkExternalNode(), externalMocks],
|
|
53
|
+
['a ledger node', mkLedgerNode(), ledgerMocks],
|
|
54
|
+
])("passes 'latest' by default to getBlockByHeight using %s", async (_, node, nodeApiMock) => {
|
|
50
55
|
const blockResult = {
|
|
51
56
|
hash: 'hash',
|
|
52
57
|
parentHash: 'parentHash',
|
|
@@ -54,7 +59,7 @@ describe('lastBlock', () => {
|
|
|
54
59
|
timestamp: new Date('2025-12-31').getTime(),
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
const context = createMockEvmContext({ node
|
|
62
|
+
const context = createMockEvmContext({ node })
|
|
58
63
|
nodeApiMock.getBlockByHeight.mockResolvedValue(blockResult)
|
|
59
64
|
|
|
60
65
|
await lastBlock(context, '')
|
|
@@ -62,14 +67,21 @@ describe('lastBlock', () => {
|
|
|
62
67
|
expect(nodeApiMock.getBlockByHeight).toHaveBeenCalledWith(expect.anything(), 'latest')
|
|
63
68
|
})
|
|
64
69
|
|
|
65
|
-
it.each<
|
|
66
|
-
[
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
it.each<
|
|
71
|
+
[
|
|
72
|
+
BlockFinalizationTag,
|
|
73
|
+
string,
|
|
74
|
+
ExternalNodeConfig | LedgerNodeConfig,
|
|
75
|
+
jest.Mocked<ReturnType<typeof mockNodeApi>>,
|
|
76
|
+
]
|
|
77
|
+
>([
|
|
78
|
+
['finalized', 'an external node', mkExternalNode(), externalMocks],
|
|
79
|
+
['finalized', 'a ledger node', mkLedgerNode(), ledgerMocks],
|
|
80
|
+
['safe', 'an external node', mkExternalNode(), externalMocks],
|
|
81
|
+
['safe', 'a ledger node', mkLedgerNode(), ledgerMocks],
|
|
70
82
|
])(
|
|
71
83
|
"forwards finalizationLevel '%s' to getBlockByHeight using %s",
|
|
72
|
-
async (finalizationLevel, _,
|
|
84
|
+
async (finalizationLevel, _, node, nodeApiMock) => {
|
|
73
85
|
const blockResult = {
|
|
74
86
|
hash: 'hash',
|
|
75
87
|
parentHash: 'parentHash',
|
|
@@ -78,10 +90,7 @@ describe('lastBlock', () => {
|
|
|
78
90
|
}
|
|
79
91
|
const expectedInfo = { hash: 'hash', height: 33, time: new Date('2025-12-31') }
|
|
80
92
|
|
|
81
|
-
const context = createMockEvmContext({
|
|
82
|
-
node: { type },
|
|
83
|
-
finalizationLevel,
|
|
84
|
-
} as Partial<EvmConfigInfo>)
|
|
93
|
+
const context = createMockEvmContext({ node, finalizationLevel })
|
|
85
94
|
nodeApiMock.getBlockByHeight.mockResolvedValue(blockResult)
|
|
86
95
|
|
|
87
96
|
expect(await lastBlock(context, '')).toEqual(expectedInfo)
|