@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.
Files changed (255) hide show
  1. package/.oxlintrc.json +3 -13
  2. package/CHANGELOG.md +13 -0
  3. package/lib/adapters/blockOperations.d.ts +2 -2
  4. package/lib/adapters/blockOperations.d.ts.map +1 -1
  5. package/lib/adapters/blockOperations.js.map +1 -1
  6. package/lib/api/index.d.ts +1 -1
  7. package/lib/api/index.d.ts.map +1 -1
  8. package/lib/config.d.ts +1 -1
  9. package/lib/config.d.ts.map +1 -1
  10. package/lib/logic/combine.d.ts +2 -1
  11. package/lib/logic/combine.d.ts.map +1 -1
  12. package/lib/logic/combine.js.map +1 -1
  13. package/lib/logic/common.d.ts +2 -1
  14. package/lib/logic/common.d.ts.map +1 -1
  15. package/lib/logic/common.js.map +1 -1
  16. package/lib/logic/craftTransaction.d.ts +1 -1
  17. package/lib/logic/craftTransaction.d.ts.map +1 -1
  18. package/lib/logic/craftTransaction.js.map +1 -1
  19. package/lib/logic/craftTransactionData.d.ts +1 -1
  20. package/lib/logic/craftTransactionData.d.ts.map +1 -1
  21. package/lib/logic/estimateFees.d.ts +1 -1
  22. package/lib/logic/estimateFees.d.ts.map +1 -1
  23. package/lib/logic/estimateFees.js.map +1 -1
  24. package/lib/logic/getBalance.d.ts +1 -1
  25. package/lib/logic/getBalance.d.ts.map +1 -1
  26. package/lib/logic/getBalance.js.map +1 -1
  27. package/lib/logic/getBlock.d.ts +1 -1
  28. package/lib/logic/getBlock.d.ts.map +1 -1
  29. package/lib/logic/getBlock.js.map +1 -1
  30. package/lib/logic/getStakes.d.ts +1 -1
  31. package/lib/logic/getStakes.d.ts.map +1 -1
  32. package/lib/logic/internalTransactionsFetcher.d.ts +1 -1
  33. package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
  34. package/lib/logic/internalTransactionsFetcher.js.map +1 -1
  35. package/lib/logic/validateIntent.d.ts +1 -1
  36. package/lib/logic/validateIntent.d.ts.map +1 -1
  37. package/lib/logic/validateIntent.js.map +1 -1
  38. package/lib/logic.d.ts +1 -1
  39. package/lib/logic.d.ts.map +1 -1
  40. package/lib/network/explorer/etherscan.d.ts +4 -4
  41. package/lib/network/explorer/etherscan.d.ts.map +1 -1
  42. package/lib/network/explorer/etherscan.js.map +1 -1
  43. package/lib/network/explorer/index.d.ts +2 -2
  44. package/lib/network/explorer/index.d.ts.map +1 -1
  45. package/lib/network/explorer/index.js.map +1 -1
  46. package/lib/network/explorer/ledger.d.ts +2 -2
  47. package/lib/network/explorer/ledger.d.ts.map +1 -1
  48. package/lib/network/explorer/ledger.js.map +1 -1
  49. package/lib/network/explorer/none.d.ts +1 -1
  50. package/lib/network/explorer/none.d.ts.map +1 -1
  51. package/lib/network/explorer/none.js.map +1 -1
  52. package/lib/network/explorer/types.d.ts +1 -1
  53. package/lib/network/explorer/types.d.ts.map +1 -1
  54. package/lib/network/gasTracker/index.d.ts +2 -2
  55. package/lib/network/gasTracker/index.d.ts.map +1 -1
  56. package/lib/network/gasTracker/index.js.map +1 -1
  57. package/lib/network/gasTracker/ledger.d.ts +3 -3
  58. package/lib/network/gasTracker/ledger.d.ts.map +1 -1
  59. package/lib/network/gasTracker/ledger.js.map +1 -1
  60. package/lib/network/gasTracker/types.d.ts +2 -2
  61. package/lib/network/gasTracker/types.d.ts.map +1 -1
  62. package/lib/network/node/ledger.d.ts +2 -2
  63. package/lib/network/node/ledger.d.ts.map +1 -1
  64. package/lib/network/node/ledger.js.map +1 -1
  65. package/lib/network/node/rpc.common.d.ts +1 -1
  66. package/lib/network/node/rpc.common.d.ts.map +1 -1
  67. package/lib/network/node/rpc.common.js.map +1 -1
  68. package/lib/network/node/types.d.ts +3 -3
  69. package/lib/network/node/types.d.ts.map +1 -1
  70. package/lib/staking/validators/monad.d.ts +2 -1
  71. package/lib/staking/validators/monad.d.ts.map +1 -1
  72. package/lib/staking/validators/monad.js.map +1 -1
  73. package/lib/staking/validators/monadResolver.d.ts +2 -1
  74. package/lib/staking/validators/monadResolver.d.ts.map +1 -1
  75. package/lib/staking/validators/monadResolver.js.map +1 -1
  76. package/lib/staking/validators/somnia.d.ts.map +1 -1
  77. package/lib/staking/validators/somnia.js.map +1 -1
  78. package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
  79. package/lib/staking/validators/zero_gravity.js.map +1 -1
  80. package/lib/types/assets.d.ts +1 -1
  81. package/lib/types/assets.d.ts.map +1 -1
  82. package/lib/types/transaction.d.ts +1 -1
  83. package/lib/types/transaction.d.ts.map +1 -1
  84. package/lib-es/adapters/blockOperations.d.ts +2 -2
  85. package/lib-es/adapters/blockOperations.d.ts.map +1 -1
  86. package/lib-es/adapters/blockOperations.js.map +1 -1
  87. package/lib-es/api/index.d.ts +1 -1
  88. package/lib-es/api/index.d.ts.map +1 -1
  89. package/lib-es/config.d.ts +1 -1
  90. package/lib-es/config.d.ts.map +1 -1
  91. package/lib-es/logic/combine.d.ts +2 -1
  92. package/lib-es/logic/combine.d.ts.map +1 -1
  93. package/lib-es/logic/combine.js.map +1 -1
  94. package/lib-es/logic/common.d.ts +2 -1
  95. package/lib-es/logic/common.d.ts.map +1 -1
  96. package/lib-es/logic/common.js +1 -1
  97. package/lib-es/logic/common.js.map +1 -1
  98. package/lib-es/logic/craftTransaction.d.ts +1 -1
  99. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  100. package/lib-es/logic/craftTransaction.js.map +1 -1
  101. package/lib-es/logic/craftTransactionData.d.ts +1 -1
  102. package/lib-es/logic/craftTransactionData.d.ts.map +1 -1
  103. package/lib-es/logic/estimateFees.d.ts +1 -1
  104. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  105. package/lib-es/logic/estimateFees.js.map +1 -1
  106. package/lib-es/logic/getBalance.d.ts +1 -1
  107. package/lib-es/logic/getBalance.d.ts.map +1 -1
  108. package/lib-es/logic/getBalance.js.map +1 -1
  109. package/lib-es/logic/getBlock.d.ts +1 -1
  110. package/lib-es/logic/getBlock.d.ts.map +1 -1
  111. package/lib-es/logic/getBlock.js.map +1 -1
  112. package/lib-es/logic/getStakes.d.ts +1 -1
  113. package/lib-es/logic/getStakes.d.ts.map +1 -1
  114. package/lib-es/logic/internalTransactionsFetcher.d.ts +1 -1
  115. package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
  116. package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
  117. package/lib-es/logic/validateIntent.d.ts +1 -1
  118. package/lib-es/logic/validateIntent.d.ts.map +1 -1
  119. package/lib-es/logic/validateIntent.js.map +1 -1
  120. package/lib-es/logic.d.ts +1 -1
  121. package/lib-es/logic.d.ts.map +1 -1
  122. package/lib-es/network/explorer/etherscan.d.ts +4 -4
  123. package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
  124. package/lib-es/network/explorer/etherscan.js.map +1 -1
  125. package/lib-es/network/explorer/index.d.ts +2 -2
  126. package/lib-es/network/explorer/index.d.ts.map +1 -1
  127. package/lib-es/network/explorer/index.js.map +1 -1
  128. package/lib-es/network/explorer/ledger.d.ts +2 -2
  129. package/lib-es/network/explorer/ledger.d.ts.map +1 -1
  130. package/lib-es/network/explorer/ledger.js.map +1 -1
  131. package/lib-es/network/explorer/none.d.ts +1 -1
  132. package/lib-es/network/explorer/none.d.ts.map +1 -1
  133. package/lib-es/network/explorer/none.js.map +1 -1
  134. package/lib-es/network/explorer/types.d.ts +1 -1
  135. package/lib-es/network/explorer/types.d.ts.map +1 -1
  136. package/lib-es/network/gasTracker/index.d.ts +2 -2
  137. package/lib-es/network/gasTracker/index.d.ts.map +1 -1
  138. package/lib-es/network/gasTracker/index.js.map +1 -1
  139. package/lib-es/network/gasTracker/ledger.d.ts +3 -3
  140. package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
  141. package/lib-es/network/gasTracker/ledger.js +1 -1
  142. package/lib-es/network/gasTracker/ledger.js.map +1 -1
  143. package/lib-es/network/gasTracker/types.d.ts +2 -2
  144. package/lib-es/network/gasTracker/types.d.ts.map +1 -1
  145. package/lib-es/network/node/ledger.d.ts +2 -2
  146. package/lib-es/network/node/ledger.d.ts.map +1 -1
  147. package/lib-es/network/node/ledger.js.map +1 -1
  148. package/lib-es/network/node/rpc.common.d.ts +1 -1
  149. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  150. package/lib-es/network/node/rpc.common.js +1 -1
  151. package/lib-es/network/node/rpc.common.js.map +1 -1
  152. package/lib-es/network/node/types.d.ts +3 -3
  153. package/lib-es/network/node/types.d.ts.map +1 -1
  154. package/lib-es/staking/validators/monad.d.ts +2 -1
  155. package/lib-es/staking/validators/monad.d.ts.map +1 -1
  156. package/lib-es/staking/validators/monad.js.map +1 -1
  157. package/lib-es/staking/validators/monadResolver.d.ts +2 -1
  158. package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
  159. package/lib-es/staking/validators/monadResolver.js.map +1 -1
  160. package/lib-es/staking/validators/somnia.d.ts.map +1 -1
  161. package/lib-es/staking/validators/somnia.js.map +1 -1
  162. package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
  163. package/lib-es/staking/validators/zero_gravity.js.map +1 -1
  164. package/lib-es/types/assets.d.ts +1 -1
  165. package/lib-es/types/assets.d.ts.map +1 -1
  166. package/lib-es/types/transaction.d.ts +1 -1
  167. package/lib-es/types/transaction.d.ts.map +1 -1
  168. package/package.json +2 -2
  169. package/src/adapters/blockOperations.test.ts +29 -31
  170. package/src/adapters/blockOperations.ts +3 -2
  171. package/src/adapters/etherscan.test.ts +7 -7
  172. package/src/adapters/ledger.test.ts +2 -2
  173. package/src/api/getBlock.integ.test.ts +1 -1
  174. package/src/api/index.fantom.integ.test.ts +1 -1
  175. package/src/api/index.flare.integ.test.ts +2 -14
  176. package/src/api/index.integ.test.ts +330 -246
  177. package/src/api/index.linea.integ.test.ts +1 -1
  178. package/src/api/index.optimism.integ.test.ts +1 -1
  179. package/src/api/index.shape.integ.test.ts +1 -1
  180. package/src/api/index.ts +1 -1
  181. package/src/config.ts +1 -1
  182. package/src/fixtures/context.fixtures.ts +79 -1
  183. package/src/fixtures/ethers.fixtures.ts +26 -0
  184. package/src/fixtures/ledger.fixtures.ts +1 -1
  185. package/src/internalTxSources.test.ts +3 -6
  186. package/src/logic/broadcast.integ.test.ts +6 -18
  187. package/src/logic/broadcast.test.ts +19 -31
  188. package/src/logic/broadcastSource.test.ts +6 -7
  189. package/src/logic/combine.test.ts +2 -2
  190. package/src/logic/combine.ts +2 -1
  191. package/src/logic/common.test.ts +120 -112
  192. package/src/logic/common.ts +2 -7
  193. package/src/logic/craftTransaction.test.ts +163 -200
  194. package/src/logic/craftTransaction.ts +3 -2
  195. package/src/logic/craftTransactionData.test.ts +6 -6
  196. package/src/logic/craftTransactionData.ts +1 -1
  197. package/src/logic/estimateFees.test.ts +19 -15
  198. package/src/logic/estimateFees.ts +6 -3
  199. package/src/logic/getBalance.test.ts +16 -15
  200. package/src/logic/getBalance.ts +4 -3
  201. package/src/logic/getBlock.test.ts +379 -388
  202. package/src/logic/getBlock.ts +3 -2
  203. package/src/logic/getBlockInfo.test.ts +7 -9
  204. package/src/logic/getNextSequence.test.ts +5 -5
  205. package/src/logic/getStakes.test.ts +35 -35
  206. package/src/logic/getStakes.ts +1 -1
  207. package/src/logic/internalTransactionsFetcher.test.ts +26 -24
  208. package/src/logic/internalTransactionsFetcher.ts +1 -1
  209. package/src/logic/lastBlock.test.ts +29 -20
  210. package/src/logic/listOperations.test.ts +44 -40
  211. package/src/logic/validateIntent.test.ts +152 -101
  212. package/src/logic/validateIntent.ts +4 -2
  213. package/src/logic.test.ts +13 -18
  214. package/src/logic.ts +1 -1
  215. package/src/network/explorer/etherscan.test.ts +6 -6
  216. package/src/network/explorer/etherscan.ts +12 -10
  217. package/src/network/explorer/index.test.ts +52 -22
  218. package/src/network/explorer/index.ts +2 -2
  219. package/src/network/explorer/ledger.test.ts +17 -5
  220. package/src/network/explorer/ledger.ts +3 -2
  221. package/src/network/explorer/none.ts +2 -1
  222. package/src/network/explorer/types.ts +1 -1
  223. package/src/network/gasTracker/index.test.ts +14 -8
  224. package/src/network/gasTracker/index.ts +2 -2
  225. package/src/network/gasTracker/ledger.test.ts +34 -29
  226. package/src/network/gasTracker/ledger.ts +5 -7
  227. package/src/network/gasTracker/types.ts +2 -2
  228. package/src/network/node/index.memoization.test.ts +25 -31
  229. package/src/network/node/index.test.ts +14 -25
  230. package/src/network/node/ledger.test.ts +45 -60
  231. package/src/network/node/ledger.ts +6 -5
  232. package/src/network/node/node.fixtures.ts +0 -2
  233. package/src/network/node/rpc.common.ts +14 -14
  234. package/src/network/node/rpc.test.ts +153 -184
  235. package/src/network/node/types.ts +3 -3
  236. package/src/staking/detectOperationType.test.ts +1 -1
  237. package/src/staking/encoder.test.ts +14 -22
  238. package/src/staking/logic.test.ts +20 -14
  239. package/src/staking/operations/index.test.ts +29 -29
  240. package/src/staking/prepareIntents.test.ts +26 -20
  241. package/src/staking/redelegations.test.ts +50 -33
  242. package/src/staking/rewards.test.ts +29 -17
  243. package/src/staking/rewardsFromReceipt.test.ts +20 -21
  244. package/src/staking/transactionData.test.ts +23 -23
  245. package/src/staking/validators/monad.test.ts +65 -24
  246. package/src/staking/validators/monad.ts +2 -1
  247. package/src/staking/validators/monadResolver.ts +2 -1
  248. package/src/staking/validators/somnia.test.ts +21 -13
  249. package/src/staking/validators/somnia.ts +2 -1
  250. package/src/staking/validators/zero_gravity.test.ts +118 -48
  251. package/src/staking/validators/zero_gravity.ts +2 -1
  252. package/src/staking/validators.integ.test.ts +13 -25
  253. package/src/staking/validators.test.ts +7 -2
  254. package/src/types/assets.ts +1 -1
  255. package/src/types/transaction.ts +1 -1
@@ -2,14 +2,14 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { EvmConfigInfo } from '../config'
5
+ import type { BufferTxData, MemoNotSupported } from '@ledgerhq/coin-module-framework/api/types'
5
6
  import {
6
- BufferTxData,
7
- MemoNotSupported,
8
- TransactionIntent,
9
- } from '@ledgerhq/coin-module-framework/api/types'
7
+ createSendTransactionIntentMockData,
8
+ createStakingTransactionIntentMockData,
9
+ } from '@ledgerhq/coin-module-framework/test-utils'
10
10
  import BigNumber from 'bignumber.js'
11
11
  import { ethers } from 'ethers'
12
- import { createMockEvmContext } from '../fixtures/context.fixtures'
12
+ import { createMockEvmContext, mkExternalNode, mkLedgerNode } from '../fixtures/context.fixtures'
13
13
  import { getNodeApi } from '../network/node'
14
14
  import { mockNodeApi } from '../network/node/node.fixtures'
15
15
  import { craftTransaction } from './craftTransaction'
@@ -21,6 +21,9 @@ jest.mock('../network/node', () => ({
21
21
 
22
22
  const mockGetNodeApi = jest.mocked(getNodeApi)
23
23
 
24
+ const nodeFor = (type: 'external' | 'ledger') =>
25
+ type === 'external' ? mkExternalNode() : mkLedgerNode()
26
+
24
27
  describe('craftTransaction', () => {
25
28
  const externalMocks = mockNodeApi()
26
29
  const ledgerMocks = mockNodeApi()
@@ -34,21 +37,21 @@ describe('craftTransaction', () => {
34
37
  it('fails to craft an unknown intent type', async () => {
35
38
  await expect(
36
39
  craftTransaction(createMockEvmContext(), 'ethereum', {
40
+ // @ts-ignore — intentionally invalid intent type to test the unsupported-type error path
37
41
  transactionIntent: { type: 'any' },
38
- } as any)
42
+ })
39
43
  ).rejects.toThrow(
40
44
  "Unsupported intent type 'any'. Must be 'send-legacy', 'send-eip1559', 'staking-legacy', or 'staking-eip1559'"
41
45
  )
42
46
  })
43
47
 
44
48
  describe('zero gas limit', () => {
45
- const intent = {
46
- intentType: 'transaction',
49
+ const intent = createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
47
50
  type: 'send-legacy',
48
51
  recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
49
52
  amount: 10n,
50
53
  asset: { type: 'native' },
51
- } as TransactionIntent<MemoNotSupported, BufferTxData>
54
+ })
52
55
 
53
56
  beforeEach(() => {
54
57
  externalMocks.getTransactionCount.mockResolvedValue(18)
@@ -64,7 +67,7 @@ describe('craftTransaction', () => {
64
67
  externalMocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
65
68
 
66
69
  const { transaction } = await craftTransaction(
67
- createMockEvmContext({ node: { type: 'external' }, chainId: 42 } as Partial<EvmConfigInfo>),
70
+ createMockEvmContext({ node: mkExternalNode(), chainId: 42 }),
68
71
  'ethereum',
69
72
  {
70
73
  transactionIntent: intent,
@@ -81,10 +84,7 @@ describe('craftTransaction', () => {
81
84
 
82
85
  await expect(
83
86
  craftTransaction(
84
- createMockEvmContext({
85
- node: { type: 'external' },
86
- chainId: 42,
87
- } as Partial<EvmConfigInfo>),
87
+ createMockEvmContext({ node: mkExternalNode(), chainId: 42 }),
88
88
  'ethereum',
89
89
  {
90
90
  transactionIntent: intent,
@@ -121,131 +121,67 @@ describe('craftTransaction', () => {
121
121
  maxPriorityFeePerGas: 4,
122
122
  },
123
123
  ],
124
- ])('%s transaction type', (transactionType, transactionTypeNumber, feeData, expectedFee) => {
125
- it.each([
126
- ['an external node', 'external', externalMocks],
127
- ['a ledger node', 'ledger', ledgerMocks],
128
- ] as const)('crafts a transaction with the native asset using %s', async (_, type, mocks) => {
129
- const context = createMockEvmContext({
130
- node: { type },
131
- chainId: 42,
132
- } as Partial<EvmConfigInfo>)
133
- mocks.getTransactionCount.mockResolvedValue(18)
134
- mocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
135
- mocks.getFeeData.mockResolvedValue(feeData)
136
-
137
- const { transaction } = await craftTransaction(context, 'ethereum', {
138
- transactionIntent: {
139
- intentType: 'transaction',
140
- type: `send-${transactionType}`,
141
- recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
142
- amount: 10n,
143
- asset: { type: 'native' },
144
- } as TransactionIntent<MemoNotSupported, BufferTxData>,
145
- customFees: {
146
- value: 0n,
147
- parameters: {
148
- gasPrice: 8n,
149
- },
150
- },
151
- })
152
-
153
- expect(transaction).toEqual(
154
- ethers.Transaction.from({
155
- type: transactionTypeNumber,
156
- to: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
157
- nonce: 18,
158
- gasLimit: 2300,
159
- data: '0x',
160
- value: 10,
161
- chainId: 42,
162
- ...expectedFee,
163
- }).unsignedSerialized
164
- )
165
- })
124
+ ] as const)(
125
+ '%s transaction type',
126
+ (transactionType, transactionTypeNumber, feeData, expectedFee) => {
127
+ it.each([
128
+ ['an external node', 'external', externalMocks],
129
+ ['a ledger node', 'ledger', ledgerMocks],
130
+ ] as const)('crafts a transaction with the native asset using %s', async (_, type, mocks) => {
131
+ const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
132
+ mocks.getTransactionCount.mockResolvedValue(18)
133
+ mocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
134
+ mocks.getFeeData.mockResolvedValue(feeData)
166
135
 
167
- it.each([
168
- ['an external node', 'external', externalMocks],
169
- ['a ledger node', 'ledger', ledgerMocks],
170
- ] as const)('crafts a transaction with a token asset using %s', async (_, type, mocks) => {
171
- const context = createMockEvmContext({
172
- node: { type },
173
- chainId: 42,
174
- } as Partial<EvmConfigInfo>)
175
- mocks.getTransactionCount.mockResolvedValue(18)
176
- mocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
177
- mocks.getFeeData.mockResolvedValue(feeData)
178
-
179
- const { transaction } = await craftTransaction(context, 'ethereum', {
180
- transactionIntent: {
181
- intentType: 'transaction',
182
- type: `send-${transactionType}`,
183
- recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
184
- amount: 10n,
185
- asset: { type: 'erc20', assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' },
186
- } as TransactionIntent<MemoNotSupported, BufferTxData>,
187
- customFees: {
188
- value: 0n,
189
- parameters: {
190
- gasPrice: 8n,
136
+ const { transaction } = await craftTransaction(context, 'ethereum', {
137
+ transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
138
+ type: `send-${transactionType}`,
139
+ recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
140
+ amount: 10n,
141
+ asset: { type: 'native' },
142
+ }),
143
+ customFees: {
144
+ value: 0n,
145
+ parameters: {
146
+ gasPrice: 8n,
147
+ },
191
148
  },
192
- },
193
- })
149
+ })
194
150
 
195
- expect(transaction).toEqual(
196
- ethers.Transaction.from({
197
- type: transactionTypeNumber,
198
- to: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
199
- nonce: 18,
200
- gasLimit: 2300,
201
- data:
202
- '0x' +
203
- Buffer.concat([
204
- Buffer.from('a9059cbb000000000000000000000000', 'hex'), // transfer selector
205
- Buffer.from('7b2c7232f9e38f30e2868f0e5bf311cd83554b5a', 'hex'), // recipient
206
- Buffer.from(
207
- '000000000000000000000000000000000000000000000000000000000000000a',
208
- 'hex'
209
- ), // amount
210
- ]).toString('hex'),
211
- value: 0,
212
- chainId: 42,
213
- ...expectedFee,
214
- }).unsignedSerialized
215
- )
216
- })
151
+ expect(transaction).toEqual(
152
+ ethers.Transaction.from({
153
+ type: transactionTypeNumber,
154
+ to: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
155
+ nonce: 18,
156
+ gasLimit: 2300,
157
+ data: '0x',
158
+ value: 10,
159
+ chainId: 42,
160
+ ...expectedFee,
161
+ }).unsignedSerialized
162
+ )
163
+ })
217
164
 
218
- it.each([
219
- ['an external node', 'external', externalMocks],
220
- ['a ledger node', 'ledger', ledgerMocks],
221
- ] as const)(
222
- 'crafts a transaction without %s when custom fees are passed',
223
- async (_, type, mocks) => {
224
- const context = createMockEvmContext({
225
- node: { type },
226
- chainId: 42,
227
- } as Partial<EvmConfigInfo>)
165
+ it.each([
166
+ ['an external node', 'external', externalMocks],
167
+ ['a ledger node', 'ledger', ledgerMocks],
168
+ ] as const)('crafts a transaction with a token asset using %s', async (_, type, mocks) => {
169
+ const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
228
170
  mocks.getTransactionCount.mockResolvedValue(18)
171
+ mocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
172
+ mocks.getFeeData.mockResolvedValue(feeData)
229
173
 
230
174
  const { transaction } = await craftTransaction(context, 'ethereum', {
231
- transactionIntent: {
232
- intentType: 'transaction',
175
+ transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
233
176
  type: `send-${transactionType}`,
234
177
  recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
235
178
  amount: 10n,
236
- asset: {
237
- type: 'erc20',
238
- assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
239
- },
240
- } as TransactionIntent<MemoNotSupported, BufferTxData>,
179
+ asset: { type: 'erc20', assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' },
180
+ }),
241
181
  customFees: {
242
182
  value: 0n,
243
183
  parameters: {
244
- gasPrice: feeData.gasPrice && BigInt(feeData.gasPrice.toFixed()),
245
- maxFeePerGas: feeData.maxFeePerGas && BigInt(feeData.maxFeePerGas.toFixed()),
246
- maxPriorityFeePerGas:
247
- feeData.maxPriorityFeePerGas && BigInt(feeData.maxPriorityFeePerGas.toFixed()),
248
- gasLimit: 2300n,
184
+ gasPrice: 8n,
249
185
  },
250
186
  },
251
187
  })
@@ -271,17 +207,69 @@ describe('craftTransaction', () => {
271
207
  ...expectedFee,
272
208
  }).unsignedSerialized
273
209
  )
274
- expect(mocks.getGasEstimation).not.toHaveBeenCalled()
275
- expect(mocks.getFeeData).not.toHaveBeenCalled()
276
- }
277
- )
278
- })
210
+ })
211
+
212
+ it.each([
213
+ ['an external node', 'external', externalMocks],
214
+ ['a ledger node', 'ledger', ledgerMocks],
215
+ ] as const)(
216
+ 'crafts a transaction without %s when custom fees are passed',
217
+ async (_, type, mocks) => {
218
+ const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
219
+ mocks.getTransactionCount.mockResolvedValue(18)
220
+
221
+ const { transaction } = await craftTransaction(context, 'ethereum', {
222
+ transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
223
+ type: `send-${transactionType}`,
224
+ recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
225
+ amount: 10n,
226
+ asset: {
227
+ type: 'erc20',
228
+ assetReference: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
229
+ },
230
+ }),
231
+ customFees: {
232
+ value: 0n,
233
+ parameters: {
234
+ gasPrice: feeData.gasPrice && BigInt(feeData.gasPrice.toFixed()),
235
+ maxFeePerGas: feeData.maxFeePerGas && BigInt(feeData.maxFeePerGas.toFixed()),
236
+ maxPriorityFeePerGas:
237
+ feeData.maxPriorityFeePerGas && BigInt(feeData.maxPriorityFeePerGas.toFixed()),
238
+ gasLimit: 2300n,
239
+ },
240
+ },
241
+ })
242
+
243
+ expect(transaction).toEqual(
244
+ ethers.Transaction.from({
245
+ type: transactionTypeNumber,
246
+ to: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
247
+ nonce: 18,
248
+ gasLimit: 2300,
249
+ data:
250
+ '0x' +
251
+ Buffer.concat([
252
+ Buffer.from('a9059cbb000000000000000000000000', 'hex'), // transfer selector
253
+ Buffer.from('7b2c7232f9e38f30e2868f0e5bf311cd83554b5a', 'hex'), // recipient
254
+ Buffer.from(
255
+ '000000000000000000000000000000000000000000000000000000000000000a',
256
+ 'hex'
257
+ ), // amount
258
+ ]).toString('hex'),
259
+ value: 0,
260
+ chainId: 42,
261
+ ...expectedFee,
262
+ }).unsignedSerialized
263
+ )
264
+ expect(mocks.getGasEstimation).not.toHaveBeenCalled()
265
+ expect(mocks.getFeeData).not.toHaveBeenCalled()
266
+ }
267
+ )
268
+ }
269
+ )
279
270
 
280
271
  it('preserves passed calldata', async () => {
281
- const context = createMockEvmContext({
282
- node: { type: 'external' },
283
- chainId: 42,
284
- } as Partial<EvmConfigInfo>)
272
+ const context = createMockEvmContext({ node: mkExternalNode(), chainId: 42 })
285
273
  externalMocks.getTransactionCount.mockResolvedValue(18)
286
274
  externalMocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
287
275
  externalMocks.getFeeData.mockResolvedValue({
@@ -292,14 +280,13 @@ describe('craftTransaction', () => {
292
280
  })
293
281
 
294
282
  const { transaction } = await craftTransaction(context, 'ethereum', {
295
- transactionIntent: {
296
- intentType: 'transaction',
283
+ transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
297
284
  type: 'send-legacy',
298
285
  recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
299
286
  amount: 10n,
300
287
  data: { type: 'buffer', value: Buffer.from([0xca, 0xfe]) },
301
288
  asset: { type: 'native' },
302
- } as TransactionIntent<MemoNotSupported, BufferTxData>,
289
+ }),
303
290
  })
304
291
 
305
292
  expect(transaction).toEqual(
@@ -317,10 +304,7 @@ describe('craftTransaction', () => {
317
304
  })
318
305
 
319
306
  it('preserves passed sequence', async () => {
320
- const context = createMockEvmContext({
321
- node: { type: 'external' },
322
- chainId: 42,
323
- } as Partial<EvmConfigInfo>)
307
+ const context = createMockEvmContext({ node: mkExternalNode(), chainId: 42 })
324
308
  externalMocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
325
309
  externalMocks.getFeeData.mockResolvedValue({
326
310
  gasPrice: new BigNumber(5),
@@ -330,14 +314,13 @@ describe('craftTransaction', () => {
330
314
  })
331
315
 
332
316
  const { transaction } = await craftTransaction(context, 'ethereum', {
333
- transactionIntent: {
334
- intentType: 'transaction',
335
- sequence: 15n,
317
+ transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
336
318
  type: 'send-legacy',
319
+ sequence: 15n,
337
320
  recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
338
321
  amount: 10n,
339
322
  asset: { type: 'native' },
340
- } as TransactionIntent<MemoNotSupported, BufferTxData>,
323
+ }),
341
324
  })
342
325
 
343
326
  expect(transaction).toEqual(
@@ -384,7 +367,7 @@ describe('craftTransaction', () => {
384
367
  maxPriorityFeePerGas: 4,
385
368
  },
386
369
  ],
387
- ])(
370
+ ] as const)(
388
371
  'staking %s transaction type',
389
372
  (transactionType, transactionTypeNumber, feeData, _expectedFee) => {
390
373
  it.each([
@@ -393,25 +376,23 @@ describe('craftTransaction', () => {
393
376
  ] as const)(
394
377
  'crafts a SEI staking delegate transaction using %s',
395
378
  async (_, type, mocks) => {
396
- const context = createMockEvmContext({
397
- node: { type },
398
- chainId: 42,
399
- } as Partial<EvmConfigInfo>)
379
+ const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
400
380
  mocks.getTransactionCount.mockResolvedValue(25)
401
381
  mocks.getGasEstimation.mockResolvedValue(new BigNumber(45000))
402
382
  mocks.getFeeData.mockResolvedValue(feeData)
403
383
 
404
384
  const { transaction } = await craftTransaction(context, 'sei_evm', {
405
- transactionIntent: {
406
- intentType: 'staking',
385
+ transactionIntent: createStakingTransactionIntentMockData<
386
+ MemoNotSupported,
387
+ BufferTxData
388
+ >({
407
389
  type: `staking-${transactionType}`,
408
- sender: '0x1234567890abcdef1234567890abcdef12345678',
390
+ mode: 'delegate',
409
391
  recipient: '0x000000000000000000000000000000000001005',
410
392
  valAddress: 'seivaloper1234567890abcdef1234567890abcdef12345678',
411
- amount: 1000000000000000000n, // 1 SEI
393
+ amount: 1000000000000000000n,
412
394
  asset: { type: 'native' },
413
- mode: 'delegate',
414
- } as any,
395
+ }),
415
396
  })
416
397
 
417
398
  // Parse the returned transaction to verify its properties
@@ -434,25 +415,23 @@ describe('craftTransaction', () => {
434
415
  ] as const)(
435
416
  'crafts a SEI staking undelegate transaction using %s',
436
417
  async (_, type, mocks) => {
437
- const context = createMockEvmContext({
438
- node: { type },
439
- chainId: 42,
440
- } as Partial<EvmConfigInfo>)
418
+ const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
441
419
  mocks.getTransactionCount.mockResolvedValue(26)
442
420
  mocks.getGasEstimation.mockResolvedValue(new BigNumber(50000))
443
421
  mocks.getFeeData.mockResolvedValue(feeData)
444
422
 
445
423
  const { transaction } = await craftTransaction(context, 'sei_evm', {
446
- transactionIntent: {
447
- intentType: 'staking',
424
+ transactionIntent: createStakingTransactionIntentMockData<
425
+ MemoNotSupported,
426
+ BufferTxData
427
+ >({
448
428
  type: `staking-${transactionType}`,
449
- sender: '0x1234567890abcdef1234567890abcdef12345678',
429
+ mode: 'undelegate',
450
430
  recipient: '0x000000000000000000000000000000000001005',
451
431
  valAddress: 'seivaloper1234567890abcdef1234567890abcdef12345678',
452
- amount: 500000000000000000n, // 0.5 SEI
432
+ amount: 500000000000000000n,
453
433
  asset: { type: 'native' },
454
- mode: 'undelegate',
455
- } as any,
434
+ }),
456
435
  })
457
436
 
458
437
  // Parse the returned transaction to verify its properties
@@ -475,25 +454,23 @@ describe('craftTransaction', () => {
475
454
  ] as const)(
476
455
  'crafts a CELO staking delegate transaction using %s',
477
456
  async (_, type, mocks) => {
478
- const context = createMockEvmContext({
479
- node: { type },
480
- chainId: 42220,
481
- } as Partial<EvmConfigInfo>)
457
+ const context = createMockEvmContext({ node: nodeFor(type), chainId: 42220 })
482
458
  mocks.getTransactionCount.mockResolvedValue(30)
483
459
  mocks.getGasEstimation.mockResolvedValue(new BigNumber(60000))
484
460
  mocks.getFeeData.mockResolvedValue(feeData)
485
461
 
486
462
  const { transaction } = await craftTransaction(context, 'celo', {
487
- transactionIntent: {
488
- intentType: 'staking',
463
+ transactionIntent: createStakingTransactionIntentMockData<
464
+ MemoNotSupported,
465
+ BufferTxData
466
+ >({
489
467
  type: `staking-${transactionType}`,
490
- sender: '0x1234567890abcdef1234567890abcdef12345678',
468
+ mode: 'delegate',
491
469
  recipient: '0x55E1A0C8f376964bd339167476063bFED7f213d5',
492
470
  valAddress: '0xabcdef1234567890abcdef1234567890abcdef12',
493
- amount: 100000000000000000000n, // 100 CELO
471
+ amount: 100000000000000000000n,
494
472
  asset: { type: 'native' },
495
- mode: 'delegate',
496
- } as any,
473
+ }),
497
474
  })
498
475
 
499
476
  // Parse the returned transaction to verify its properties
@@ -513,21 +490,12 @@ describe('craftTransaction', () => {
513
490
  )
514
491
 
515
492
  it('fails to craft staking transaction for unsupported currency', async () => {
516
- const context = createMockEvmContext({
517
- node: { type: 'external' },
518
- } as Partial<EvmConfigInfo>)
493
+ const context = createMockEvmContext({ node: mkExternalNode() })
519
494
 
520
495
  await expect(
496
+ // @ts-ignore — intentionally bare staking intent to test unsupported-currency error path
521
497
  craftTransaction(context, 'unsupported_network', {
522
- transactionIntent: {
523
- type: 'staking',
524
- sender: '0x1234567890abcdef1234567890abcdef12345678',
525
- recipient: '0x000000000000000000000000000000000001005',
526
- valAddress: 'validator123',
527
- amount: 1000000000000000000n,
528
- asset: { type: 'native' },
529
- mode: 'delegate',
530
- } as any,
498
+ transactionIntent: { type: 'staking', mode: 'delegate' },
531
499
  })
532
500
  ).rejects.toThrow(
533
501
  "Unsupported intent type 'staking'. Must be 'send-legacy', 'send-eip1559', 'staking-legacy', or 'staking-eip1559'"
@@ -535,23 +503,18 @@ describe('craftTransaction', () => {
535
503
  })
536
504
 
537
505
  it('fails to craft staking transaction with unsupported operation', async () => {
538
- const context = createMockEvmContext({
539
- node: { type: 'external' },
540
- } as Partial<EvmConfigInfo>)
506
+ const context = createMockEvmContext({ node: mkExternalNode() })
541
507
 
542
508
  await expect(
543
509
  craftTransaction(context, 'sei_evm', {
544
510
  transactionIntent: {
545
- type: 'staking',
546
- sender: '0x1234567890abcdef1234567890abcdef12345678',
547
- recipient: '0x000000000000000000000000000000000001005',
548
- valAddress: 'validator123',
549
- amount: 1000000000000000000n,
550
- asset: { type: 'native' },
511
+ type: 'staking-legacy',
512
+ intentType: 'staking',
513
+ // @ts-ignore — intentionally invalid staking mode to test unsupported-operation error path
551
514
  mode: 'unsupported_operation',
552
- } as any,
515
+ },
553
516
  })
554
- ).rejects.toThrow()
517
+ ).rejects.toThrow('Invalid staking operation: unsupported_operation')
555
518
  })
556
519
  })
557
520
  })
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { EvmContext } from '../config'
5
- import {
5
+ import type {
6
6
  BufferTxData,
7
7
  CraftedTransaction,
8
8
  FeeEstimation,
@@ -10,7 +10,8 @@ import {
10
10
  MemoNotSupported,
11
11
  TransactionIntent,
12
12
  } from '@ledgerhq/coin-module-framework/api/types'
13
- import { Transaction, TransactionLike } from 'ethers'
13
+ import type { TransactionLike } from 'ethers'
14
+ import { Transaction } from 'ethers'
14
15
  import { GasEstimationError } from '../errors'
15
16
  import { getNodeApi } from '../network/node'
16
17
  import { TransactionTypes } from '../types'
@@ -1,11 +1,8 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import {
5
- TransactionIntent,
6
- MemoNotSupported,
7
- BufferTxData,
8
- } from '@ledgerhq/coin-module-framework/api/types'
4
+ import type { MemoNotSupported, BufferTxData } from '@ledgerhq/coin-module-framework/api/types'
5
+ import { createSendTransactionIntentMockData } from '@ledgerhq/coin-module-framework/test-utils'
9
6
  import * as commonModule from './common'
10
7
  import { craftTransactionData } from './craftTransactionData'
11
8
 
@@ -24,7 +21,10 @@ describe('craftTransactionData', () => {
24
21
  .spyOn(commonModule, 'getCallData')
25
22
  .mockReturnValueOnce(expectedBuffer)
26
23
 
27
- const intent = {} as unknown as TransactionIntent<MemoNotSupported, BufferTxData>
24
+ const intent = createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
25
+ type: 'send',
26
+ data: { type: 'buffer', value: Buffer.alloc(0) },
27
+ })
28
28
  const callData = craftTransactionData(intent)
29
29
 
30
30
  expect(callData).toEqual({
@@ -1,7 +1,7 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import {
4
+ import type {
5
5
  TransactionIntent,
6
6
  MemoNotSupported,
7
7
  BufferTxData,