@ledgerhq/coin-evm 5.3.2 → 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.
Files changed (47) hide show
  1. package/.oxlintrc.json +1 -1
  2. package/CHANGELOG.md +7 -0
  3. package/package.json +2 -2
  4. package/src/adapters/blockOperations.test.ts +27 -29
  5. package/src/api/index.flare.integ.test.ts +1 -13
  6. package/src/api/index.integ.test.ts +86 -97
  7. package/src/fixtures/context.fixtures.ts +79 -1
  8. package/src/fixtures/ethers.fixtures.ts +26 -0
  9. package/src/logic/broadcast.integ.test.ts +6 -18
  10. package/src/logic/broadcast.test.ts +19 -31
  11. package/src/logic/broadcastSource.test.ts +6 -7
  12. package/src/logic/common.test.ts +120 -112
  13. package/src/logic/craftTransaction.test.ts +161 -199
  14. package/src/logic/craftTransactionData.test.ts +6 -6
  15. package/src/logic/estimateFees.test.ts +19 -15
  16. package/src/logic/getBalance.test.ts +15 -14
  17. package/src/logic/getBlock.test.ts +372 -382
  18. package/src/logic/getBlockInfo.test.ts +6 -6
  19. package/src/logic/getNextSequence.test.ts +5 -5
  20. package/src/logic/getStakes.test.ts +34 -34
  21. package/src/logic/internalTransactionsFetcher.test.ts +23 -19
  22. package/src/logic/lastBlock.test.ts +29 -21
  23. package/src/logic/listOperations.test.ts +43 -40
  24. package/src/logic/validateIntent.test.ts +151 -101
  25. package/src/logic.test.ts +13 -18
  26. package/src/network/explorer/etherscan.test.ts +5 -5
  27. package/src/network/explorer/index.test.ts +51 -21
  28. package/src/network/explorer/ledger.test.ts +15 -4
  29. package/src/network/gasTracker/index.test.ts +14 -8
  30. package/src/network/gasTracker/ledger.test.ts +25 -13
  31. package/src/network/node/index.memoization.test.ts +25 -31
  32. package/src/network/node/index.test.ts +14 -25
  33. package/src/network/node/ledger.test.ts +45 -60
  34. package/src/network/node/node.fixtures.ts +0 -2
  35. package/src/network/node/rpc.test.ts +152 -177
  36. package/src/staking/encoder.test.ts +13 -21
  37. package/src/staking/logic.test.ts +20 -14
  38. package/src/staking/operations/index.test.ts +28 -28
  39. package/src/staking/prepareIntents.test.ts +26 -20
  40. package/src/staking/redelegations.test.ts +27 -18
  41. package/src/staking/rewards.test.ts +23 -15
  42. package/src/staking/rewardsFromReceipt.test.ts +19 -20
  43. package/src/staking/transactionData.test.ts +22 -22
  44. package/src/staking/validators/monad.test.ts +65 -24
  45. package/src/staking/validators/somnia.test.ts +21 -13
  46. package/src/staking/validators/zero_gravity.test.ts +118 -48
  47. package/src/staking/validators.integ.test.ts +13 -25
@@ -1,14 +1,14 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo, EvmContext } from '../config'
4
+ import type { EvmContext } from '../config'
5
5
  import type {
6
6
  AssetInfo,
7
7
  BufferTxData,
8
8
  MemoNotSupported,
9
- SendTransactionIntent,
10
9
  TransactionIntent,
11
10
  } from '@ledgerhq/coin-module-framework/api/index'
11
+ import { createSendTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
12
12
  import BigNumber from 'bignumber.js'
13
13
  import { GasEstimationError } from '../errors'
14
14
  import { createMockEvmContext } from '../fixtures/context.fixtures'
@@ -51,7 +51,7 @@ describe('estimateFees', () => {
51
51
  const nodeApiMock = mockNodeApi()
52
52
  const context: EvmContext = createMockEvmContext({
53
53
  gasTracker: { type: 'ledger', explorerId: 'eth' },
54
- } as Partial<EvmConfigInfo>)
54
+ })
55
55
 
56
56
  beforeEach(() => {
57
57
  jest.clearAllMocks()
@@ -61,10 +61,14 @@ describe('estimateFees', () => {
61
61
 
62
62
  it('does not try to estimate with an invalid address and returns 0 as fallback', async () => {
63
63
  expect(
64
- await estimateFees(context, 'ethereum', {
65
- type: 'send-legacy',
66
- recipient: 'not-an-address',
67
- } as TransactionIntent<MemoNotSupported, BufferTxData>)
64
+ await estimateFees(
65
+ context,
66
+ 'ethereum',
67
+ createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
68
+ type: 'send-legacy',
69
+ recipient: 'not-an-address',
70
+ })
71
+ )
68
72
  ).toEqual({ value: 0n })
69
73
  expect(nodeApiMock.getGasEstimation).not.toHaveBeenCalled()
70
74
  })
@@ -84,7 +88,7 @@ describe('estimateFees', () => {
84
88
  recipient: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
85
89
  sender: '0xsender',
86
90
  data: { type: 'buffer', value: Buffer.from([]) },
87
- } as SendTransactionIntent<MemoNotSupported, BufferTxData>,
91
+ },
88
92
  {
89
93
  feesStrategy: 'fast',
90
94
  gasOptions: {
@@ -184,7 +188,7 @@ describe('estimateFees', () => {
184
188
  type: 'erc20',
185
189
  assetReference: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
186
190
  },
187
- } as SendTransactionIntent<MemoNotSupported, BufferTxData>,
191
+ },
188
192
  { feesStrategy: 'fast' }
189
193
  )
190
194
 
@@ -244,7 +248,7 @@ describe('estimateFees', () => {
244
248
  sender: '0xsender',
245
249
  data: { type: 'buffer', value: Buffer.from([]) },
246
250
  asset: { type: 'native' },
247
- } as SendTransactionIntent<MemoNotSupported, BufferTxData>,
251
+ },
248
252
  { feesStrategy: 'medium' }
249
253
  )
250
254
 
@@ -275,7 +279,7 @@ describe('estimateFees', () => {
275
279
  recipient: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
276
280
  sender: '0xsender',
277
281
  data: { type: 'buffer', value: Buffer.from([]) },
278
- } as SendTransactionIntent<MemoNotSupported, BufferTxData>,
282
+ },
279
283
  {
280
284
  feesStrategy: 'custom',
281
285
  gasPrice: 60000n,
@@ -317,7 +321,7 @@ describe('estimateFees', () => {
317
321
  recipient: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
318
322
  sender: '0xsender',
319
323
  data: { type: 'buffer', value: Buffer.from([]) },
320
- } as SendTransactionIntent<MemoNotSupported, BufferTxData>,
324
+ },
321
325
  { feesStrategy: 'slow' }
322
326
  )
323
327
 
@@ -356,7 +360,7 @@ describe('estimateFees', () => {
356
360
  recipient: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
357
361
  sender: '0xsender',
358
362
  data: { type: 'buffer', value: Buffer.from([]) },
359
- } as SendTransactionIntent<MemoNotSupported, BufferTxData>,
363
+ },
360
364
  { feesStrategy: 'slow' }
361
365
  )
362
366
 
@@ -601,7 +605,7 @@ describe('estimateFees', () => {
601
605
  recipient: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
602
606
  sender: '0xsender',
603
607
  data: { type: 'buffer', value: Buffer.from([]) },
604
- } as SendTransactionIntent<MemoNotSupported, BufferTxData>,
608
+ },
605
609
  {
606
610
  feesStrategy: 'custom',
607
611
  gasPrice: 1_000_000_000n,
@@ -642,7 +646,7 @@ describe('estimateFees', () => {
642
646
  recipient: '0x7b2C7232f9E38F30E2868f0E5Bf311Cd83554b5A',
643
647
  sender: '0xsender',
644
648
  data: { type: 'buffer', value: Buffer.from([]) },
645
- } as SendTransactionIntent<MemoNotSupported, BufferTxData>,
649
+ },
646
650
  {
647
651
  feesStrategy: 'custom',
648
652
  gasLimit: 50000n,
@@ -1,7 +1,7 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo, EvmContext } from '../config'
4
+ import type { EvmContext } from '../config'
5
5
  import type { AssetInfo } from '@ledgerhq/coin-module-framework/api/types'
6
6
  import BigNumber from 'bignumber.js'
7
7
  import { createMockEvmContext } from '../fixtures/context.fixtures'
@@ -32,7 +32,7 @@ describe('getBalance', () => {
32
32
  const nodeApiMock = mockNodeApi()
33
33
  let context: EvmContext
34
34
  const setNativeContracts = (nativeContracts?: string[]) => {
35
- context = createMockEvmContext({ nativeContracts } as Partial<EvmConfigInfo>)
35
+ context = createMockEvmContext(Array.isArray(nativeContracts) ? { nativeContracts } : {})
36
36
  }
37
37
 
38
38
  beforeEach(() => {
@@ -103,13 +103,11 @@ describe('getBalance', () => {
103
103
  },
104
104
  ], // expected
105
105
  ],
106
- ])('returns %s', async (_, operations, tokenBalances, expected) => {
106
+ ])('returns %s', async (_, operations, tokenBalances: Record<string, string>, expected) => {
107
107
  nodeApiMock.getCoinBalance.mockResolvedValue(new BigNumber('10000000000000000000000'))
108
108
  nodeApiMock.getTokenBalance.mockImplementation(
109
109
  (_currency: unknown, _address: string, contractAddress: string) =>
110
- Promise.resolve(
111
- new BigNumber((tokenBalances as Record<string, string>)[contractAddress] || '0')
112
- )
110
+ Promise.resolve(new BigNumber(tokenBalances[contractAddress] || '0'))
113
111
  )
114
112
 
115
113
  mockGetExplorerApi.mockReturnValue({
@@ -232,14 +230,17 @@ describe('getBalance', () => {
232
230
  }
233
231
  )
234
232
  mockGetExplorerApi.mockReturnValue({
235
- getOperations: () =>
236
- Promise.resolve({
237
- lastTokenOperations: [
238
- { asset: { type: 'erc20', assetReference: 'contract1' } },
239
- { asset: { type: 'erc20', assetReference: 'contract1' } },
240
- { asset: { type: 'erc20', assetReference: 'contract2' } },
241
- ],
242
- } as any),
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
+ }),
243
244
  })
244
245
  mockGetStakes.mockResolvedValue({
245
246
  items: [],