@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,17 @@
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 type { TransactionReceipt, TransactionResponse, ethers } from 'ethers'
6
- import { AssertionError, fail } from 'assert'
7
4
  import { delay } from '@ledgerhq/coin-module-framework/promises'
8
5
  import BigNumber from 'bignumber.js'
9
- import { FetchRequest, JsonRpcProvider, Network, Transaction } from 'ethers'
6
+ import { FeeData, FetchRequest, JsonRpcProvider, Network, Transaction } from 'ethers'
10
7
  import { getCoinConfig } from '../../config'
11
8
  import { GasEstimationError, InsufficientFunds, UnsupportedRpcMethodError } from '../../errors'
9
+ import { createMockEvmConfigInfo, mkExternalNode } from '../../fixtures/context.fixtures'
10
+ import {
11
+ mkBlock,
12
+ mkTransactionReceipt,
13
+ mkTransactionResponse,
14
+ } from '../../fixtures/ethers.fixtures'
12
15
  import {
13
16
  createNodeApi,
14
17
  DEFAULT_RETRIES_RPC_METHODS,
@@ -22,11 +25,11 @@ import {
22
25
 
23
26
  const currencyId = 'my_new_chain'
24
27
 
25
- const evmConfig = {
28
+ const evmConfig = createMockEvmConfigInfo({
26
29
  chainId: 1,
27
30
  name: 'My New Chain',
28
- node: { type: 'external', uri: 'http://test' },
29
- } as EvmConfigInfo
31
+ node: mkExternalNode({ uri: 'http://test' }),
32
+ })
30
33
 
31
34
  const nodeApi = createNodeApi(evmConfig, {
32
35
  type: 'external',
@@ -44,7 +47,7 @@ const now = Math.floor(Date.now() / 1000)
44
47
  const address = '0x6cBCD73CD8e8a42844662f0A0e76D7F79Afd933d'
45
48
 
46
49
  jest.mock('@ledgerhq/coin-module-framework/promises')
47
- ;(delay as jest.Mock).mockImplementation(
50
+ jest.mocked(delay).mockImplementation(
48
51
  () => new Promise((resolve) => setTimeout(resolve, 1)) // mocking the delay supposed to happen after each try
49
52
  )
50
53
 
@@ -55,9 +58,7 @@ describe('EVM Family', () => {
55
58
 
56
59
  beforeEach(() => {
57
60
  jest.resetAllMocks()
58
- jest
59
- .spyOn(JsonRpcProvider.prototype as any, '_detectNetwork')
60
- .mockResolvedValue(Network.from(1))
61
+ jest.spyOn(JsonRpcProvider.prototype, '_detectNetwork').mockResolvedValue(Network.from(1))
61
62
 
62
63
  mockGetConfig.mockImplementation((): any => {
63
64
  return {
@@ -70,66 +71,66 @@ describe('EVM Family', () => {
70
71
  }
71
72
  })
72
73
 
73
- jest.spyOn(JsonRpcProvider.prototype, 'getFeeData').mockResolvedValue({
74
- gasPrice: BigInt(666),
75
- maxFeePerGas: 0n,
76
- maxPriorityFeePerGas: 0n,
77
- } as ethers.FeeData)
74
+ jest
75
+ .spyOn(JsonRpcProvider.prototype, 'getFeeData')
76
+ .mockResolvedValue(new FeeData(BigInt(666), 0n, 0n))
78
77
 
79
78
  jest.spyOn(JsonRpcProvider.prototype, 'getBalance').mockResolvedValue(BigInt(420))
80
79
  jest
81
80
  .spyOn(JsonRpcProvider.prototype, 'call')
82
81
  .mockResolvedValue('0x000000000000000000000000000000000000000000000000000000000000A455')
83
- jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValue({
84
- hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
85
- parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
86
- number: 1,
87
- difficulty: 0n,
88
- gasLimit: BigInt(1),
89
- gasUsed: BigInt(2),
90
- extraData: '0x',
91
- baseFeePerGas: BigInt(123),
92
- timestamp: now,
93
- } as Partial<ethers.Block> as ethers.Block)
82
+ jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValue(
83
+ mkBlock({
84
+ hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
85
+ parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
86
+ number: 1,
87
+ difficulty: 0n,
88
+ gasLimit: BigInt(1),
89
+ gasUsed: BigInt(2),
90
+ extraData: '0x',
91
+ baseFeePerGas: BigInt(123),
92
+ timestamp: now,
93
+ })
94
+ )
94
95
 
95
96
  jest.spyOn(JsonRpcProvider.prototype, 'getTransactionCount').mockResolvedValue(5)
96
97
 
97
- jest.spyOn(JsonRpcProvider.prototype, 'getTransaction').mockResolvedValue({
98
- hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
99
- blockNumber: 69,
100
- blockHash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
101
- nonce: 123,
102
- value: BigInt(456),
103
- gasLimit: BigInt(123),
104
- gasPrice: BigInt(789),
105
- data: '0x',
106
- to: '0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C',
107
- from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
108
- type: 0,
109
- confirmations: jest.fn().mockResolvedValue(1),
110
- provider: {} as any,
111
- } as Partial<TransactionResponse> as TransactionResponse)
112
-
113
- jest.spyOn(JsonRpcProvider.prototype, 'getTransactionReceipt').mockResolvedValue({
114
- blockHash: '0x8a179bc6cb299f936c4fd614995e62d597ec6108b579c23034fb220967ceaa94',
115
- blockNumber: 69,
116
- byzantium: true,
117
- confirmations: jest.fn().mockResolvedValue(100),
118
- contractAddress: null,
119
- cumulativeGasUsed: BigInt(121),
120
- effectiveGasPrice: BigInt(789),
121
- from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
122
- gasUsed: BigInt(122),
123
- gasLimit: BigInt(21000),
124
- gasPrice: BigInt(789),
125
- logs: [],
126
- logsBloom: '0x',
127
- status: 1,
128
- to: '0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C',
129
- transactionHash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
130
- transactionIndex: 123,
131
- type: 0,
132
- } as Partial<TransactionReceipt> as TransactionReceipt)
98
+ jest.spyOn(JsonRpcProvider.prototype, 'getTransaction').mockResolvedValue(
99
+ mkTransactionResponse({
100
+ hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
101
+ blockNumber: 69,
102
+ blockHash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
103
+ nonce: 123,
104
+ value: BigInt(456),
105
+ gasLimit: BigInt(123),
106
+ gasPrice: BigInt(789),
107
+ data: '0x',
108
+ to: '0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C',
109
+ from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
110
+ type: 0,
111
+ confirmations: jest.fn().mockResolvedValue(1),
112
+ })
113
+ )
114
+
115
+ jest.spyOn(JsonRpcProvider.prototype, 'getTransactionReceipt').mockResolvedValue(
116
+ mkTransactionReceipt({
117
+ blockHash: '0x8a179bc6cb299f936c4fd614995e62d597ec6108b579c23034fb220967ceaa94',
118
+ blockNumber: 69,
119
+ confirmations: jest.fn().mockResolvedValue(100),
120
+ contractAddress: null,
121
+ cumulativeGasUsed: BigInt(121),
122
+ from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
123
+ gasUsed: BigInt(122),
124
+ gasPrice: BigInt(789),
125
+ logs: [],
126
+ logsBloom: '0x',
127
+ status: 1,
128
+ to: '0xC2907EFccE4011C491BbedA8A0fA63BA7aab596C',
129
+ hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
130
+ index: 123,
131
+ type: 0,
132
+ })
133
+ )
133
134
 
134
135
  jest
135
136
  .spyOn(JsonRpcProvider.prototype, 'broadcastTransaction')
@@ -192,15 +193,7 @@ describe('EVM Family', () => {
192
193
  retries: DEFAULT_RETRIES_RPC_METHODS,
193
194
  }
194
195
 
195
- try {
196
- await withApi(evmConfig, currencyId, spy, nodeConfig)
197
- fail('Promise should have been rejected')
198
- } catch (e) {
199
- if (e instanceof AssertionError) {
200
- throw e
201
- }
202
- expect(e).toBeInstanceOf(SpyError)
203
- }
196
+ await expect(withApi(evmConfig, currencyId, spy, nodeConfig)).rejects.toThrow(SpyError)
204
197
  })
205
198
 
206
199
  it('provider cache should reuse the same JsonRpcProvider for the same currency id and same uri', async () => {
@@ -695,14 +688,12 @@ describe('EVM Family', () => {
695
688
 
696
689
  describe('getGasEstimation', () => {
697
690
  it('should return the expected payload', async () => {
698
- jest
699
- .spyOn(JsonRpcProvider.prototype as any, '_perform')
700
- .mockImplementation(async (req: any) => {
701
- if (req.method === 'estimateGas') {
702
- return 5n
703
- }
704
- return null
705
- })
691
+ jest.spyOn(JsonRpcProvider.prototype, '_perform').mockImplementation(async (req: any) => {
692
+ if (req.method === 'estimateGas') {
693
+ return 5n
694
+ }
695
+ return null
696
+ })
706
697
  expect(
707
698
  await nodeApi.getGasEstimation(currencyId, address, {
708
699
  recipient: '0x0000000000000000000000000000000000000000',
@@ -713,14 +704,12 @@ describe('EVM Family', () => {
713
704
  })
714
705
 
715
706
  it('should throw a GasEstimationError in case of error', async () => {
716
- jest
717
- .spyOn(JsonRpcProvider.prototype as any, '_perform')
718
- .mockImplementation(async (req: any) => {
719
- if (req.method === 'estimateGas') {
720
- throw new Error('fail')
721
- }
722
- return null
723
- })
707
+ jest.spyOn(JsonRpcProvider.prototype, '_perform').mockImplementation(async (req: any) => {
708
+ if (req.method === 'estimateGas') {
709
+ throw new Error('fail')
710
+ }
711
+ return null
712
+ })
724
713
 
725
714
  await expect(
726
715
  nodeApi.getGasEstimation(currencyId, address, {
@@ -957,7 +946,7 @@ describe('EVM Family', () => {
957
946
  },
958
947
  }))
959
948
  const sendSpy = jest
960
- .spyOn(JsonRpcProvider.prototype as any, 'send')
949
+ .spyOn(JsonRpcProvider.prototype, 'send')
961
950
  .mockImplementation(async (method) => {
962
951
  if (method === 'eth_getBlockByNumber') {
963
952
  return {
@@ -1067,28 +1056,24 @@ describe('EVM Family', () => {
1067
1056
  },
1068
1057
  }))
1069
1058
 
1070
- jest
1071
- .spyOn(JsonRpcProvider.prototype as any, 'send')
1072
- .mockImplementationOnce(async (method) => {
1073
- if (method === 'eth_getBlockByNumber') {
1074
- return {
1075
- parentHash: '0x0',
1076
- number: 1,
1077
- timestamp: 123,
1078
- difficulty: 0n,
1079
- gasLimit: 1n,
1080
- gasUsed: 2n,
1081
- extraData: '0x',
1082
- }
1059
+ jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
1060
+ if (method === 'eth_getBlockByNumber') {
1061
+ return {
1062
+ parentHash: '0x0',
1063
+ number: 1,
1064
+ timestamp: 123,
1065
+ difficulty: 0n,
1066
+ gasLimit: 1n,
1067
+ gasUsed: 2n,
1068
+ extraData: '0x',
1083
1069
  }
1084
- })
1070
+ }
1071
+ })
1085
1072
  // node reports 1 Gwei via the getFeeData mock at the top of the suite (666 wei), but
1086
1073
  // we override here to assert the floor wins
1087
- jest.spyOn(JsonRpcProvider.prototype, 'getFeeData').mockResolvedValueOnce({
1088
- gasPrice: BigInt('1000000000'), // 1 Gwei
1089
- maxFeePerGas: 0n,
1090
- maxPriorityFeePerGas: 0n,
1091
- } as ethers.FeeData)
1074
+ jest.spyOn(JsonRpcProvider.prototype, 'getFeeData').mockResolvedValueOnce(
1075
+ new FeeData(BigInt('1000000000'), 0n, 0n) // 1 Gwei
1076
+ )
1092
1077
 
1093
1078
  const result = await nodeApi.getFeeData(getCoinConfig(currencyId).info, currencyId, legacyTx)
1094
1079
 
@@ -1135,24 +1120,22 @@ describe('EVM Family', () => {
1135
1120
  }
1136
1121
 
1137
1122
  it('should return the expected payload for a legacy tx', async () => {
1138
- jest
1139
- .spyOn(JsonRpcProvider.prototype as any, 'send')
1140
- .mockImplementationOnce(async (method) => {
1141
- switch (method) {
1142
- case 'eth_getBlockByNumber':
1143
- return {
1144
- parentHash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1145
- number: 1,
1146
- timestamp: 123,
1147
- difficulty: 0n,
1148
- gasLimit: 1n,
1149
- gasUsed: 2n,
1150
- extraData: '0x',
1151
- }
1152
- default:
1153
- throw new Error(`Method not mocked: ${method}`)
1154
- }
1155
- })
1123
+ jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
1124
+ switch (method) {
1125
+ case 'eth_getBlockByNumber':
1126
+ return {
1127
+ parentHash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1128
+ number: 1,
1129
+ timestamp: 123,
1130
+ difficulty: 0n,
1131
+ gasLimit: 1n,
1132
+ gasUsed: 2n,
1133
+ extraData: '0x',
1134
+ }
1135
+ default:
1136
+ throw new Error(`Method not mocked: ${method}`)
1137
+ }
1138
+ })
1156
1139
 
1157
1140
  expect(
1158
1141
  await nodeApi.getFeeData(getCoinConfig('optimism').info, 'optimism', legacyTx)
@@ -1178,30 +1161,18 @@ describe('EVM Family', () => {
1178
1161
  const serializedTransaction =
1179
1162
  '0x02f873012d85010c388d0085077715912682520894c2907efcce4011c491bbeda8a0fa63ba7aab596c87038d7ea4c6800080c001a0bbffe7ba303ab03f697d64672c4a288ae863df8a62ffc67ba72872ce8c227f6fa01261e7c9f06af13631f03fad9b88d3c48931d353b6b41b4072fddcca5ec41628'
1180
1163
 
1181
- try {
1182
- await nodeApi.broadcastTransaction(currencyId, serializedTransaction)
1183
- fail('Promise should have been rejected')
1184
- } catch (e) {
1185
- if (e instanceof AssertionError) {
1186
- throw e
1187
- }
1188
- expect(e).toBeInstanceOf(InsufficientFunds)
1189
- }
1164
+ await expect(nodeApi.broadcastTransaction(currencyId, serializedTransaction)).rejects.toThrow(
1165
+ InsufficientFunds
1166
+ )
1190
1167
  })
1191
1168
 
1192
1169
  it('should throw any other error', async () => {
1193
1170
  const serializedTransaction =
1194
1171
  '0x02f873012d85010c388d0085077715912682520894c2907efcce4011c491bbeda8a0fa63ba7aab596c87038d7ea4c6800080c001a0bbffe7ba303ab03f697d64672c4a288ae863df8a62ffc67ba72872ce8c227f6fa01261e7c9f06af13631f03fad9b88d3c48931d353b6b41b4072fddcca5ec41625'
1195
1172
 
1196
- try {
1197
- await nodeApi.broadcastTransaction(currencyId, serializedTransaction)
1198
- fail('Promise should have been rejected')
1199
- } catch (e) {
1200
- if (e instanceof AssertionError) {
1201
- throw e
1202
- }
1203
- expect((e as Error).message).toEqual('any error')
1204
- }
1173
+ await expect(nodeApi.broadcastTransaction(currencyId, serializedTransaction)).rejects.toThrow(
1174
+ 'any error'
1175
+ )
1205
1176
  })
1206
1177
  })
1207
1178
 
@@ -1219,22 +1190,24 @@ describe('EVM Family', () => {
1219
1190
  })
1220
1191
 
1221
1192
  it('should prefetch block transactions when requested', async () => {
1222
- jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce({
1223
- hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1224
- parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
1225
- number: 1,
1226
- timestamp: now,
1227
- transactions: ['0xtx1'],
1228
- prefetchedTransactions: [
1229
- {
1230
- hash: '0xtx1',
1231
- value: 1n,
1232
- from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
1233
- to: '0xc2907efcce4011c491bbeda8a0fa63ba7aab596c',
1234
- gasPrice: '0',
1235
- },
1236
- ],
1237
- } as any)
1193
+ jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce(
1194
+ mkBlock({
1195
+ hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1196
+ parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
1197
+ number: 1,
1198
+ timestamp: now,
1199
+ transactions: ['0xtx1'],
1200
+ prefetchedTransactions: [
1201
+ mkTransactionResponse({
1202
+ hash: '0xtx1',
1203
+ value: 1n,
1204
+ from: '0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d',
1205
+ to: '0xc2907efcce4011c491bbeda8a0fa63ba7aab596c',
1206
+ gasPrice: 0n,
1207
+ }),
1208
+ ],
1209
+ })
1210
+ )
1238
1211
 
1239
1212
  expect(await nodeApi.getBlockByHeight(currencyId, 1, true)).toEqual({
1240
1213
  hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
@@ -1255,18 +1228,23 @@ describe('EVM Family', () => {
1255
1228
  })
1256
1229
 
1257
1230
  it('should fallback to transaction hashes when prefetched transactions are unavailable', async () => {
1258
- jest.spyOn(JsonRpcProvider.prototype, 'getBlock').mockResolvedValueOnce({
1231
+ const blockWithThrowingGetter = mkBlock({
1259
1232
  hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
1260
1233
  parentHash: '0xfc900c22725f9c0843c9cf7d2c47f4b61b246bd21e18e99f709aebaefc8aff14',
1261
1234
  number: 1,
1262
1235
  timestamp: now,
1263
1236
  transactions: ['0xtx1'],
1264
- get prefetchedTransactions() {
1237
+ })
1238
+ Object.defineProperty(blockWithThrowingGetter, 'prefetchedTransactions', {
1239
+ get() {
1265
1240
  const error = new Error('transactions were not prefetched with block request')
1266
- ;(error as Error & { code?: string }).code = 'UNSUPPORTED_OPERATION'
1241
+ Object.assign(error, { code: 'UNSUPPORTED_OPERATION' })
1267
1242
  throw error
1268
1243
  },
1269
- } as any)
1244
+ })
1245
+ jest
1246
+ .spyOn(JsonRpcProvider.prototype, 'getBlock')
1247
+ .mockResolvedValueOnce(blockWithThrowingGetter)
1270
1248
 
1271
1249
  expect(await nodeApi.getBlockByHeight(currencyId, 1, true)).toEqual({
1272
1250
  hash: '0x474dee0136108e9412e9d84197b468bb057a8dad0f2024fc55adebc4a28fa8c5',
@@ -1478,7 +1456,7 @@ describe('EVM Family', () => {
1478
1456
  (e: unknown) => e
1479
1457
  )
1480
1458
  expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
1481
- expect((err as { method?: string }).method).toBe('trace_block')
1459
+ expect(err).toMatchObject({ method: 'trace_block' })
1482
1460
  }
1483
1461
  )
1484
1462
  })
@@ -1548,7 +1526,7 @@ describe('EVM Family', () => {
1548
1526
  (e: unknown) => e
1549
1527
  )
1550
1528
  expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
1551
- expect((err as { method?: string }).method).toBe('debug_traceBlockByNumber')
1529
+ expect(err).toMatchObject({ method: 'debug_traceBlockByNumber' })
1552
1530
  }
1553
1531
  )
1554
1532
 
@@ -1568,7 +1546,7 @@ describe('EVM Family', () => {
1568
1546
  (e: unknown) => e
1569
1547
  )
1570
1548
  expect(err).toBeInstanceOf(UnsupportedRpcMethodError)
1571
- expect((err as { method?: string }).method).toBe('debug_traceBlockByNumber')
1549
+ expect(err).toMatchObject({ method: 'debug_traceBlockByNumber' })
1572
1550
  })
1573
1551
  })
1574
1552
 
@@ -1747,16 +1725,13 @@ describe('EVM Family', () => {
1747
1725
  const NORMALIZED_RECIPIENT = '0xc2907efcce4011c491bbeda8a0fa63ba7aab596c'
1748
1726
 
1749
1727
  let capturedTransaction: { from?: string; to?: string } | undefined
1750
- jest
1751
- .spyOn(JsonRpcProvider.prototype as any, '_perform')
1752
- .mockImplementation(async (arg: unknown) => {
1753
- const req = arg as { method: string; transaction?: typeof capturedTransaction }
1754
- if (req.method === 'estimateGas') {
1755
- capturedTransaction = req.transaction
1756
- return 21000n
1757
- }
1758
- return null
1759
- })
1728
+ jest.spyOn(JsonRpcProvider.prototype, '_perform').mockImplementation(async (arg) => {
1729
+ if (arg.method === 'estimateGas') {
1730
+ capturedTransaction = arg.transaction
1731
+ return 21000n
1732
+ }
1733
+ return null
1734
+ })
1760
1735
 
1761
1736
  await nodeApi.getGasEstimation(currencyId, address, {
1762
1737
  recipient: EIP1191_RECIPIENT,
@@ -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