@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.
Files changed (48) hide show
  1. package/.oxlintrc.json +2 -2
  2. package/CHANGELOG.md +13 -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 +59 -79
  26. package/src/network/explorer/etherscan.test.ts +95 -136
  27. package/src/network/explorer/index.test.ts +51 -21
  28. package/src/network/explorer/ledger.test.ts +51 -44
  29. package/src/network/gasTracker/index.test.ts +14 -8
  30. package/src/network/gasTracker/ledger.test.ts +43 -61
  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 +204 -219
  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
  48. package/src/api/index.fantom.integ.test.ts +0 -103
@@ -18,7 +18,7 @@ describe('encodeStakingData', () => {
18
18
 
19
19
  const encoded = encodeStakingData({
20
20
  currencyId,
21
- operation: 'delegate' as StakingOperation,
21
+ operation: 'delegate',
22
22
  config,
23
23
  params,
24
24
  })
@@ -33,7 +33,7 @@ describe('encodeStakingData', () => {
33
33
 
34
34
  const encoded = encodeStakingData({
35
35
  currencyId,
36
- operation: 'undelegate' as StakingOperation,
36
+ operation: 'undelegate',
37
37
  config,
38
38
  params,
39
39
  })
@@ -49,7 +49,7 @@ describe('encodeStakingData', () => {
49
49
 
50
50
  const encoded = encodeStakingData({
51
51
  currencyId,
52
- operation: 'redelegate' as StakingOperation,
52
+ operation: 'redelegate',
53
53
  config,
54
54
  params,
55
55
  })
@@ -84,7 +84,7 @@ describe('encodeStakingData', () => {
84
84
 
85
85
  const encoded = encodeStakingData({
86
86
  currencyId,
87
- operation: 'delegate' as StakingOperation,
87
+ operation: 'delegate',
88
88
  config,
89
89
  params,
90
90
  })
@@ -99,7 +99,7 @@ describe('encodeStakingData', () => {
99
99
 
100
100
  const encoded = encodeStakingData({
101
101
  currencyId,
102
- operation: 'undelegate' as StakingOperation,
102
+ operation: 'undelegate',
103
103
  config,
104
104
  params,
105
105
  })
@@ -115,7 +115,7 @@ describe('encodeStakingData', () => {
115
115
  expect(() => {
116
116
  encodeStakingData({
117
117
  currencyId: 'unsupported_currency',
118
- operation: 'delegate' as StakingOperation,
118
+ operation: 'delegate',
119
119
  config,
120
120
  params: ['validator'],
121
121
  })
@@ -126,7 +126,8 @@ describe('encodeStakingData', () => {
126
126
  expect(() => {
127
127
  encodeStakingData({
128
128
  currencyId: 'sei_evm',
129
- operation: 'invalidOperation' as StakingOperation,
129
+ // @ts-ignore — intentionally invalid operation to test error path
130
+ operation: 'invalidOperation',
130
131
  config,
131
132
  params: ['validator'],
132
133
  })
@@ -197,12 +198,7 @@ describe('decodeStakingResult', () => {
197
198
  [mockBalance, mockDelegation],
198
199
  ])
199
200
 
200
- const decoded = decodeStakingResult(
201
- currencyId,
202
- 'getStakedBalance' as StakingOperation,
203
- config,
204
- encodedResult
205
- )
201
+ const decoded = decodeStakingResult(currencyId, 'getStakedBalance', config, encodedResult)
206
202
 
207
203
  expect(decoded).toBeInstanceOf(Array)
208
204
  expect(decoded.length).toBeGreaterThan(0)
@@ -265,7 +261,7 @@ describe('decodeStakingResult', () => {
265
261
 
266
262
  const decoded = decodeStakingResult(
267
263
  'sei_evm',
268
- 'getStakedBalance' as StakingOperation,
264
+ 'getStakedBalance',
269
265
  STAKING_CONTRACTS['sei_evm'],
270
266
  encodedResult
271
267
  )
@@ -283,18 +279,14 @@ describe('decodeStakingResult', () => {
283
279
 
284
280
  it('should throw error for unsupported currency', () => {
285
281
  expect(() => {
286
- decodeStakingResult(
287
- 'unsupported_currency',
288
- 'getStakedBalance' as StakingOperation,
289
- config,
290
- '0x'
291
- )
282
+ decodeStakingResult('unsupported_currency', 'getStakedBalance', config, '0x')
292
283
  }).toThrow('No ABI found for staking currency: unsupported_currency')
293
284
  })
294
285
 
295
286
  it('should throw error for unsupported operation', () => {
296
287
  expect(() => {
297
- decodeStakingResult('sei_evm', 'invalidOperation' as StakingOperation, config, '0x')
288
+ // @ts-ignore — intentionally invalid operation to test error path
289
+ decodeStakingResult('sei_evm', 'invalidOperation', config, '0x')
298
290
  }).toThrow("Operation 'invalidOperation' not supported for currency: sei_evm")
299
291
  })
300
292
  })
@@ -1,9 +1,10 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo } from '../config'
5
4
  import type { Stake } from '@ledgerhq/coin-module-framework/api/types'
5
+ import type { DeepPartialCtor } from '@ledgerhq/coin-module-framework/test/utils'
6
6
  import { ethers } from 'ethers'
7
+ import { createMockEvmConfigInfo, mkExternalNode } from '../fixtures/context.fixtures'
7
8
  import {
8
9
  canCompound,
9
10
  canRedelegate,
@@ -12,12 +13,23 @@ import {
12
13
  isSeiAccountUnassociated,
13
14
  } from './logic'
14
15
 
16
+ jest.mock('ethers', () => {
17
+ const actual = jest.requireActual('ethers')
18
+ const JsonRpcProvider = jest.fn()
19
+ const Contract = jest.fn()
20
+ return {
21
+ ...actual,
22
+ ethers: { ...actual.ethers, JsonRpcProvider, Contract },
23
+ JsonRpcProvider,
24
+ Contract,
25
+ }
26
+ })
15
27
  jest.mock('../network/node/types')
16
28
 
17
29
  const mockIsExternalNodeConfig = jest.mocked(require('../network/node/types').isExternalNodeConfig)
18
30
 
19
- const mockNode = { type: 'external', uri: 'https://sei-evm.coin.ledger.com' }
20
- const mockConfig = { node: mockNode } as unknown as EvmConfigInfo
31
+ const mockNode = mkExternalNode({ uri: 'https://sei-evm.coin.ledger.com' })
32
+ const mockConfig = createMockEvmConfigInfo({ chainId: 1, node: mockNode })
21
33
 
22
34
  function makeStake(delegate: string, overrides: Partial<Stake> = {}): Stake {
23
35
  return {
@@ -130,26 +142,20 @@ describe('evm staking logic', () => {
130
142
 
131
143
  describe('isSeiAccountUnassociated', () => {
132
144
  const SEI_ADDRESS = '0x1234567890abcdef1234567890abcdef12345678'
133
- let contractSpy: jest.SpyInstance
134
- let providerSpy: jest.SpyInstance
135
145
  let mockGetSeiAddr: jest.Mock
136
146
 
137
147
  beforeEach(() => {
138
148
  jest.clearAllMocks()
139
149
  mockGetSeiAddr = jest.fn().mockResolvedValue('sei1associatedcosmosaddress')
140
- providerSpy = jest.spyOn(ethers, 'JsonRpcProvider' as any).mockImplementation(() => ({}))
141
- contractSpy = jest
142
- .spyOn(ethers, 'Contract' as any)
150
+ jest
151
+ .mocked<DeepPartialCtor<typeof ethers.JsonRpcProvider>>(ethers.JsonRpcProvider)
152
+ .mockImplementation(() => ({}))
153
+ jest
154
+ .mocked<DeepPartialCtor<typeof ethers.Contract>>(ethers.Contract)
143
155
  .mockImplementation(() => ({ getSeiAddr: mockGetSeiAddr }))
144
-
145
156
  mockIsExternalNodeConfig.mockImplementation((node: unknown) => node === mockNode)
146
157
  })
147
158
 
148
- afterEach(() => {
149
- contractSpy.mockRestore()
150
- providerSpy.mockRestore()
151
- })
152
-
153
159
  it('returns false for a non-sei_evm currency without querying the chain', async () => {
154
160
  await expect(isSeiAccountUnassociated(mockConfig, 'ethereum', SEI_ADDRESS)).resolves.toBe(
155
161
  false
@@ -18,7 +18,7 @@ describe('buildTransactionParams', () => {
18
18
  const currencyId = 'sei_evm'
19
19
 
20
20
  it('should build params for delegate operation', () => {
21
- const params = buildTransactionParams(currencyId, 'delegate' as StakingOperation, {
21
+ const params = buildTransactionParams(currencyId, 'delegate', {
22
22
  valAddress: validatorAddress,
23
23
  amount,
24
24
  })
@@ -27,7 +27,7 @@ describe('buildTransactionParams', () => {
27
27
  })
28
28
 
29
29
  it('should build params for undelegate operation (amount converted from 18-dec EVM to 6-dec usei)', () => {
30
- const params = buildTransactionParams(currencyId, 'undelegate' as StakingOperation, {
30
+ const params = buildTransactionParams(currencyId, 'undelegate', {
31
31
  valAddress: validatorAddress,
32
32
  amount,
33
33
  })
@@ -36,7 +36,7 @@ describe('buildTransactionParams', () => {
36
36
  })
37
37
 
38
38
  it('should build params for redelegate operation (amount converted from 18-dec EVM to 6-dec usei)', () => {
39
- const params = buildTransactionParams(currencyId, 'redelegate' as StakingOperation, {
39
+ const params = buildTransactionParams(currencyId, 'redelegate', {
40
40
  valAddress: validatorAddress,
41
41
  amount,
42
42
  dstValAddress: dstValidatorAddress,
@@ -47,7 +47,7 @@ describe('buildTransactionParams', () => {
47
47
 
48
48
  it('should truncate sub-usei precision on undelegate (precompile has 6-decimal precision)', () => {
49
49
  // 1.234567891 SEI -> truncated to 1.234567 uSEI (9th and later decimals dropped)
50
- const params = buildTransactionParams(currencyId, 'undelegate' as StakingOperation, {
50
+ const params = buildTransactionParams(currencyId, 'undelegate', {
51
51
  valAddress: validatorAddress,
52
52
  amount: 1234567891000000000n,
53
53
  })
@@ -57,7 +57,7 @@ describe('buildTransactionParams', () => {
57
57
 
58
58
  it('should throw error for redelegate without dstValAddress', () => {
59
59
  expect(() => {
60
- buildTransactionParams(currencyId, 'redelegate' as StakingOperation, {
60
+ buildTransactionParams(currencyId, 'redelegate', {
61
61
  valAddress: validatorAddress,
62
62
  amount,
63
63
  })
@@ -65,7 +65,7 @@ describe('buildTransactionParams', () => {
65
65
  })
66
66
 
67
67
  it('should build params for getStakedBalance operation', () => {
68
- const params = buildTransactionParams(currencyId, 'getStakedBalance' as StakingOperation, {
68
+ const params = buildTransactionParams(currencyId, 'getStakedBalance', {
69
69
  valAddress: validatorAddress,
70
70
  amount,
71
71
  dstValAddress: validatorAddress,
@@ -77,7 +77,7 @@ describe('buildTransactionParams', () => {
77
77
 
78
78
  it('should throw error for getStakedBalance without required params', () => {
79
79
  expect(() => {
80
- buildTransactionParams(currencyId, 'getStakedBalance' as StakingOperation, {
80
+ buildTransactionParams(currencyId, 'getStakedBalance', {
81
81
  valAddress: validatorAddress,
82
82
  amount,
83
83
  })
@@ -97,7 +97,7 @@ describe('buildTransactionParams', () => {
97
97
 
98
98
  describe('Monad', () => {
99
99
  it('builds params for delegate operation (valId as bigint, amount carried by msg.value)', () => {
100
- const params = buildTransactionParams('monad', 'delegate' as StakingOperation, {
100
+ const params = buildTransactionParams('monad', 'delegate', {
101
101
  valId: '42',
102
102
  amount: 1000000000000000000n,
103
103
  })
@@ -106,7 +106,7 @@ describe('buildTransactionParams', () => {
106
106
  })
107
107
 
108
108
  it('builds params for claimReward operation (valId as bigint)', () => {
109
- const params = buildTransactionParams('monad', 'claimReward' as StakingOperation, {
109
+ const params = buildTransactionParams('monad', 'claimReward', {
110
110
  valId: '42',
111
111
  amount: 0n,
112
112
  })
@@ -115,7 +115,7 @@ describe('buildTransactionParams', () => {
115
115
  })
116
116
 
117
117
  it('builds params for compoundReward operation (valId as bigint)', () => {
118
- const params = buildTransactionParams('monad', 'compoundReward' as StakingOperation, {
118
+ const params = buildTransactionParams('monad', 'compoundReward', {
119
119
  valId: '42',
120
120
  amount: 0n,
121
121
  })
@@ -125,14 +125,14 @@ describe('buildTransactionParams', () => {
125
125
 
126
126
  it('throws when monad staking is missing valId', () => {
127
127
  expect(() => {
128
- buildTransactionParams('monad', 'delegate' as StakingOperation, {
128
+ buildTransactionParams('monad', 'delegate', {
129
129
  amount: 1000000000000000000n,
130
130
  })
131
131
  }).toThrow('monad staking requires valId')
132
132
  })
133
133
 
134
134
  it('builds params for undelegate operation (valId, amount, withdrawId as bigints)', () => {
135
- const params = buildTransactionParams('monad', 'undelegate' as StakingOperation, {
135
+ const params = buildTransactionParams('monad', 'undelegate', {
136
136
  valId: '42',
137
137
  amount: 1000000000000000000n,
138
138
  withdrawId: '7',
@@ -143,7 +143,7 @@ describe('buildTransactionParams', () => {
143
143
 
144
144
  it('throws when monad undelegate is missing withdrawId', () => {
145
145
  expect(() => {
146
- buildTransactionParams('monad', 'undelegate' as StakingOperation, {
146
+ buildTransactionParams('monad', 'undelegate', {
147
147
  valId: '42',
148
148
  amount: 1000000000000000000n,
149
149
  })
@@ -151,7 +151,7 @@ describe('buildTransactionParams', () => {
151
151
  })
152
152
 
153
153
  it('builds params for withdraw operation (valId, withdrawId as bigints)', () => {
154
- const params = buildTransactionParams('monad', 'withdraw' as StakingOperation, {
154
+ const params = buildTransactionParams('monad', 'withdraw', {
155
155
  valId: '42',
156
156
  amount: 0n,
157
157
  withdrawId: '7',
@@ -162,7 +162,7 @@ describe('buildTransactionParams', () => {
162
162
 
163
163
  it('throws when monad withdraw is missing withdrawId', () => {
164
164
  expect(() => {
165
- buildTransactionParams('monad', 'withdraw' as StakingOperation, {
165
+ buildTransactionParams('monad', 'withdraw', {
166
166
  valId: '42',
167
167
  amount: 0n,
168
168
  })
@@ -175,7 +175,7 @@ describe('buildTransactionParams', () => {
175
175
  const celoValidatorAddress = '0x123456789abcdef'
176
176
 
177
177
  it('should build params for delegate operation', () => {
178
- const params = buildTransactionParams(currencyId, 'delegate' as StakingOperation, {
178
+ const params = buildTransactionParams(currencyId, 'delegate', {
179
179
  valAddress: celoValidatorAddress,
180
180
  amount,
181
181
  })
@@ -184,7 +184,7 @@ describe('buildTransactionParams', () => {
184
184
  })
185
185
 
186
186
  it('should build params for undelegate operation', () => {
187
- const params = buildTransactionParams(currencyId, 'undelegate' as StakingOperation, {
187
+ const params = buildTransactionParams(currencyId, 'undelegate', {
188
188
  valAddress: celoValidatorAddress,
189
189
  amount,
190
190
  })
@@ -194,7 +194,7 @@ describe('buildTransactionParams', () => {
194
194
 
195
195
  it('should throw error for redelegate operation (not supported)', () => {
196
196
  expect(() => {
197
- buildTransactionParams(currencyId, 'redelegate' as StakingOperation, {
197
+ buildTransactionParams(currencyId, 'redelegate', {
198
198
  valAddress: celoValidatorAddress,
199
199
  amount,
200
200
  })
@@ -202,7 +202,7 @@ describe('buildTransactionParams', () => {
202
202
  })
203
203
 
204
204
  it('should build params for getStakedBalance operation', () => {
205
- const params = buildTransactionParams(currencyId, 'getStakedBalance' as StakingOperation, {
205
+ const params = buildTransactionParams(currencyId, 'getStakedBalance', {
206
206
  valAddress: celoValidatorAddress,
207
207
  amount,
208
208
  })
@@ -211,7 +211,7 @@ describe('buildTransactionParams', () => {
211
211
  })
212
212
 
213
213
  it('should build params for getUnstakedBalance operation', () => {
214
- const params = buildTransactionParams(currencyId, 'getUnstakedBalance' as StakingOperation, {
214
+ const params = buildTransactionParams(currencyId, 'getUnstakedBalance', {
215
215
  valAddress: celoValidatorAddress,
216
216
  amount,
217
217
  })
@@ -225,7 +225,7 @@ describe('buildTransactionParams', () => {
225
225
  const somniaValidatorAddress = '0x1234567890abcdef1234567890abcdef12345678'
226
226
 
227
227
  it('builds params for delegate operation', () => {
228
- const params = buildTransactionParams(currencyId, 'delegate' as StakingOperation, {
228
+ const params = buildTransactionParams(currencyId, 'delegate', {
229
229
  valAddress: somniaValidatorAddress,
230
230
  amount,
231
231
  })
@@ -234,7 +234,7 @@ describe('buildTransactionParams', () => {
234
234
  })
235
235
 
236
236
  it('builds params for undelegate operation', () => {
237
- const params = buildTransactionParams(currencyId, 'undelegate' as StakingOperation, {
237
+ const params = buildTransactionParams(currencyId, 'undelegate', {
238
238
  valAddress: somniaValidatorAddress,
239
239
  amount,
240
240
  })
@@ -243,7 +243,7 @@ describe('buildTransactionParams', () => {
243
243
  })
244
244
 
245
245
  it('builds params for claimReward operation', () => {
246
- const params = buildTransactionParams(currencyId, 'claimReward' as StakingOperation, {
246
+ const params = buildTransactionParams(currencyId, 'claimReward', {
247
247
  valAddress: somniaValidatorAddress,
248
248
  amount: 0n,
249
249
  })
@@ -252,7 +252,7 @@ describe('buildTransactionParams', () => {
252
252
  })
253
253
 
254
254
  it('builds params for getStakedBalance operation', () => {
255
- const params = buildTransactionParams(currencyId, 'getStakedBalance' as StakingOperation, {
255
+ const params = buildTransactionParams(currencyId, 'getStakedBalance', {
256
256
  valAddress: somniaValidatorAddress,
257
257
  amount: 0n,
258
258
  delegator: delegatorAddress,
@@ -263,7 +263,7 @@ describe('buildTransactionParams', () => {
263
263
 
264
264
  it('throws when getStakedBalance is missing delegator', () => {
265
265
  expect(() => {
266
- buildTransactionParams(currencyId, 'getStakedBalance' as StakingOperation, {
266
+ buildTransactionParams(currencyId, 'getStakedBalance', {
267
267
  valAddress: somniaValidatorAddress,
268
268
  amount: 0n,
269
269
  })
@@ -274,7 +274,7 @@ describe('buildTransactionParams', () => {
274
274
  describe('Error handling', () => {
275
275
  it('should throw error for unsupported currency', () => {
276
276
  expect(() => {
277
- buildTransactionParams('unsupported_currency', 'delegate' as StakingOperation, {
277
+ buildTransactionParams('unsupported_currency', 'delegate', {
278
278
  valAddress: validatorAddress,
279
279
  amount,
280
280
  })
@@ -283,7 +283,7 @@ describe('buildTransactionParams', () => {
283
283
 
284
284
  it('should throw error for unsupported operation type', () => {
285
285
  expect(() => {
286
- buildTransactionParams('sei_evm', 'invalidOperation' as StakingOperation, {
286
+ buildTransactionParams('sei_evm', 'invalidOperation', {
287
287
  valAddress: validatorAddress,
288
288
  amount,
289
289
  })
@@ -294,7 +294,7 @@ describe('buildTransactionParams', () => {
294
294
  'throws when %s staking is missing valAddress',
295
295
  (currencyId) => {
296
296
  expect(() => {
297
- buildTransactionParams(currencyId, 'delegate' as StakingOperation, { amount })
297
+ buildTransactionParams(currencyId, 'delegate', { amount })
298
298
  }).toThrow(`${currencyId} staking requires valAddress`)
299
299
  }
300
300
  )
@@ -1,9 +1,13 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo } from '../config'
4
+ import type { MemoNotSupported } from '@ledgerhq/coin-module-framework/api/index'
5
+ import type { BufferTxData } from '@ledgerhq/coin-module-framework/api/types'
6
+ import type { TransactionRequest } from 'ethers'
7
+ import { createStakingTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
5
8
  import { ethers } from 'ethers'
6
9
  import zeroGravityAbi from '../abis/zero_gravity-validator.abi.json'
10
+ import { createMockEvmConfigInfo, mkExternalNode } from '../fixtures/context.fixtures'
7
11
  import { withApi } from '../network/node/rpc.common'
8
12
  import { isExternalNodeConfig } from '../network/node/types'
9
13
  import { prepareStakingIntent } from './prepareIntents'
@@ -15,32 +19,34 @@ jest.mock('./validators/monad', () => ({ __esModule: true, findFirstFreeWithdraw
15
19
  const mockedWithApi = jest.mocked(withApi)
16
20
  const mockedIsExternalNodeConfig = jest.mocked(isExternalNodeConfig)
17
21
 
18
- const mockConfig = {
19
- node: { type: 'external', uri: 'https://zero-gravity.coin.ledger.com' },
20
- } as unknown as EvmConfigInfo
22
+ const mockConfig = createMockEvmConfigInfo({
23
+ chainId: 1,
24
+ node: mkExternalNode({ uri: 'https://zero-gravity.coin.ledger.com' }),
25
+ })
21
26
 
22
27
  const makeIntent = (overrides: Record<string, unknown> = {}) =>
23
- ({
24
- intentType: 'staking',
25
- type: 'staking-legacy',
26
- mode: 'undelegate',
27
- amount: 1_000_000_000_000_000_000n,
28
- asset: { type: 'native' },
29
- recipient: '0x0000000000000000000000000000000000000001',
30
- sender: '0x0000000000000000000000000000000000000002',
31
- valAddress: '0x0000000000000000000000000000000000000001',
32
- data: { type: 'buffer', value: Buffer.from([]) },
33
- useAllAmount: false,
34
- ...overrides,
35
- }) as never
28
+ Object.assign(
29
+ createStakingTransactionIntentMockData<MemoNotSupported, BufferTxData>({
30
+ type: 'staking-legacy',
31
+ mode: 'undelegate',
32
+ amount: 1_000_000_000_000_000_000n,
33
+ asset: { type: 'native' },
34
+ recipient: '0x0000000000000000000000000000000000000001',
35
+ sender: '0x0000000000000000000000000000000000000002',
36
+ valAddress: '0x0000000000000000000000000000000000000001',
37
+ data: { type: 'buffer', value: Buffer.from([]) },
38
+ useAllAmount: false,
39
+ }),
40
+ overrides
41
+ )
36
42
 
37
43
  function makeCallHandler(options: {
38
44
  getDelegationShares?: bigint
39
45
  convertToSharesResult?: bigint
40
46
  withdrawalFeeGwei?: bigint
41
47
  }) {
42
- const iface = new ethers.Interface(zeroGravityAbi as ethers.InterfaceAbi)
43
- return jest.fn(async ({ data }: { data?: string }) => {
48
+ const iface = new ethers.Interface(zeroGravityAbi)
49
+ return jest.fn(async ({ data }: TransactionRequest) => {
44
50
  const desc = iface.parseTransaction({ data: data ?? '0x' })
45
51
  if (desc?.name === 'getDelegation') {
46
52
  return iface.encodeFunctionResult('getDelegation', [
@@ -60,7 +66,7 @@ function makeCallHandler(options: {
60
66
 
61
67
  function setupProvider(callHandler: ReturnType<typeof jest.fn>) {
62
68
  mockedWithApi.mockImplementation(async (_config, _currencyId, fn) =>
63
- fn({ call: callHandler } as never)
69
+ fn(Object.assign(Object.create(null), { call: callHandler }))
64
70
  )
65
71
  }
66
72
 
@@ -3,6 +3,7 @@
3
3
 
4
4
  import type { EvmConfigInfo } from '../config'
5
5
  import type { OperationLike } from './redelegations'
6
+ import type { DeepPartialCtor } from '@ledgerhq/coin-module-framework/test/utils'
6
7
  import { BigNumber } from 'bignumber.js'
7
8
  import { ethers } from 'ethers'
8
9
  import { USEI_TO_EVM_SCALE } from '../utils'
@@ -15,6 +16,17 @@ import {
15
16
  buildRedelegationsFromOps,
16
17
  } from './redelegations'
17
18
 
19
+ jest.mock('ethers', () => {
20
+ const actual = jest.requireActual('ethers')
21
+ const JsonRpcProvider = jest.fn()
22
+ const Contract = jest.fn()
23
+ return {
24
+ ...actual,
25
+ ethers: { ...actual.ethers, JsonRpcProvider, Contract },
26
+ JsonRpcProvider,
27
+ Contract,
28
+ }
29
+ })
18
30
  jest.mock('@ledgerhq/live-network', () => jest.fn())
19
31
  jest.mock('../network/node/rpc.common')
20
32
  jest.mock('../network/node/types')
@@ -63,30 +75,22 @@ function makeOperation(overrides: Partial<OperationLike> = {}): OperationLike {
63
75
 
64
76
  describe('redelegations', () => {
65
77
  describe('fetchRedelegations', () => {
66
- // Spy on ethers.Contract so the Sei address precompile call doesn't make a
67
- // real network request during tests. By default the spy resolves to a
68
- // dummy Cosmos address so the REST API call is reached in most tests.
69
- // Individual tests that want to verify failure behaviour override it.
70
- let contractSpy: jest.SpyInstance
71
- let providerSpy: jest.SpyInstance
78
+ // ethers.JsonRpcProvider and ethers.Contract are module-mocked at the top of
79
+ // this file so no real network request is made during tests.
72
80
  let mockGetSeiAddr: jest.Mock
73
81
 
74
82
  beforeEach(() => {
75
83
  jest.clearAllMocks()
76
84
  mockGetSeiAddr = jest.fn().mockResolvedValue('sei1defaultcosmosaddressfortest')
77
- providerSpy = jest.spyOn(ethers, 'JsonRpcProvider' as any).mockImplementation(() => ({}))
78
- contractSpy = jest
79
- .spyOn(ethers, 'Contract' as any)
85
+ jest
86
+ .mocked<DeepPartialCtor<typeof ethers.JsonRpcProvider>>(ethers.JsonRpcProvider)
87
+ .mockImplementation(() => ({}))
88
+ jest
89
+ .mocked<DeepPartialCtor<typeof ethers.Contract>>(ethers.Contract)
80
90
  .mockImplementation(() => ({ getSeiAddr: mockGetSeiAddr }))
81
-
82
91
  mockIsExternalNodeConfig.mockImplementation((node: unknown) => node === mockNode)
83
92
  })
84
93
 
85
- afterEach(() => {
86
- contractSpy.mockRestore()
87
- providerSpy.mockRestore()
88
- })
89
-
90
94
  it('should return [] for an unknown currencyId', async () => {
91
95
  expect(await fetchRedelegations(mockConfig, 'unknown_chain', '0xabc')).toEqual([])
92
96
  })
@@ -199,9 +203,14 @@ describe('redelegations', () => {
199
203
  await fetchRedelegations(mockConfig, 'sei_evm', evmAddress)
200
204
 
201
205
  expect(mockNetwork).toHaveBeenCalledTimes(1)
202
- const calledUrl: string = (mockNetwork.mock.calls[0][0] as { url: string }).url
203
- expect(calledUrl).toContain(canonicalCosmosAddress)
204
- expect(calledUrl).not.toContain('sei1vmzrwxhgllkjaswzawaue7m7f9qcrc0rww3ccn')
206
+ expect(mockNetwork).toHaveBeenCalledWith(
207
+ expect.objectContaining({ url: expect.stringContaining(canonicalCosmosAddress) })
208
+ )
209
+ expect(mockNetwork).not.toHaveBeenCalledWith(
210
+ expect.objectContaining({
211
+ url: expect.stringContaining('sei1vmzrwxhgllkjaswzawaue7m7f9qcrc0rww3ccn'),
212
+ })
213
+ )
205
214
  })
206
215
 
207
216
  it('should return [] when the precompile call fails (address not associated)', async () => {
@@ -1,11 +1,23 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { EvmConfigInfo } from '../config'
4
+ import type { DeepPartialCtor } from '@ledgerhq/coin-module-framework/test/utils'
5
5
  import { ethers } from 'ethers'
6
+ import { createMockEvmConfigInfo, mkExternalNode } from '../fixtures/context.fixtures'
6
7
  import { USEI_TO_EVM_SCALE } from '../utils'
7
8
  import { fetchRewards } from './rewards'
8
9
 
10
+ jest.mock('ethers', () => {
11
+ const actual = jest.requireActual('ethers')
12
+ const JsonRpcProvider = jest.fn()
13
+ const Contract = jest.fn()
14
+ return {
15
+ ...actual,
16
+ ethers: { ...actual.ethers, JsonRpcProvider, Contract },
17
+ JsonRpcProvider,
18
+ Contract,
19
+ }
20
+ })
9
21
  jest.mock('@ledgerhq/live-network', () => jest.fn())
10
22
  jest.mock('../network/node/types')
11
23
 
@@ -15,8 +27,8 @@ const mockIsExternalNodeConfig = jest.mocked(require('../network/node/types').is
15
27
  const EVM_ADDRESS = '0x1234567890abcdef1234567890abcdef12345678'
16
28
  const COSMOS_ADDRESS = 'sei1defaultcosmosaddressfortest'
17
29
 
18
- const mockNode = { type: 'external', uri: 'https://sei-evm.coin.ledger.com' }
19
- const mockConfig = { node: mockNode } as unknown as EvmConfigInfo
30
+ const mockNode = mkExternalNode({ uri: 'https://sei-evm.coin.ledger.com' })
31
+ const mockConfig = createMockEvmConfigInfo({ chainId: 1, node: mockNode })
20
32
 
21
33
  type RewardCoin = { denom: string; amount: string }
22
34
  const restResponse = (rewards: Array<{ validator_address: string; reward: RewardCoin[] }>) => ({
@@ -24,26 +36,20 @@ const restResponse = (rewards: Array<{ validator_address: string; reward: Reward
24
36
  })
25
37
 
26
38
  describe('fetchRewards', () => {
27
- let contractSpy: jest.SpyInstance
28
- let providerSpy: jest.SpyInstance
29
39
  let mockGetSeiAddr: jest.Mock
30
40
 
31
41
  beforeEach(() => {
32
42
  jest.clearAllMocks()
33
43
  mockGetSeiAddr = jest.fn().mockResolvedValue(COSMOS_ADDRESS)
34
- providerSpy = jest.spyOn(ethers, 'JsonRpcProvider' as any).mockReturnValue({})
35
- contractSpy = jest
36
- .spyOn(ethers, 'Contract' as any)
44
+ jest
45
+ .mocked<DeepPartialCtor<typeof ethers.JsonRpcProvider>>(ethers.JsonRpcProvider)
46
+ .mockReturnValue({})
47
+ jest
48
+ .mocked<DeepPartialCtor<typeof ethers.Contract>>(ethers.Contract)
37
49
  .mockReturnValue({ getSeiAddr: mockGetSeiAddr })
38
-
39
50
  mockIsExternalNodeConfig.mockImplementation((node: unknown) => node === mockNode)
40
51
  })
41
52
 
42
- afterEach(() => {
43
- contractSpy.mockRestore()
44
- providerSpy.mockRestore()
45
- })
46
-
47
53
  it.each([
48
54
  { case: 'unknown currencyId', currencyId: 'unknown_chain', setup: () => undefined },
49
55
  {
@@ -78,7 +84,9 @@ describe('fetchRewards', () => {
78
84
 
79
85
  await fetchRewards(mockConfig, 'sei_evm', '0x66c4371aE8FFeD2ec1c2EBbbcCfb7E494181E1E3')
80
86
 
81
- expect((mockNetwork.mock.calls[0][0] as { url: string }).url).toContain(canonicalCosmosAddress)
87
+ expect(mockNetwork.mock.calls[0][0]).toMatchObject({
88
+ url: expect.stringContaining(canonicalCosmosAddress),
89
+ })
82
90
  })
83
91
 
84
92
  it('scales the integer usei portion to wei (drops sub-usei sdk.Dec precision)', async () => {