@ledgerhq/coin-tezos 7.12.0 → 8.0.0

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 (189) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/lib/api/index.d.ts +1 -2
  3. package/lib/api/index.d.ts.map +1 -1
  4. package/lib/api/index.js +45 -44
  5. package/lib/api/index.js.map +1 -1
  6. package/lib/api/types.d.ts +3 -2
  7. package/lib/api/types.d.ts.map +1 -1
  8. package/lib/config.d.ts +3 -1
  9. package/lib/config.d.ts.map +1 -1
  10. package/lib/config.js.map +1 -1
  11. package/lib/logic/broadcast.d.ts +2 -1
  12. package/lib/logic/broadcast.d.ts.map +1 -1
  13. package/lib/logic/broadcast.js +3 -2
  14. package/lib/logic/broadcast.js.map +1 -1
  15. package/lib/logic/craftRawOperations.d.ts +2 -1
  16. package/lib/logic/craftRawOperations.d.ts.map +1 -1
  17. package/lib/logic/craftRawOperations.js +5 -8
  18. package/lib/logic/craftRawOperations.js.map +1 -1
  19. package/lib/logic/craftTransaction.d.ts +3 -2
  20. package/lib/logic/craftTransaction.d.ts.map +1 -1
  21. package/lib/logic/craftTransaction.js +6 -9
  22. package/lib/logic/craftTransaction.js.map +1 -1
  23. package/lib/logic/estimateFees.d.ts +2 -1
  24. package/lib/logic/estimateFees.d.ts.map +1 -1
  25. package/lib/logic/estimateFees.js +24 -19
  26. package/lib/logic/estimateFees.js.map +1 -1
  27. package/lib/logic/getBalance.d.ts +2 -1
  28. package/lib/logic/getBalance.d.ts.map +1 -1
  29. package/lib/logic/getBalance.js +7 -8
  30. package/lib/logic/getBalance.js.map +1 -1
  31. package/lib/logic/getBlock.d.ts +2 -1
  32. package/lib/logic/getBlock.d.ts.map +1 -1
  33. package/lib/logic/getBlock.js +12 -10
  34. package/lib/logic/getBlock.js.map +1 -1
  35. package/lib/logic/getBlockInfo.d.ts +2 -1
  36. package/lib/logic/getBlockInfo.d.ts.map +1 -1
  37. package/lib/logic/getBlockInfo.js +5 -3
  38. package/lib/logic/getBlockInfo.js.map +1 -1
  39. package/lib/logic/getStakes.d.ts +3 -2
  40. package/lib/logic/getStakes.d.ts.map +1 -1
  41. package/lib/logic/getStakes.js +9 -9
  42. package/lib/logic/getStakes.js.map +1 -1
  43. package/lib/logic/lastBlock.d.ts +2 -1
  44. package/lib/logic/lastBlock.d.ts.map +1 -1
  45. package/lib/logic/lastBlock.js +4 -6
  46. package/lib/logic/lastBlock.js.map +1 -1
  47. package/lib/logic/listOperations.d.ts +2 -1
  48. package/lib/logic/listOperations.d.ts.map +1 -1
  49. package/lib/logic/listOperations.js +8 -6
  50. package/lib/logic/listOperations.js.map +1 -1
  51. package/lib/logic/tezosToolkit.d.ts +2 -1
  52. package/lib/logic/tezosToolkit.d.ts.map +1 -1
  53. package/lib/logic/tezosToolkit.js +2 -6
  54. package/lib/logic/tezosToolkit.js.map +1 -1
  55. package/lib/logic/validateIntent.d.ts +2 -1
  56. package/lib/logic/validateIntent.d.ts.map +1 -1
  57. package/lib/logic/validateIntent.js +12 -13
  58. package/lib/logic/validateIntent.js.map +1 -1
  59. package/lib/network/bakers.d.ts +5 -4
  60. package/lib/network/bakers.d.ts.map +1 -1
  61. package/lib/network/bakers.js +9 -10
  62. package/lib/network/bakers.js.map +1 -1
  63. package/lib/network/index.d.ts +1 -1
  64. package/lib/network/index.d.ts.map +1 -1
  65. package/lib/network/index.js +2 -5
  66. package/lib/network/index.js.map +1 -1
  67. package/lib/network/tzkt.d.ts +16 -9
  68. package/lib/network/tzkt.d.ts.map +1 -1
  69. package/lib/network/tzkt.js +341 -333
  70. package/lib/network/tzkt.js.map +1 -1
  71. package/lib/utils.d.ts +2 -1
  72. package/lib/utils.d.ts.map +1 -1
  73. package/lib/utils.js +1 -6
  74. package/lib/utils.js.map +1 -1
  75. package/lib-es/api/index.d.ts +1 -2
  76. package/lib-es/api/index.d.ts.map +1 -1
  77. package/lib-es/api/index.js +40 -36
  78. package/lib-es/api/index.js.map +1 -1
  79. package/lib-es/api/types.d.ts +3 -2
  80. package/lib-es/api/types.d.ts.map +1 -1
  81. package/lib-es/config.d.ts +3 -1
  82. package/lib-es/config.d.ts.map +1 -1
  83. package/lib-es/config.js.map +1 -1
  84. package/lib-es/logic/broadcast.d.ts +2 -1
  85. package/lib-es/logic/broadcast.d.ts.map +1 -1
  86. package/lib-es/logic/broadcast.js +3 -2
  87. package/lib-es/logic/broadcast.js.map +1 -1
  88. package/lib-es/logic/craftRawOperations.d.ts +2 -1
  89. package/lib-es/logic/craftRawOperations.d.ts.map +1 -1
  90. package/lib-es/logic/craftRawOperations.js +5 -5
  91. package/lib-es/logic/craftRawOperations.js.map +1 -1
  92. package/lib-es/logic/craftTransaction.d.ts +3 -2
  93. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  94. package/lib-es/logic/craftTransaction.js +6 -6
  95. package/lib-es/logic/craftTransaction.js.map +1 -1
  96. package/lib-es/logic/estimateFees.d.ts +2 -1
  97. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  98. package/lib-es/logic/estimateFees.js +24 -16
  99. package/lib-es/logic/estimateFees.js.map +1 -1
  100. package/lib-es/logic/getBalance.d.ts +2 -1
  101. package/lib-es/logic/getBalance.d.ts.map +1 -1
  102. package/lib-es/logic/getBalance.js +5 -3
  103. package/lib-es/logic/getBalance.js.map +1 -1
  104. package/lib-es/logic/getBlock.d.ts +2 -1
  105. package/lib-es/logic/getBlock.d.ts.map +1 -1
  106. package/lib-es/logic/getBlock.js +10 -8
  107. package/lib-es/logic/getBlock.js.map +1 -1
  108. package/lib-es/logic/getBlockInfo.d.ts +2 -1
  109. package/lib-es/logic/getBlockInfo.d.ts.map +1 -1
  110. package/lib-es/logic/getBlockInfo.js +4 -2
  111. package/lib-es/logic/getBlockInfo.js.map +1 -1
  112. package/lib-es/logic/getStakes.d.ts +3 -2
  113. package/lib-es/logic/getStakes.d.ts.map +1 -1
  114. package/lib-es/logic/getStakes.js +9 -6
  115. package/lib-es/logic/getStakes.js.map +1 -1
  116. package/lib-es/logic/lastBlock.d.ts +2 -1
  117. package/lib-es/logic/lastBlock.d.ts.map +1 -1
  118. package/lib-es/logic/lastBlock.js +4 -3
  119. package/lib-es/logic/lastBlock.js.map +1 -1
  120. package/lib-es/logic/listOperations.d.ts +2 -1
  121. package/lib-es/logic/listOperations.d.ts.map +1 -1
  122. package/lib-es/logic/listOperations.js +7 -5
  123. package/lib-es/logic/listOperations.js.map +1 -1
  124. package/lib-es/logic/tezosToolkit.d.ts +2 -1
  125. package/lib-es/logic/tezosToolkit.d.ts.map +1 -1
  126. package/lib-es/logic/tezosToolkit.js +2 -3
  127. package/lib-es/logic/tezosToolkit.js.map +1 -1
  128. package/lib-es/logic/validateIntent.d.ts +2 -1
  129. package/lib-es/logic/validateIntent.d.ts.map +1 -1
  130. package/lib-es/logic/validateIntent.js +10 -8
  131. package/lib-es/logic/validateIntent.js.map +1 -1
  132. package/lib-es/network/bakers.d.ts +5 -4
  133. package/lib-es/network/bakers.d.ts.map +1 -1
  134. package/lib-es/network/bakers.js +9 -10
  135. package/lib-es/network/bakers.js.map +1 -1
  136. package/lib-es/network/index.d.ts +1 -1
  137. package/lib-es/network/index.d.ts.map +1 -1
  138. package/lib-es/network/index.js +1 -1
  139. package/lib-es/network/index.js.map +1 -1
  140. package/lib-es/network/tzkt.d.ts +16 -9
  141. package/lib-es/network/tzkt.d.ts.map +1 -1
  142. package/lib-es/network/tzkt.js +340 -333
  143. package/lib-es/network/tzkt.js.map +1 -1
  144. package/lib-es/utils.d.ts +2 -1
  145. package/lib-es/utils.d.ts.map +1 -1
  146. package/lib-es/utils.js +1 -3
  147. package/lib-es/utils.js.map +1 -1
  148. package/package.json +2 -2
  149. package/src/api/index-mainnet.integ.test.ts +34 -30
  150. package/src/api/index.integ.test.ts +69 -53
  151. package/src/api/index.test.ts +99 -60
  152. package/src/api/index.ts +52 -36
  153. package/src/api/types.ts +3 -2
  154. package/src/config.ts +4 -1
  155. package/src/logic/broadcast.integ.test.ts +12 -13
  156. package/src/logic/broadcast.ts +4 -2
  157. package/src/logic/craftRawOperations.test.ts +47 -33
  158. package/src/logic/craftRawOperations.ts +6 -4
  159. package/src/logic/craftTransaction.integ.test.ts +12 -5
  160. package/src/logic/craftTransaction.test.ts +39 -31
  161. package/src/logic/craftTransaction.ts +10 -5
  162. package/src/logic/estimateFees.integ.test.ts +7 -7
  163. package/src/logic/estimateFees.test.ts +52 -49
  164. package/src/logic/estimateFees.ts +34 -22
  165. package/src/logic/getBalance.test.ts +19 -17
  166. package/src/logic/getBalance.ts +6 -3
  167. package/src/logic/getBlock.integ.test.ts +8 -30
  168. package/src/logic/getBlock.test.ts +91 -81
  169. package/src/logic/getBlock.ts +11 -8
  170. package/src/logic/getBlockInfo.integ.test.ts +9 -18
  171. package/src/logic/getBlockInfo.test.ts +19 -9
  172. package/src/logic/getBlockInfo.ts +5 -2
  173. package/src/logic/getStakes.test.ts +46 -49
  174. package/src/logic/getStakes.ts +14 -5
  175. package/src/logic/lastBlock.ts +5 -3
  176. package/src/logic/listOperations.integ.test.ts +40 -67
  177. package/src/logic/listOperations.test.ts +65 -59
  178. package/src/logic/listOperations.ts +8 -3
  179. package/src/logic/tezosToolkit.ts +3 -3
  180. package/src/logic/validateIntent.test.ts +78 -74
  181. package/src/logic/validateIntent.ts +17 -7
  182. package/src/network/bakers.integ.test.ts +2 -5
  183. package/src/network/bakers.test.ts +5 -6
  184. package/src/network/bakers.ts +13 -10
  185. package/src/network/index.ts +2 -1
  186. package/src/network/tzkt.integ.test.ts +3 -14
  187. package/src/network/tzkt.test.ts +128 -96
  188. package/src/network/tzkt.ts +426 -393
  189. package/src/utils.ts +2 -3
@@ -1,12 +1,22 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import type { TezosCoinConfig, TezosContext } from '../config'
4
5
  import type { APIAccount } from '../network/types'
5
6
  import type { BalanceOptions, Operation } from '@ledgerhq/coin-module-framework/api/types'
6
7
  import type { TransactionIntent } from '@ledgerhq/coin-module-framework/api/types'
7
- import networkApi from '../network/tzkt'
8
8
  import { createApi } from './index'
9
9
 
10
+ // The tzkt factory `createTzktApi(config)` builds a fresh object on every call, so a spy on a
11
+ // single instance would not intercept the calls the source makes internally. We mock the module
12
+ // so `createTzktApi` always returns the SAME shared object, and expose its `getAccountByAddress`
13
+ // jest.fn as `mockGetAccountByAddress` for the assertions below (which used to target
14
+ // `mockGetAccountByAddress`).
15
+ const mockGetAccountByAddress = jest.fn()
16
+ jest.mock('../network/tzkt', () => ({
17
+ createTzktApi: () => ({ getAccountByAddress: mockGetAccountByAddress }),
18
+ }))
19
+
10
20
  const DEFAULT_ESTIMATED_FEES = 300n
11
21
  const DEFAULT_GAS_LIMIT = 30n
12
22
  const DEFAULT_STORAGE_LIMIT = 40n
@@ -14,7 +24,7 @@ const DEFAULT_STORAGE_LIMIT = 40n
14
24
  const logicGetTransactions = jest.fn()
15
25
  const logicEstimateFees = jest.fn()
16
26
  const logicCraftTransactionMock = jest.fn(
17
- (_account: unknown, _transaction: { fee: { fees: string } }) => {
27
+ (_context: unknown, _account: unknown, _transaction: { fee: { fees: string } }) => {
18
28
  return { type: undefined, contents: undefined }
19
29
  }
20
30
  )
@@ -23,8 +33,8 @@ const logicCraftRawOperationsMock = jest.fn()
23
33
  jest.mock('../logic', () => ({
24
34
  listOperations: async () => logicGetTransactions(),
25
35
  estimateFees: (...args: unknown[]) => logicEstimateFees(...args),
26
- craftTransaction: (account: unknown, transaction: { fee: { fees: string } }) =>
27
- logicCraftTransactionMock(account, transaction),
36
+ craftTransaction: (context: unknown, account: unknown, transaction: { fee: { fees: string } }) =>
37
+ logicCraftTransactionMock(context, account, transaction),
28
38
  craftRawOperations: (...args: unknown[]) => logicCraftRawOperationsMock(...args),
29
39
  rawEncode: () => Promise.resolve('tz1heMGVHQnx7ALDcDKqez8fan64Eyicw4DJ'),
30
40
  }))
@@ -34,7 +44,7 @@ jest.mock('../logic/tezosToolkit', () => ({
34
44
  getTezosToolkit: () => mockGetTezosToolkit(),
35
45
  }))
36
46
 
37
- jest.spyOn(networkApi, 'getAccountByAddress').mockResolvedValue({
47
+ mockGetAccountByAddress.mockResolvedValue({
38
48
  type: 'user',
39
49
  balance: 1000,
40
50
  revealed: true,
@@ -47,7 +57,17 @@ jest.spyOn(networkApi, 'getAccountByAddress').mockResolvedValue({
47
57
  firstActivityTime: '2021-01-01T00:00:00Z',
48
58
  } as APIAccount)
49
59
 
50
- const api = createApi({
60
+ const api = createApi()
61
+
62
+ /** Builds a TezosContext carrying the given coin config (see logic/getBalance.test.ts). */
63
+ function makeContext(config: unknown): TezosContext {
64
+ return {
65
+ config: async () => config as TezosCoinConfig,
66
+ logger: () => undefined,
67
+ }
68
+ }
69
+
70
+ const context = makeContext({
51
71
  baker: {
52
72
  url: 'https://baker.example.com',
53
73
  },
@@ -76,9 +96,16 @@ describe('craftRawTransaction', () => {
76
96
  logicCraftRawOperationsMock.mockResolvedValue('03deadbeef')
77
97
  const rawTransaction = '[{"kind":"transaction","destination":"tz1recipient","amount":"1000"}]'
78
98
 
79
- const result = await api.craftRawTransaction(rawTransaction, 'tz1sender', 'edpkpublickey', 5n)
99
+ const result = await api.craftRawTransaction(
100
+ context,
101
+ rawTransaction,
102
+ 'tz1sender',
103
+ 'edpkpublickey',
104
+ 5n
105
+ )
80
106
 
81
107
  expect(logicCraftRawOperationsMock).toHaveBeenCalledWith(
108
+ expect.anything(),
82
109
  rawTransaction,
83
110
  'tz1sender',
84
111
  'edpkpublickey',
@@ -95,7 +122,7 @@ describe('get operations', () => {
95
122
 
96
123
  it('could return no operation', async () => {
97
124
  logicGetTransactions.mockResolvedValue([[], ''])
98
- const { items: operations, next: token } = await api.listOperations('addr', {
125
+ const { items: operations, next: token } = await api.listOperations(context, 'addr', {
99
126
  minHeight: 100,
100
127
  order: 'asc',
101
128
  })
@@ -125,7 +152,7 @@ describe('get operations', () => {
125
152
 
126
153
  it('only does 1 iteration', async () => {
127
154
  logicGetTransactions.mockResolvedValue([[op], '888'])
128
- const { items: operations, next: token } = await api.listOperations('addr', {
155
+ const { items: operations, next: token } = await api.listOperations(context, 'addr', {
129
156
  minHeight: 100,
130
157
  order: 'asc',
131
158
  })
@@ -151,7 +178,7 @@ describe('craftTransaction', () => {
151
178
  txFee: 500n,
152
179
  },
153
180
  })
154
- await api.craftTransaction({
181
+ await api.craftTransaction(context, {
155
182
  intentType: 'transaction',
156
183
  type: 'send',
157
184
  sender: 'tz1test',
@@ -160,6 +187,7 @@ describe('craftTransaction', () => {
160
187
  } as TransactionIntent)
161
188
  expect(logicEstimateFees).toHaveBeenCalledTimes(1)
162
189
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
190
+ expect.anything(),
163
191
  expect.objectContaining({ address: 'tz1test' }),
164
192
  expect.objectContaining({
165
193
  fee: expect.objectContaining({
@@ -183,7 +211,7 @@ describe('craftTransaction', () => {
183
211
  txFee: 50n,
184
212
  },
185
213
  })
186
- await api.craftTransaction({
214
+ await api.craftTransaction(context, {
187
215
  intentType: 'transaction',
188
216
  type: 'send',
189
217
  sender: 'tz1test',
@@ -191,6 +219,7 @@ describe('craftTransaction', () => {
191
219
  amount: 1000n,
192
220
  } as TransactionIntent)
193
221
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
222
+ expect.anything(),
194
223
  expect.any(Object),
195
224
  expect.objectContaining({
196
225
  fee: expect.objectContaining({ fees: estimatedFees.toString() }),
@@ -213,6 +242,7 @@ describe('craftTransaction', () => {
213
242
  },
214
243
  })
215
244
  await api.craftTransaction(
245
+ context,
216
246
  {
217
247
  intentType: 'transaction',
218
248
  type: 'send',
@@ -220,9 +250,10 @@ describe('craftTransaction', () => {
220
250
  recipient: 'tz1recipient',
221
251
  amount: 1000n,
222
252
  } as TransactionIntent,
223
- { value: customFee }
253
+ { customFees: { value: customFee } }
224
254
  )
225
255
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
256
+ expect.anything(),
226
257
  expect.any(Object),
227
258
  expect.objectContaining({
228
259
  fee: expect.objectContaining({ fees: customFee.toString() }),
@@ -242,6 +273,7 @@ describe('craftTransaction', () => {
242
273
  },
243
274
  })
244
275
  await api.craftTransaction(
276
+ context,
245
277
  {
246
278
  intentType: 'transaction',
247
279
  type: 'send',
@@ -249,9 +281,10 @@ describe('craftTransaction', () => {
249
281
  recipient: 'tz1recipient',
250
282
  amount: 1000n,
251
283
  } as TransactionIntent,
252
- { value: customFee }
284
+ { customFees: { value: customFee } }
253
285
  )
254
286
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
287
+ expect.anything(),
255
288
  expect.any(Object),
256
289
  expect.objectContaining({
257
290
  fee: expect.objectContaining({ fees: customFee.toString() }),
@@ -265,7 +298,7 @@ describe('craftTransaction', () => {
265
298
  const delegateRecipient = 'tz3Vq38qYD3GEbWcXHMLt5PaASZrkDtEiA8D'
266
299
  const totalCustomFee = BigInt(minFees * 2)
267
300
 
268
- const apiMinFees1000 = createApi({
301
+ const contextMinFees1000 = makeContext({
269
302
  baker: { url: 'https://baker.example.com' },
270
303
  explorer: { url: 'foo', maxTxQuery: 1 },
271
304
  node: { url: 'bar' },
@@ -290,7 +323,7 @@ describe('craftTransaction', () => {
290
323
  numTransactions: 0,
291
324
  firstActivityTime: '2021-01-01T00:00:00Z',
292
325
  } as APIAccount
293
- ;(networkApi.getAccountByAddress as jest.Mock)
326
+ mockGetAccountByAddress
294
327
  .mockResolvedValueOnce(unrevealedAccount)
295
328
  .mockResolvedValueOnce(unrevealedAccount)
296
329
 
@@ -306,7 +339,8 @@ describe('craftTransaction', () => {
306
339
  },
307
340
  })
308
341
 
309
- await apiMinFees1000.craftTransaction(
342
+ await api.craftTransaction(
343
+ contextMinFees1000,
310
344
  {
311
345
  intentType: 'staking',
312
346
  type: 'delegate',
@@ -319,6 +353,7 @@ describe('craftTransaction', () => {
319
353
  )
320
354
 
321
355
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
356
+ expect.anything(),
322
357
  expect.objectContaining({ address: unrevealedSender }),
323
358
  expect.objectContaining({
324
359
  fee: expect.objectContaining({
@@ -340,7 +375,7 @@ describe('craftTransaction', () => {
340
375
  storageLimit: DEFAULT_STORAGE_LIMIT,
341
376
  })
342
377
 
343
- await api.craftTransaction({
378
+ await api.craftTransaction(context, {
344
379
  intentType: 'staking',
345
380
  type,
346
381
  sender: 'tz1test',
@@ -349,6 +384,7 @@ describe('craftTransaction', () => {
349
384
  } as TransactionIntent)
350
385
 
351
386
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
387
+ expect.anything(),
352
388
  expect.objectContaining({ address: 'tz1test' }),
353
389
  expect.objectContaining({
354
390
  type,
@@ -366,7 +402,7 @@ describe('craftTransaction', () => {
366
402
  storageLimit: DEFAULT_STORAGE_LIMIT,
367
403
  })
368
404
 
369
- await api.craftTransaction({
405
+ await api.craftTransaction(context, {
370
406
  intentType: 'staking',
371
407
  type: 'finalize_unstake',
372
408
  sender: 'tz1test',
@@ -375,6 +411,7 @@ describe('craftTransaction', () => {
375
411
  } as TransactionIntent)
376
412
 
377
413
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
414
+ expect.anything(),
378
415
  expect.objectContaining({ address: 'tz1test' }),
379
416
  expect.objectContaining({
380
417
  type: 'finalize_unstake',
@@ -395,7 +432,7 @@ describe('estimateFees', () => {
395
432
  gasLimit: DEFAULT_GAS_LIMIT,
396
433
  storageLimit: DEFAULT_STORAGE_LIMIT,
397
434
  })
398
- const result = await api.estimateFees({
435
+ const result = await api.estimateFees(context, {
399
436
  intentType: 'transaction',
400
437
  type: 'send',
401
438
  sender: 'tz1test',
@@ -414,7 +451,7 @@ describe('estimateFees', () => {
414
451
  gasLimit: DEFAULT_GAS_LIMIT,
415
452
  storageLimit: DEFAULT_STORAGE_LIMIT,
416
453
  })
417
- const result = await api.estimateFees({
454
+ const result = await api.estimateFees(context, {
418
455
  intentType: 'transaction',
419
456
  type: 'send',
420
457
  sender: 'tz1test',
@@ -433,7 +470,7 @@ describe('estimateFees', () => {
433
470
  gasLimit: DEFAULT_GAS_LIMIT,
434
471
  storageLimit: DEFAULT_STORAGE_LIMIT,
435
472
  })
436
- const result = await api.estimateFees({
473
+ const result = await api.estimateFees(context, {
437
474
  intentType: 'transaction',
438
475
  type: 'send',
439
476
  sender: 'tz1test',
@@ -450,7 +487,7 @@ describe('estimateFees', () => {
450
487
  })
451
488
 
452
489
  it('forwards stakedBalance and unstakedBalance to the logic estimate for send-max', async () => {
453
- ;(networkApi.getAccountByAddress as jest.Mock).mockResolvedValueOnce({
490
+ mockGetAccountByAddress.mockResolvedValueOnce({
454
491
  type: 'user',
455
492
  balance: 1000,
456
493
  revealed: true,
@@ -471,7 +508,7 @@ describe('estimateFees', () => {
471
508
  amount: 500n,
472
509
  })
473
510
 
474
- await api.estimateFees({
511
+ await api.estimateFees(context, {
475
512
  intentType: 'transaction',
476
513
  type: 'send',
477
514
  sender: 'tz1test',
@@ -481,6 +518,7 @@ describe('estimateFees', () => {
481
518
  } as TransactionIntent)
482
519
 
483
520
  expect(logicEstimateFees).toHaveBeenCalledWith(
521
+ expect.anything(),
484
522
  expect.objectContaining({
485
523
  account: expect.objectContaining({ stakedBalance: 200n, unstakedBalance: 300n }),
486
524
  })
@@ -495,7 +533,7 @@ describe('estimateFees', () => {
495
533
  taquitoError: 'test',
496
534
  })
497
535
  await expect(
498
- api.estimateFees({
536
+ api.estimateFees(context, {
499
537
  intentType: 'transaction',
500
538
  type: 'send',
501
539
  sender: 'tz1test',
@@ -512,7 +550,7 @@ describe('estimateFees', () => {
512
550
  storageLimit: DEFAULT_STORAGE_LIMIT,
513
551
  taquitoError: 'proto.024-PtTALLiN.michelson_v1.script_rejected',
514
552
  })
515
- const result = await api.estimateFees({
553
+ const result = await api.estimateFees(context, {
516
554
  intentType: 'transaction',
517
555
  type: 'send',
518
556
  sender: 'tz1test',
@@ -532,7 +570,7 @@ describe('estimateFees', () => {
532
570
  storageLimit: DEFAULT_STORAGE_LIMIT,
533
571
  taquitoError: 'proto.022-PsRiotum.delegate.unchanged',
534
572
  })
535
- const result = await api.estimateFees({
573
+ const result = await api.estimateFees(context, {
536
574
  intentType: 'staking',
537
575
  type: 'delegate',
538
576
  sender: 'tz1test',
@@ -557,7 +595,7 @@ describe('estimateFees', () => {
557
595
  taquitoError:
558
596
  'proto.alpha.cannot_stake_with_unfinalizable_unstake_requests_to_another_delegate',
559
597
  })
560
- const result = await api.estimateFees({
598
+ const result = await api.estimateFees(context, {
561
599
  intentType: 'staking',
562
600
  type: 'stake',
563
601
  sender: 'tz1test',
@@ -576,7 +614,7 @@ describe('estimateFees', () => {
576
614
 
577
615
  it('returns total estimation for unrevealed delegate when minFees applied (composite)', async () => {
578
616
  const unrevealedSender = 'tz2TaTpo31sAiX2HBJUTLLdUnqVJR4QjLy1V'
579
- ;(networkApi.getAccountByAddress as jest.Mock).mockResolvedValueOnce({
617
+ mockGetAccountByAddress.mockResolvedValueOnce({
580
618
  type: 'user',
581
619
  balance: 1000000,
582
620
  revealed: false,
@@ -597,7 +635,7 @@ describe('estimateFees', () => {
597
635
  storageLimit: DEFAULT_STORAGE_LIMIT,
598
636
  })
599
637
 
600
- const result = await api.estimateFees({
638
+ const result = await api.estimateFees(context, {
601
639
  intentType: 'staking',
602
640
  type: 'delegate',
603
641
  sender: unrevealedSender,
@@ -622,7 +660,7 @@ describe('estimateFees', () => {
622
660
  storageLimit: DEFAULT_STORAGE_LIMIT,
623
661
  })
624
662
 
625
- const result = await api.estimateFees({
663
+ const result = await api.estimateFees(context, {
626
664
  intentType: 'staking',
627
665
  type,
628
666
  sender: 'tz1test',
@@ -632,6 +670,7 @@ describe('estimateFees', () => {
632
670
 
633
671
  expect(result.value).toBe(DEFAULT_ESTIMATED_FEES)
634
672
  expect(logicEstimateFees).toHaveBeenCalledWith(
673
+ expect.anything(),
635
674
  expect.objectContaining({
636
675
  transaction: expect.objectContaining({
637
676
  mode: type,
@@ -646,7 +685,7 @@ describe('estimateFees', () => {
646
685
  const delegateRecipient = 'tz3Vq38qYD3GEbWcXHMLt5PaASZrkDtEiA8D'
647
686
  const minFees = 1000
648
687
 
649
- const apiMinFees1000 = createApi({
688
+ const contextMinFees1000 = makeContext({
650
689
  baker: { url: 'https://baker.example.com' },
651
690
  explorer: { url: 'foo', maxTxQuery: 1 },
652
691
  node: { url: 'bar' },
@@ -695,7 +734,7 @@ describe('estimateFees', () => {
695
734
  numTransactions: 0,
696
735
  firstActivityTime: '2021-01-01T00:00:00Z',
697
736
  } as APIAccount
698
- ;(networkApi.getAccountByAddress as jest.Mock)
737
+ mockGetAccountByAddress
699
738
  .mockImplementationOnce(() => Promise.resolve(defaultUserForTry))
700
739
  .mockImplementationOnce(() => Promise.resolve(recipientAccount))
701
740
  .mockImplementationOnce(() => Promise.resolve(senderUnrevealedAccount))
@@ -712,7 +751,7 @@ describe('estimateFees', () => {
712
751
  },
713
752
  })
714
753
 
715
- const result = await apiMinFees1000.estimateFees({
754
+ const result = await api.estimateFees(contextMinFees1000, {
716
755
  intentType: 'staking',
717
756
  type: 'delegate',
718
757
  sender: unrevealedSender,
@@ -732,7 +771,7 @@ describe('estimateFees', () => {
732
771
  // SAFE_FALLBACK_GAS = 2500, FALLBACK_OP_SIZE_BYTES = 154
733
772
  // baseTxFee = max(minFees=1, ceil(120 + 0.1*2500 + 154)) = max(1, 524) = 524
734
773
  // createApi here to reset the global coinConfig to minFees=1 (other tests may leave it at a higher value)
735
- const apiLowMinFees = createApi({
774
+ const contextLowMinFees = makeContext({
736
775
  baker: { url: 'https://baker.example.com' },
737
776
  explorer: { url: 'foo', maxTxQuery: 1 },
738
777
  node: { url: 'bar' },
@@ -772,7 +811,7 @@ describe('estimateFees', () => {
772
811
  firstActivityTime: '2021-01-01T00:00:00Z',
773
812
  } as APIAccount
774
813
 
775
- ;(networkApi.getAccountByAddress as jest.Mock)
814
+ mockGetAccountByAddress
776
815
  .mockResolvedValueOnce(revealedAccount) // initial sender lookup
777
816
  .mockResolvedValueOnce(recipientAccount) // recipient lookup in catch block
778
817
  .mockResolvedValueOnce(revealedAccount) // sender lookup for needsReveal in catch block
@@ -785,7 +824,7 @@ describe('estimateFees', () => {
785
824
  },
786
825
  })
787
826
 
788
- const result = await apiLowMinFees.estimateFees({
827
+ const result = await api.estimateFees(contextLowMinFees, {
789
828
  intentType: 'transaction',
790
829
  type: 'send',
791
830
  sender: revealedSender,
@@ -806,7 +845,7 @@ describe('estimateFees', () => {
806
845
  // baseTxFee = max(minFees=1, ceil(120 + 0.1*2500 + 154)) = 524
807
846
  // revealFee = max(0, getRevealFee(tz2address)) — tz2 addresses have a non-zero reveal fee
808
847
  // createApi here to reset the global coinConfig to minFees=1 (other tests may leave it at a higher value)
809
- const apiLowMinFees = createApi({
848
+ const contextLowMinFees = makeContext({
810
849
  baker: { url: 'https://baker.example.com' },
811
850
  explorer: { url: 'foo', maxTxQuery: 1 },
812
851
  node: { url: 'bar' },
@@ -846,7 +885,7 @@ describe('estimateFees', () => {
846
885
  firstActivityTime: '2021-01-01T00:00:00Z',
847
886
  } as APIAccount
848
887
 
849
- ;(networkApi.getAccountByAddress as jest.Mock)
888
+ mockGetAccountByAddress
850
889
  .mockResolvedValueOnce(unrevealedAccount) // initial sender lookup
851
890
  .mockResolvedValueOnce(recipientAccount) // recipient lookup in catch block
852
891
  .mockResolvedValueOnce(unrevealedAccount) // sender lookup for needsReveal in catch block
@@ -859,7 +898,7 @@ describe('estimateFees', () => {
859
898
  },
860
899
  })
861
900
 
862
- const result = await apiLowMinFees.estimateFees({
901
+ const result = await api.estimateFees(contextLowMinFees, {
863
902
  intentType: 'transaction',
864
903
  type: 'send',
865
904
  sender: unrevealedSender,
@@ -880,7 +919,7 @@ describe('estimateFees', () => {
880
919
  it('uses minFees floor when it exceeds the static fallback calculation', async () => {
881
920
  // With minFees = 2000 > ceil(120 + 0.1*2500 + 154) = 524 → baseTxFee = 2000
882
921
  const minFees = 2000
883
- const apiHighMinFees = createApi({
922
+ const contextHighMinFees = makeContext({
884
923
  baker: { url: 'https://baker.example.com' },
885
924
  explorer: { url: 'foo', maxTxQuery: 1 },
886
925
  node: { url: 'bar' },
@@ -918,7 +957,7 @@ describe('estimateFees', () => {
918
957
  firstActivityTime: '2021-01-01T00:00:00Z',
919
958
  } as APIAccount
920
959
 
921
- ;(networkApi.getAccountByAddress as jest.Mock)
960
+ mockGetAccountByAddress
922
961
  .mockResolvedValueOnce(revealedAccount)
923
962
  .mockResolvedValueOnce(recipientAccount)
924
963
  .mockResolvedValueOnce(revealedAccount)
@@ -931,7 +970,7 @@ describe('estimateFees', () => {
931
970
  },
932
971
  })
933
972
 
934
- const result = await apiHighMinFees.estimateFees({
973
+ const result = await api.estimateFees(contextHighMinFees, {
935
974
  intentType: 'transaction',
936
975
  type: 'send',
937
976
  sender: 'tz1test',
@@ -950,18 +989,18 @@ describe('estimateFees', () => {
950
989
  describe('getBalance', () => {
951
990
  it('should throw an exception when options is provided', async () => {
952
991
  await expect(
953
- api.getBalance('random address', {} as unknown as BalanceOptions)
992
+ api.getBalance(context, 'random address', {} as unknown as BalanceOptions)
954
993
  ).rejects.toMatchObject({ name: 'InvalidParameterError' })
955
994
  })
956
995
  })
957
996
 
958
997
  describe('getAccountInfo', () => {
959
998
  afterEach(() => {
960
- ;(networkApi.getAccountByAddress as jest.Mock).mockClear()
999
+ mockGetAccountByAddress.mockClear()
961
1000
  })
962
1001
 
963
1002
  it('returns revealed:true for a revealed user account', async () => {
964
- ;(networkApi.getAccountByAddress as jest.Mock).mockResolvedValueOnce({
1003
+ mockGetAccountByAddress.mockResolvedValueOnce({
965
1004
  type: 'user',
966
1005
  balance: 1000,
967
1006
  revealed: true,
@@ -974,15 +1013,15 @@ describe('getAccountInfo', () => {
974
1013
  firstActivityTime: '2021-01-01T00:00:00Z',
975
1014
  } as APIAccount)
976
1015
 
977
- await expect(api.getAccountInfo('tz1test')).resolves.toEqual({
1016
+ await expect(api.getAccountInfo(context, 'tz1test')).resolves.toEqual({
978
1017
  type: 'tezos',
979
1018
  revealed: true,
980
1019
  })
981
- expect(networkApi.getAccountByAddress).toHaveBeenCalledWith('tz1test')
1020
+ expect(mockGetAccountByAddress).toHaveBeenCalledWith('tz1test')
982
1021
  })
983
1022
 
984
1023
  it('returns revealed:false for an unrevealed user account', async () => {
985
- ;(networkApi.getAccountByAddress as jest.Mock).mockResolvedValueOnce({
1024
+ mockGetAccountByAddress.mockResolvedValueOnce({
986
1025
  type: 'user',
987
1026
  balance: 1000,
988
1027
  revealed: false,
@@ -995,17 +1034,17 @@ describe('getAccountInfo', () => {
995
1034
  firstActivityTime: '2021-01-01T00:00:00Z',
996
1035
  } as APIAccount)
997
1036
 
998
- await expect(api.getAccountInfo('tz2unrevealed')).resolves.toEqual({
1037
+ await expect(api.getAccountInfo(context, 'tz2unrevealed')).resolves.toEqual({
999
1038
  type: 'tezos',
1000
1039
  revealed: false,
1001
1040
  })
1002
- expect(networkApi.getAccountByAddress).toHaveBeenCalledWith('tz2unrevealed')
1041
+ expect(mockGetAccountByAddress).toHaveBeenCalledWith('tz2unrevealed')
1003
1042
  })
1004
1043
 
1005
1044
  it('returns revealed:true for a registered baker (delegate) account', async () => {
1006
1045
  // tzkt reports bakers with type "delegate" (not "user"), still carrying revealed:true.
1007
1046
  // Regression test for LIVE-34256: bakers must not be reported as unrevealed.
1008
- ;(networkApi.getAccountByAddress as jest.Mock).mockResolvedValueOnce({
1047
+ mockGetAccountByAddress.mockResolvedValueOnce({
1009
1048
  type: 'delegate',
1010
1049
  balance: 616109,
1011
1050
  revealed: true,
@@ -1014,32 +1053,32 @@ describe('getAccountInfo', () => {
1014
1053
  counter: 18,
1015
1054
  } as APIAccount)
1016
1055
 
1017
- await expect(api.getAccountInfo('tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9')).resolves.toEqual({
1056
+ await expect(
1057
+ api.getAccountInfo(context, 'tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9')
1058
+ ).resolves.toEqual({
1018
1059
  type: 'tezos',
1019
1060
  revealed: true,
1020
1061
  })
1021
- expect(networkApi.getAccountByAddress).toHaveBeenCalledWith(
1022
- 'tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9'
1023
- )
1062
+ expect(mockGetAccountByAddress).toHaveBeenCalledWith('tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9')
1024
1063
  })
1025
1064
 
1026
1065
  it('returns revealed:false for an empty / non-existent account', async () => {
1027
- ;(networkApi.getAccountByAddress as jest.Mock).mockResolvedValueOnce({
1066
+ mockGetAccountByAddress.mockResolvedValueOnce({
1028
1067
  type: 'empty',
1029
1068
  address: 'tz1empty',
1030
1069
  counter: 0,
1031
1070
  } as APIAccount)
1032
1071
 
1033
- await expect(api.getAccountInfo('tz1empty')).resolves.toEqual({
1072
+ await expect(api.getAccountInfo(context, 'tz1empty')).resolves.toEqual({
1034
1073
  type: 'tezos',
1035
1074
  revealed: false,
1036
1075
  })
1037
- expect(networkApi.getAccountByAddress).toHaveBeenCalledWith('tz1empty')
1076
+ expect(mockGetAccountByAddress).toHaveBeenCalledWith('tz1empty')
1038
1077
  })
1039
1078
 
1040
1079
  it('propagates errors from getAccountByAddress', async () => {
1041
- ;(networkApi.getAccountByAddress as jest.Mock).mockRejectedValueOnce(new Error('boom'))
1080
+ mockGetAccountByAddress.mockRejectedValueOnce(new Error('boom'))
1042
1081
 
1043
- await expect(api.getAccountInfo('tz1boom')).rejects.toThrow('boom')
1082
+ await expect(api.getAccountInfo(context, 'tz1boom')).rejects.toThrow('boom')
1044
1083
  })
1045
1084
  })