@ledgerhq/coin-evm 5.3.2 → 5.3.4
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 +2 -2
- package/CHANGELOG.md +13 -0
- package/package.json +2 -2
- package/src/adapters/blockOperations.test.ts +27 -29
- package/src/api/index.flare.integ.test.ts +1 -13
- package/src/api/index.integ.test.ts +86 -97
- package/src/fixtures/context.fixtures.ts +79 -1
- package/src/fixtures/ethers.fixtures.ts +26 -0
- 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/common.test.ts +120 -112
- package/src/logic/craftTransaction.test.ts +161 -199
- package/src/logic/craftTransactionData.test.ts +6 -6
- package/src/logic/estimateFees.test.ts +19 -15
- package/src/logic/getBalance.test.ts +15 -14
- package/src/logic/getBlock.test.ts +372 -382
- package/src/logic/getBlockInfo.test.ts +6 -6
- package/src/logic/getNextSequence.test.ts +5 -5
- package/src/logic/getStakes.test.ts +34 -34
- package/src/logic/internalTransactionsFetcher.test.ts +23 -19
- package/src/logic/lastBlock.test.ts +29 -21
- package/src/logic/listOperations.test.ts +43 -40
- package/src/logic/validateIntent.test.ts +151 -101
- package/src/logic.test.ts +59 -79
- package/src/network/explorer/etherscan.test.ts +95 -136
- package/src/network/explorer/index.test.ts +51 -21
- package/src/network/explorer/ledger.test.ts +51 -44
- package/src/network/gasTracker/index.test.ts +14 -8
- package/src/network/gasTracker/ledger.test.ts +43 -61
- 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/node.fixtures.ts +0 -2
- package/src/network/node/rpc.test.ts +204 -219
- package/src/staking/encoder.test.ts +13 -21
- package/src/staking/logic.test.ts +20 -14
- package/src/staking/operations/index.test.ts +28 -28
- package/src/staking/prepareIntents.test.ts +26 -20
- package/src/staking/redelegations.test.ts +27 -18
- package/src/staking/rewards.test.ts +23 -15
- package/src/staking/rewardsFromReceipt.test.ts +19 -20
- package/src/staking/transactionData.test.ts +22 -22
- package/src/staking/validators/monad.test.ts +65 -24
- package/src/staking/validators/somnia.test.ts +21 -13
- package/src/staking/validators/zero_gravity.test.ts +118 -48
- package/src/staking/validators.integ.test.ts +13 -25
- package/src/api/index.fantom.integ.test.ts +0 -103
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { AssertionError, fail } from 'assert'
|
|
5
4
|
import { delay } from '@ledgerhq/coin-module-framework/promises'
|
|
6
5
|
import axios from 'axios'
|
|
7
6
|
import BigNumber from 'bignumber.js'
|
|
8
7
|
import { Transaction } from 'ethers'
|
|
9
8
|
import { DEFAULT_LEDGER_EXPLORER_URI } from '../../config'
|
|
10
9
|
import { GasEstimationError } from '../../errors'
|
|
10
|
+
import { createMockEvmConfigInfo } from '../../fixtures/context.fixtures'
|
|
11
11
|
import { getGasOptions } from '../gasTracker/ledger'
|
|
12
12
|
import { createLedgerNodeApi } from './ledger'
|
|
13
13
|
|
|
@@ -19,9 +19,9 @@ jest.mock('../gasTracker/ledger', () => ({
|
|
|
19
19
|
getGasOptions: jest.fn(),
|
|
20
20
|
}))
|
|
21
21
|
|
|
22
|
-
const mockGetGasOptions =
|
|
22
|
+
const mockGetGasOptions = jest.mocked(getGasOptions)
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
jest.mocked(delay).mockImplementation(
|
|
25
25
|
() => new Promise((resolve) => setTimeout(resolve, 1)) // mocking the delay supposed to happen after each try
|
|
26
26
|
)
|
|
27
27
|
|
|
@@ -149,15 +149,7 @@ describe('EVM Family', () => {
|
|
|
149
149
|
}
|
|
150
150
|
return { data: {} }
|
|
151
151
|
})
|
|
152
|
-
|
|
153
|
-
await api.getTransaction(currencyId, '0xHash')
|
|
154
|
-
fail('Promise should have been rejected')
|
|
155
|
-
} catch (e) {
|
|
156
|
-
if (e instanceof AssertionError) {
|
|
157
|
-
throw e
|
|
158
|
-
}
|
|
159
|
-
expect(e).toBeInstanceOf(SpyError)
|
|
160
|
-
}
|
|
152
|
+
await expect(api.getTransaction(currencyId, '0xHash')).rejects.toBeInstanceOf(SpyError)
|
|
161
153
|
})
|
|
162
154
|
})
|
|
163
155
|
|
|
@@ -290,15 +282,9 @@ describe('EVM Family', () => {
|
|
|
290
282
|
throw new Error()
|
|
291
283
|
})
|
|
292
284
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
} catch (e) {
|
|
297
|
-
if (e instanceof AssertionError) {
|
|
298
|
-
throw e
|
|
299
|
-
}
|
|
300
|
-
expect(e).toBeInstanceOf(GasEstimationError)
|
|
301
|
-
}
|
|
285
|
+
await expect(
|
|
286
|
+
api.getGasEstimation(currencyId, address, { amount: new BigNumber(0), recipient: '0x0' })
|
|
287
|
+
).rejects.toBeInstanceOf(GasEstimationError)
|
|
302
288
|
})
|
|
303
289
|
|
|
304
290
|
it('should throw GasEstimationError if request throws ECONNABORTED', async () => {
|
|
@@ -307,34 +293,17 @@ describe('EVM Family', () => {
|
|
|
307
293
|
.spyOn(axios, 'request')
|
|
308
294
|
.mockImplementation(() => Promise.reject({ code: 'ECONNABORTED' }))
|
|
309
295
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
} catch (e) {
|
|
314
|
-
if (e instanceof AssertionError) {
|
|
315
|
-
throw e
|
|
316
|
-
}
|
|
317
|
-
expect(e).toBeInstanceOf(GasEstimationError)
|
|
318
|
-
}
|
|
296
|
+
await expect(
|
|
297
|
+
api.getGasEstimation(currencyId, address, { amount: new BigNumber(0), recipient: '0x0' })
|
|
298
|
+
).rejects.toBeInstanceOf(GasEstimationError)
|
|
319
299
|
})
|
|
320
300
|
|
|
321
301
|
it('should return the expected payload', async () => {
|
|
322
302
|
const api = createLedgerNodeApi(ledgerConfig)
|
|
323
|
-
jest
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
to: '0xBob',
|
|
328
|
-
estimated_gas_limit: '1000000',
|
|
329
|
-
},
|
|
330
|
-
}
|
|
331
|
-
: {
|
|
332
|
-
data: {
|
|
333
|
-
to: '0xBob',
|
|
334
|
-
estimated_gas_limit: '789',
|
|
335
|
-
},
|
|
336
|
-
}
|
|
337
|
-
})
|
|
303
|
+
jest
|
|
304
|
+
.spyOn(axios, 'request')
|
|
305
|
+
.mockResolvedValueOnce({ data: { to: '0xBob', estimated_gas_limit: '789' } })
|
|
306
|
+
.mockResolvedValueOnce({ data: { to: '0xBob', estimated_gas_limit: '1000000' } })
|
|
338
307
|
|
|
339
308
|
const transaction = {
|
|
340
309
|
family: 'evm',
|
|
@@ -385,18 +354,30 @@ describe('EVM Family', () => {
|
|
|
385
354
|
},
|
|
386
355
|
}))
|
|
387
356
|
|
|
388
|
-
const slowFeeData = await api.getFeeData(
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
357
|
+
const slowFeeData = await api.getFeeData(
|
|
358
|
+
createMockEvmConfigInfo({ chainId: 1, node: ledgerConfig }),
|
|
359
|
+
currencyId,
|
|
360
|
+
{
|
|
361
|
+
type: 2,
|
|
362
|
+
feesStrategy: 'slow',
|
|
363
|
+
}
|
|
364
|
+
)
|
|
365
|
+
const mediumFeeData = await api.getFeeData(
|
|
366
|
+
createMockEvmConfigInfo({ chainId: 1, node: ledgerConfig }),
|
|
367
|
+
currencyId,
|
|
368
|
+
{
|
|
369
|
+
type: 2,
|
|
370
|
+
feesStrategy: 'medium',
|
|
371
|
+
}
|
|
372
|
+
)
|
|
373
|
+
const fastFeeData = await api.getFeeData(
|
|
374
|
+
createMockEvmConfigInfo({ chainId: 1, node: ledgerConfig }),
|
|
375
|
+
currencyId,
|
|
376
|
+
{
|
|
377
|
+
type: 2,
|
|
378
|
+
feesStrategy: 'fast',
|
|
379
|
+
}
|
|
380
|
+
)
|
|
400
381
|
|
|
401
382
|
expect(slowFeeData).toEqual({
|
|
402
383
|
maxFeePerGas: new BigNumber(1),
|
|
@@ -441,7 +422,11 @@ describe('EVM Family', () => {
|
|
|
441
422
|
},
|
|
442
423
|
}))
|
|
443
424
|
|
|
444
|
-
const feeData = await api.getFeeData(
|
|
425
|
+
const feeData = await api.getFeeData(
|
|
426
|
+
createMockEvmConfigInfo({ chainId: 1, node: ledgerConfig }),
|
|
427
|
+
currencyId,
|
|
428
|
+
{ type: 2 }
|
|
429
|
+
)
|
|
445
430
|
|
|
446
431
|
expect(feeData).toEqual({
|
|
447
432
|
maxFeePerGas: new BigNumber(5),
|
|
@@ -579,7 +564,7 @@ describe('EVM Family', () => {
|
|
|
579
564
|
describe('getOptimismAdditionalFees', () => {
|
|
580
565
|
it('should return 0 for an incompatible currency', async () => {
|
|
581
566
|
const api = createLedgerNodeApi(ledgerConfig)
|
|
582
|
-
expect(await api.getOptimismAdditionalFees(currencyId,
|
|
567
|
+
expect(await api.getOptimismAdditionalFees(currencyId, '')).toEqual(new BigNumber(0))
|
|
583
568
|
})
|
|
584
569
|
|
|
585
570
|
it('should return the expected payload', async () => {
|
|
@@ -659,7 +644,7 @@ describe('EVM Family', () => {
|
|
|
659
644
|
describe('getScrollAdditionalFees', () => {
|
|
660
645
|
it('should return 0 for an incompatible currency', async () => {
|
|
661
646
|
const api = createLedgerNodeApi(ledgerConfig)
|
|
662
|
-
expect(await api.getScrollAdditionalFees(currencyId,
|
|
647
|
+
expect(await api.getScrollAdditionalFees(currencyId, '')).toEqual(new BigNumber(0))
|
|
663
648
|
})
|
|
664
649
|
|
|
665
650
|
it('should return the expected payload', async () => {
|
|
@@ -15,8 +15,6 @@ export function mockNodeApi(overrides: Partial<jest.Mocked<NodeApi>> = {}): jest
|
|
|
15
15
|
broadcastTransaction: jest.fn(),
|
|
16
16
|
getBlockByHeight: jest.fn(),
|
|
17
17
|
getBlockReceipts: jest.fn(),
|
|
18
|
-
traceBlockErigon: jest.fn(),
|
|
19
|
-
traceBlockGeth: jest.fn(),
|
|
20
18
|
getOptimismAdditionalFees: jest.fn(),
|
|
21
19
|
getScrollAdditionalFees: jest.fn(),
|
|
22
20
|
...overrides,
|