@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,6 +1,7 @@
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 {
5
6
  APIDelegationType,
6
7
  APIOriginationType,
@@ -12,6 +13,11 @@ import type {
12
13
  import type { OtherBlockOperation } from '@ledgerhq/coin-module-framework/api/types'
13
14
  import { getBlock } from './getBlock'
14
15
 
16
+ const context: TezosContext = {
17
+ config: async () => ({}) as unknown as TezosCoinConfig,
18
+ logger: () => undefined,
19
+ }
20
+
15
21
  // ---------------------------------------------------------------------------
16
22
  // Network mock
17
23
  // Using the same lazy-reference pattern as the XRP reference tests so that the
@@ -28,10 +34,10 @@ const mockFetchBlockOriginations = jest.fn()
28
34
  const mockFetchBlockReveals = jest.fn()
29
35
 
30
36
  jest.mock('../network', () => ({
31
- tzkt: {
37
+ createTzktApi: () => ({
32
38
  getBlockByLevel: (...args: unknown[]) => mockGetBlockByLevel(...args),
33
39
  getOperationsOrigination: (...args: unknown[]) => mockGetOperationsOrigination(...args),
34
- },
40
+ }),
35
41
  fetchBlockTransactions: (...args: unknown[]) => mockFetchBlockTransactions(...args),
36
42
  fetchBlockTokenTransfers: (...args: unknown[]) => mockFetchBlockTokenTransfers(...args),
37
43
  fetchBlockDelegations: (...args: unknown[]) => mockFetchBlockDelegations(...args),
@@ -204,7 +210,7 @@ describe('block info and guard', () => {
204
210
  )
205
211
 
206
212
  // When
207
- const result = await getBlock(level)
213
+ const result = await getBlock(context, level)
208
214
 
209
215
  // Then
210
216
  expect(mockGetBlockByLevel).toHaveBeenCalledWith(level)
@@ -219,7 +225,9 @@ describe('block info and guard', () => {
219
225
 
220
226
  it('throws for height = 0 without any network calls', async () => {
221
227
  // When / Then
222
- await expect(getBlock(0)).rejects.toThrow('getBlock: height must be a positive integer, got 0')
228
+ await expect(getBlock(context, 0)).rejects.toThrow(
229
+ 'getBlock: height must be a positive integer, got 0'
230
+ )
223
231
  expect(mockGetBlockByLevel).not.toHaveBeenCalled()
224
232
  expect(mockFetchBlockTransactions).not.toHaveBeenCalled()
225
233
  expect(mockFetchBlockTokenTransfers).not.toHaveBeenCalled()
@@ -227,7 +235,7 @@ describe('block info and guard', () => {
227
235
 
228
236
  it('throws for negative height without any network calls', async () => {
229
237
  // When / Then
230
- await expect(getBlock(-3)).rejects.toThrow(
238
+ await expect(getBlock(context, -3)).rejects.toThrow(
231
239
  'getBlock: height must be a positive integer, got -3'
232
240
  )
233
241
  expect(mockGetBlockByLevel).not.toHaveBeenCalled()
@@ -236,7 +244,9 @@ describe('block info and guard', () => {
236
244
  it.each([NaN, 1.5, Infinity, -Infinity])(
237
245
  'throws for non-safe-integer height (%s) without any network calls',
238
246
  async (height) => {
239
- await expect(getBlock(height)).rejects.toThrow('getBlock: height must be a positive integer')
247
+ await expect(getBlock(context, height)).rejects.toThrow(
248
+ 'getBlock: height must be a positive integer'
249
+ )
240
250
  expect(mockGetBlockByLevel).not.toHaveBeenCalled()
241
251
  }
242
252
  )
@@ -246,7 +256,7 @@ describe('block info and guard', () => {
246
256
  mockGetBlockByLevel.mockResolvedValue(makeBlock())
247
257
 
248
258
  // When
249
- const result = await getBlock(5_000_000)
259
+ const result = await getBlock(context, 5_000_000)
250
260
 
251
261
  // Then
252
262
  expect(result.transactions).toEqual([])
@@ -261,7 +271,7 @@ describe('block info and guard', () => {
261
271
  ])
262
272
 
263
273
  // When
264
- const result = await getBlock(5_000_000)
274
+ const result = await getBlock(context, 5_000_000)
265
275
 
266
276
  // Then – only the tx with a valid hash is included
267
277
  expect(result.transactions).toHaveLength(1)
@@ -276,7 +286,7 @@ describe('block info and guard', () => {
276
286
  ])
277
287
 
278
288
  // When
279
- const result = await getBlock(5_000_000)
289
+ const result = await getBlock(context, 5_000_000)
280
290
 
281
291
  // Then – the tx still appears (it has a hash), but no txIdToHash entry was created
282
292
  expect(result.transactions).toHaveLength(1)
@@ -297,7 +307,7 @@ describe('native XTZ operations', () => {
297
307
  ])
298
308
 
299
309
  // When
300
- const result = await getBlock(5_000_000)
310
+ const result = await getBlock(context, 5_000_000)
301
311
  const tx = result.transactions[0]
302
312
 
303
313
  // Then
@@ -324,7 +334,7 @@ describe('native XTZ operations', () => {
324
334
  mockFetchBlockTransactions.mockResolvedValue([makeTx({ amount: 0, bakerFee: 0 })])
325
335
 
326
336
  // When
327
- const result = await getBlock(5_000_000)
337
+ const result = await getBlock(context, 5_000_000)
328
338
 
329
339
  // Then — no balance impact, no operations
330
340
  expect(result.transactions[0].operations).toEqual([])
@@ -336,7 +346,7 @@ describe('native XTZ operations', () => {
336
346
  mockFetchBlockTransactions.mockResolvedValue([makeTx({ amount: 0, bakerFee: 1500 })])
337
347
 
338
348
  // When
339
- const result = await getBlock(5_000_000)
349
+ const result = await getBlock(context, 5_000_000)
340
350
 
341
351
  // Then — fees are a balance change, so operations must be emitted for fee attribution
342
352
  expect(result.transactions[0].fees).toBe(1500n)
@@ -366,7 +376,7 @@ describe('native XTZ operations', () => {
366
376
  ])
367
377
 
368
378
  // When
369
- const result = await getBlock(5_000_000)
379
+ const result = await getBlock(context, 5_000_000)
370
380
 
371
381
  // Then — peer must be absent (not set to undefined) when the counterparty is unknown
372
382
  expect(result.transactions[0].operations).toHaveLength(1)
@@ -387,7 +397,7 @@ describe('native XTZ operations', () => {
387
397
  ])
388
398
 
389
399
  // When
390
- const result = await getBlock(5_000_000)
400
+ const result = await getBlock(context, 5_000_000)
391
401
 
392
402
  // Then — peer must be absent (not set to undefined) when the counterparty is unknown
393
403
  expect(result.transactions[0].operations).toHaveLength(1)
@@ -409,7 +419,7 @@ describe('native XTZ operations', () => {
409
419
  ])
410
420
 
411
421
  // When
412
- const result = await getBlock(5_000_000)
422
+ const result = await getBlock(context, 5_000_000)
413
423
 
414
424
  // Then — only the tx with a hash produces a BlockTransaction
415
425
  expect(result.transactions).toHaveLength(1)
@@ -430,7 +440,7 @@ describe('fee computation and fee payer', () => {
430
440
  ])
431
441
 
432
442
  // When
433
- const result = await getBlock(5_000_000)
443
+ const result = await getBlock(context, 5_000_000)
434
444
 
435
445
  // Then
436
446
  expect(result.transactions[0].fees).toBe(550n)
@@ -444,7 +454,7 @@ describe('fee computation and fee payer', () => {
444
454
  ])
445
455
 
446
456
  // When
447
- const result = await getBlock(5_000_000)
457
+ const result = await getBlock(context, 5_000_000)
448
458
 
449
459
  // Then
450
460
  expect(result.transactions[0].feesPayer).toBe('tz1FeePayer')
@@ -462,7 +472,7 @@ describe('fee computation and fee payer', () => {
462
472
  ])
463
473
 
464
474
  // When
465
- const result = await getBlock(5_000_000)
475
+ const result = await getBlock(context, 5_000_000)
466
476
 
467
477
  // Then
468
478
  expect(result.transactions[0].feesPayer).toBe('tz1RealUser')
@@ -474,7 +484,7 @@ describe('fee computation and fee payer', () => {
474
484
  mockFetchBlockTransactions.mockResolvedValue([makeTx({ sender: null, initiator: null })])
475
485
 
476
486
  // When
477
- const result = await getBlock(5_000_000)
487
+ const result = await getBlock(context, 5_000_000)
478
488
 
479
489
  // Then
480
490
  expect(result.transactions[0].feesPayer).toBeUndefined()
@@ -494,7 +504,7 @@ describe('fee computation and fee payer', () => {
494
504
  ])
495
505
 
496
506
  // When
497
- const result = await getBlock(5_000_000)
507
+ const result = await getBlock(context, 5_000_000)
498
508
 
499
509
  // Then – all three ?? 0 branches are exercised; total fees must be 0n
500
510
  expect(result.transactions[0].fees).toBe(0n)
@@ -512,7 +522,7 @@ describe('failed transactions', () => {
512
522
  mockFetchBlockTransactions.mockResolvedValue([makeTx({ status: 'failed', amount: 1_000_000 })])
513
523
 
514
524
  // When
515
- const result = await getBlock(5_000_000)
525
+ const result = await getBlock(context, 5_000_000)
516
526
 
517
527
  // Then
518
528
  expect(result.transactions[0].failed).toBe(true)
@@ -527,7 +537,7 @@ describe('failed transactions', () => {
527
537
  ])
528
538
 
529
539
  // When
530
- const result = await getBlock(5_000_000)
540
+ const result = await getBlock(context, 5_000_000)
531
541
 
532
542
  // Then
533
543
  expect(result.transactions[0].failed).toBe(true)
@@ -543,7 +553,7 @@ describe('failed transactions', () => {
543
553
  ])
544
554
 
545
555
  // When
546
- const result = await getBlock(5_000_000)
556
+ const result = await getBlock(context, 5_000_000)
547
557
 
548
558
  // Then
549
559
  expect(result.transactions).toHaveLength(1)
@@ -557,7 +567,7 @@ describe('failed transactions', () => {
557
567
  mockFetchBlockTransactions.mockResolvedValue([makeTx({ status: undefined, amount: 100_000 })])
558
568
 
559
569
  // When
560
- const result = await getBlock(5_000_000)
570
+ const result = await getBlock(context, 5_000_000)
561
571
 
562
572
  // Then
563
573
  expect(result.transactions[0].failed).toBe(false)
@@ -587,7 +597,7 @@ describe('batch and internal operations', () => {
587
597
  ])
588
598
 
589
599
  // When
590
- const result = await getBlock(5_000_000)
600
+ const result = await getBlock(context, 5_000_000)
591
601
 
592
602
  // Then – one BlockTransaction with both ops' ops and combined fees
593
603
  expect(result.transactions).toHaveLength(1)
@@ -606,7 +616,7 @@ describe('batch and internal operations', () => {
606
616
  ])
607
617
 
608
618
  // When
609
- const result = await getBlock(5_000_000)
619
+ const result = await getBlock(context, 5_000_000)
610
620
 
611
621
  // Then
612
622
  expect(result.transactions[0].feesPayer).toBe('tz1ActualPayer')
@@ -621,7 +631,7 @@ describe('batch and internal operations', () => {
621
631
  ])
622
632
 
623
633
  // When
624
- const result = await getBlock(5_000_000)
634
+ const result = await getBlock(context, 5_000_000)
625
635
 
626
636
  // Then
627
637
  expect(result.transactions).toHaveLength(2)
@@ -647,7 +657,7 @@ describe('FA token transfers', () => {
647
657
  ])
648
658
 
649
659
  // When
650
- const result = await getBlock(5_000_000)
660
+ const result = await getBlock(context, 5_000_000)
651
661
 
652
662
  // Then – one BlockTransaction with 2 native ops + 2 token ops
653
663
  expect(result.transactions).toHaveLength(1)
@@ -670,7 +680,7 @@ describe('FA token transfers', () => {
670
680
  ])
671
681
 
672
682
  // When
673
- const result = await getBlock(5_000_000)
683
+ const result = await getBlock(context, 5_000_000)
674
684
 
675
685
  // Then – failed tx has no operations at all
676
686
  expect(result.transactions).toHaveLength(1)
@@ -686,7 +696,7 @@ describe('FA token transfers', () => {
686
696
  ])
687
697
 
688
698
  // When
689
- const result = await getBlock(5_000_000)
699
+ const result = await getBlock(context, 5_000_000)
690
700
 
691
701
  // Then – one standalone BlockTransaction with 2 token ops
692
702
  expect(result.transactions).toHaveLength(1)
@@ -712,7 +722,7 @@ describe('FA token transfers', () => {
712
722
  ])
713
723
 
714
724
  // When
715
- const result = await getBlock(5_000_000)
725
+ const result = await getBlock(context, 5_000_000)
716
726
 
717
727
  // Then – merged into one standalone BlockTransaction with 4 ops (2 per transfer)
718
728
  expect(result.transactions).toHaveLength(1)
@@ -728,7 +738,7 @@ describe('FA token transfers', () => {
728
738
  ])
729
739
 
730
740
  // When
731
- const result = await getBlock(5_000_000)
741
+ const result = await getBlock(context, 5_000_000)
732
742
 
733
743
  // Then – each gets its own BlockTransaction
734
744
  expect(result.transactions).toHaveLength(2)
@@ -747,7 +757,7 @@ describe('FA token transfers', () => {
747
757
  ])
748
758
 
749
759
  // When
750
- const result = await getBlock(5_000_000)
760
+ const result = await getBlock(context, 5_000_000)
751
761
 
752
762
  // Then — peer must be absent when mint has no sender
753
763
  expect(result.transactions[0].operations).toHaveLength(1)
@@ -772,7 +782,7 @@ describe('FA token transfers', () => {
772
782
  ])
773
783
 
774
784
  // When
775
- const result = await getBlock(5_000_000)
785
+ const result = await getBlock(context, 5_000_000)
776
786
 
777
787
  // Then — peer must be absent when burn has no receiver
778
788
  expect(result.transactions[0].operations).toHaveLength(1)
@@ -792,7 +802,7 @@ describe('FA token transfers', () => {
792
802
  ])
793
803
 
794
804
  // When
795
- const result = await getBlock(5_000_000)
805
+ const result = await getBlock(context, 5_000_000)
796
806
 
797
807
  // Then – zero-amount transfer is silently discarded
798
808
  expect(result.transactions).toHaveLength(0)
@@ -816,7 +826,7 @@ describe('FA token transfers', () => {
816
826
  ])
817
827
 
818
828
  // When
819
- const result = await getBlock(5_000_000)
829
+ const result = await getBlock(context, 5_000_000)
820
830
 
821
831
  // Then — tokenId "7" must be part of the reference so different FA2 tokens under
822
832
  // the same contract are not conflated.
@@ -846,7 +856,7 @@ describe('FA token transfers', () => {
846
856
  ])
847
857
 
848
858
  // When
849
- const result = await getBlock(5_000_000)
859
+ const result = await getBlock(context, 5_000_000)
850
860
 
851
861
  // Then
852
862
  const op = result.transactions[0].operations[0] as any
@@ -874,7 +884,7 @@ describe('delegation operations', () => {
874
884
  ])
875
885
 
876
886
  // When
877
- const result = await getBlock(5_000_000)
887
+ const result = await getBlock(context, 5_000_000)
878
888
 
879
889
  // Then
880
890
  expect(result.transactions).toHaveLength(1)
@@ -909,7 +919,7 @@ describe('delegation operations', () => {
909
919
  ])
910
920
 
911
921
  // When
912
- const result = await getBlock(5_000_000)
922
+ const result = await getBlock(context, 5_000_000)
913
923
 
914
924
  // Then
915
925
  expect(result.transactions).toHaveLength(1)
@@ -934,7 +944,7 @@ describe('delegation operations', () => {
934
944
  ])
935
945
 
936
946
  // When
937
- const result = await getBlock(5_000_000)
947
+ const result = await getBlock(context, 5_000_000)
938
948
 
939
949
  // Then
940
950
  expect(result.transactions[0].fees).toBe(650n)
@@ -946,7 +956,7 @@ describe('delegation operations', () => {
946
956
  mockFetchBlockDelegations.mockResolvedValue([makeDelegation({ status: 'failed' })])
947
957
 
948
958
  // When
949
- const result = await getBlock(5_000_000)
959
+ const result = await getBlock(context, 5_000_000)
950
960
 
951
961
  // Then — failed but operations still present (listOperations path always includes them)
952
962
  expect(result.transactions[0].failed).toBe(true)
@@ -962,7 +972,7 @@ describe('delegation operations', () => {
962
972
  ])
963
973
 
964
974
  // When
965
- const result = await getBlock(5_000_000)
975
+ const result = await getBlock(context, 5_000_000)
966
976
 
967
977
  // Then
968
978
  expect(result.transactions).toHaveLength(1)
@@ -975,7 +985,7 @@ describe('delegation operations', () => {
975
985
  mockFetchBlockDelegations.mockResolvedValue([makeDelegation({ sender: null })])
976
986
 
977
987
  // When
978
- const result = await getBlock(5_000_000)
988
+ const result = await getBlock(context, 5_000_000)
979
989
 
980
990
  // Then
981
991
  expect(result.transactions).toHaveLength(1)
@@ -993,7 +1003,7 @@ describe('delegation operations', () => {
993
1003
  ])
994
1004
 
995
1005
  // When
996
- const result = await getBlock(5_000_000)
1006
+ const result = await getBlock(context, 5_000_000)
997
1007
 
998
1008
  // Then - single BlockTransaction with both transfer and delegation operations, combined fees
999
1009
  expect(result.transactions).toHaveLength(1)
@@ -1014,7 +1024,7 @@ describe('delegation operations', () => {
1014
1024
  ])
1015
1025
 
1016
1026
  // When
1017
- const result = await getBlock(5_000_000)
1027
+ const result = await getBlock(context, 5_000_000)
1018
1028
 
1019
1029
  // Then - the whole batch is marked as failed, operations cleared, fees accumulated
1020
1030
  expect(result.transactions).toMatchObject([{ failed: true, operations: [], fees: 800n }])
@@ -1031,7 +1041,7 @@ describe('delegation operations', () => {
1031
1041
  ])
1032
1042
 
1033
1043
  // When
1034
- const result = await getBlock(5_000_000)
1044
+ const result = await getBlock(context, 5_000_000)
1035
1045
 
1036
1046
  // Then - no operations (tx was failed), but fees still accumulated
1037
1047
  expect(result.transactions).toMatchObject([{ failed: true, operations: [], fees: 1000n }])
@@ -1044,7 +1054,7 @@ describe('delegation operations', () => {
1044
1054
  mockFetchBlockDelegations.mockResolvedValue([makeDelegation({ hash: 'opDelegation1' })])
1045
1055
 
1046
1056
  // When
1047
- const result = await getBlock(5_000_000)
1057
+ const result = await getBlock(context, 5_000_000)
1048
1058
 
1049
1059
  // Then
1050
1060
  expect(result.transactions).toHaveLength(2)
@@ -1059,7 +1069,7 @@ describe('delegation operations', () => {
1059
1069
  mockFetchBlockDelegations.mockResolvedValue([makeDelegation({ status: undefined })])
1060
1070
 
1061
1071
  // When
1062
- const result = await getBlock(5_000_000)
1072
+ const result = await getBlock(context, 5_000_000)
1063
1073
 
1064
1074
  // Then
1065
1075
  expect(result.transactions[0].failed).toBe(false)
@@ -1072,7 +1082,7 @@ describe('delegation operations', () => {
1072
1082
  mockFetchBlockDelegations.mockResolvedValue([makeDelegation({ sender: null })])
1073
1083
 
1074
1084
  // When
1075
- const result = await getBlock(5_000_000)
1085
+ const result = await getBlock(context, 5_000_000)
1076
1086
 
1077
1087
  // Then
1078
1088
  expect(result.transactions[0].feesPayer).toBeUndefined()
@@ -1086,7 +1096,7 @@ describe('delegation operations', () => {
1086
1096
  ])
1087
1097
 
1088
1098
  // When
1089
- const result = await getBlock(5_000_000)
1099
+ const result = await getBlock(context, 5_000_000)
1090
1100
 
1091
1101
  // Then
1092
1102
  const op = result.transactions[0].operations[0] as Record<string, unknown>
@@ -1112,7 +1122,7 @@ describe('staking operations', () => {
1112
1122
  makeStaking({ action, amount: Number(expectedStakedAmount) }),
1113
1123
  ])
1114
1124
 
1115
- const result = await getBlock(5_000_000)
1125
+ const result = await getBlock(context, 5_000_000)
1116
1126
 
1117
1127
  expect(result.transactions).toHaveLength(1)
1118
1128
  const tx = result.transactions[0]
@@ -1140,7 +1150,7 @@ describe('staking operations', () => {
1140
1150
  makeStaking({ status: 'failed', amount: undefined, requestedAmount: 750_000_000 }),
1141
1151
  ])
1142
1152
 
1143
- const result = await getBlock(5_000_000)
1153
+ const result = await getBlock(context, 5_000_000)
1144
1154
 
1145
1155
  expect(result.transactions[0].failed).toBe(true)
1146
1156
  expect(result.transactions[0].operations).toHaveLength(1)
@@ -1152,7 +1162,7 @@ describe('staking operations', () => {
1152
1162
  mockGetBlockByLevel.mockResolvedValue(makeBlock())
1153
1163
  mockFetchBlockStaking.mockResolvedValue([makeStaking({ sender: null })])
1154
1164
 
1155
- const result = await getBlock(5_000_000)
1165
+ const result = await getBlock(context, 5_000_000)
1156
1166
 
1157
1167
  expect(result.transactions).toHaveLength(1)
1158
1168
  expect(result.transactions[0].operations).toEqual([])
@@ -1165,7 +1175,7 @@ describe('staking operations', () => {
1165
1175
  makeStaking({ id: 301, hash: 'opStaking2' }),
1166
1176
  ])
1167
1177
 
1168
- const result = await getBlock(5_000_000)
1178
+ const result = await getBlock(context, 5_000_000)
1169
1179
 
1170
1180
  expect(result.transactions).toHaveLength(1)
1171
1181
  expect(result.transactions[0].hash).toBe('opStaking2')
@@ -1180,7 +1190,7 @@ describe('staking operations', () => {
1180
1190
  makeStaking({ hash: 'opShared', action: 'stake', amount: 100, bakerFee: 300 }),
1181
1191
  ])
1182
1192
 
1183
- const result = await getBlock(5_000_000)
1193
+ const result = await getBlock(context, 5_000_000)
1184
1194
 
1185
1195
  expect(result.transactions).toHaveLength(1)
1186
1196
  const tx = result.transactions[0]
@@ -1193,7 +1203,7 @@ describe('staking operations', () => {
1193
1203
  mockGetBlockByLevel.mockResolvedValue(makeBlock())
1194
1204
  mockFetchBlockStaking.mockResolvedValue([makeStaking({ baker: null })])
1195
1205
 
1196
- const result = await getBlock(5_000_000)
1206
+ const result = await getBlock(context, 5_000_000)
1197
1207
 
1198
1208
  const op = result.transactions[0].operations[0] as Record<string, unknown>
1199
1209
  expect(op).not.toHaveProperty('delegate')
@@ -1212,7 +1222,7 @@ describe('origination operations', () => {
1212
1222
  makeOrigination({ contractBalance: 0, counter: 42, gasLimit: 3494, storageLimit: 5852 }),
1213
1223
  ])
1214
1224
 
1215
- const result = await getBlock(5_000_000)
1225
+ const result = await getBlock(context, 5_000_000)
1216
1226
 
1217
1227
  expect(result.transactions).toHaveLength(1)
1218
1228
  const tx = result.transactions[0]
@@ -1236,7 +1246,7 @@ describe('origination operations', () => {
1236
1246
  mockGetBlockByLevel.mockResolvedValue(makeBlock())
1237
1247
  mockFetchBlockOriginations.mockResolvedValue([makeOrigination({ contractBalance: 500_000 })])
1238
1248
 
1239
- const result = await getBlock(5_000_000)
1249
+ const result = await getBlock(context, 5_000_000)
1240
1250
 
1241
1251
  expect(result.transactions).toHaveLength(1)
1242
1252
  const tx = result.transactions[0]
@@ -1252,7 +1262,7 @@ describe('origination operations', () => {
1252
1262
  mockGetBlockByLevel.mockResolvedValue(makeBlock())
1253
1263
  mockFetchBlockOriginations.mockResolvedValue([makeOrigination({ contractBalance: -500 })])
1254
1264
 
1255
- const result = await getBlock(5_000_000)
1265
+ const result = await getBlock(context, 5_000_000)
1256
1266
 
1257
1267
  expect(result.transactions[0].operations[0]).not.toHaveProperty('amount')
1258
1268
  })
@@ -1263,7 +1273,7 @@ describe('origination operations', () => {
1263
1273
  makeOrigination({ status: 'failed', contractBalance: 500_000 }),
1264
1274
  ])
1265
1275
 
1266
- const result = await getBlock(5_000_000)
1276
+ const result = await getBlock(context, 5_000_000)
1267
1277
 
1268
1278
  expect(result.transactions).toHaveLength(1)
1269
1279
  const tx = result.transactions[0]
@@ -1276,7 +1286,7 @@ describe('origination operations', () => {
1276
1286
  mockGetBlockByLevel.mockResolvedValue(makeBlock())
1277
1287
  mockFetchBlockOriginations.mockResolvedValue([makeOrigination({ hash: undefined })])
1278
1288
 
1279
- const result = await getBlock(5_000_000)
1289
+ const result = await getBlock(context, 5_000_000)
1280
1290
  expect(result.transactions).toHaveLength(0)
1281
1291
  })
1282
1292
 
@@ -1286,7 +1296,7 @@ describe('origination operations', () => {
1286
1296
  makeOrigination({ sender: null, contractBalance: 100_000 }),
1287
1297
  ])
1288
1298
 
1289
- const result = await getBlock(5_000_000)
1299
+ const result = await getBlock(context, 5_000_000)
1290
1300
 
1291
1301
  expect(result.transactions).toHaveLength(1)
1292
1302
  const tx = result.transactions[0]
@@ -1303,7 +1313,7 @@ describe('origination operations', () => {
1303
1313
  makeTokenTransfer({ transactionId: undefined, originationId: 400, amount: '1000' }),
1304
1314
  ])
1305
1315
 
1306
- const result = await getBlock(5_000_000)
1316
+ const result = await getBlock(context, 5_000_000)
1307
1317
 
1308
1318
  // origination tx should contain both the native transfer and the token ops
1309
1319
  const origTx = result.transactions.find((t) => t.hash === 'opOrig1')!
@@ -1324,7 +1334,7 @@ describe('origination operations', () => {
1324
1334
  { id: 999, hash: 'opCrossBlockOrig', block: 'BLsomeOtherBlock' },
1325
1335
  ])
1326
1336
 
1327
- const result = await getBlock(5_000_000)
1337
+ const result = await getBlock(context, 5_000_000)
1328
1338
 
1329
1339
  // The token transfer should use the resolved origination hash, not "token-50"
1330
1340
  expect(mockGetOperationsOrigination).toHaveBeenCalledWith(0, undefined, { 'id.in': '999' })
@@ -1344,7 +1354,7 @@ describe('reveal operations', () => {
1344
1354
  makeReveal({ counter: 10, gasLimit: 10600, storageLimit: 0, bakerFee: 1420 }),
1345
1355
  ])
1346
1356
 
1347
- const result = await getBlock(5_000_000)
1357
+ const result = await getBlock(context, 5_000_000)
1348
1358
 
1349
1359
  expect(result.transactions).toHaveLength(1)
1350
1360
  const tx = result.transactions[0]
@@ -1372,7 +1382,7 @@ describe('reveal operations', () => {
1372
1382
  makeReveal({ hash: 'opBatchedHash', bakerFee: 1420, sender: { address: 'tz1User' } }),
1373
1383
  ])
1374
1384
 
1375
- const result = await getBlock(5_000_000)
1385
+ const result = await getBlock(context, 5_000_000)
1376
1386
 
1377
1387
  expect(result.transactions).toHaveLength(1)
1378
1388
  const tx = result.transactions[0]
@@ -1386,7 +1396,7 @@ describe('reveal operations', () => {
1386
1396
  mockGetBlockByLevel.mockResolvedValue(makeBlock())
1387
1397
  mockFetchBlockReveals.mockResolvedValue([makeReveal({ status: 'failed' })])
1388
1398
 
1389
- const result = await getBlock(5_000_000)
1399
+ const result = await getBlock(context, 5_000_000)
1390
1400
 
1391
1401
  expect(result.transactions[0].failed).toBe(true)
1392
1402
  expect(result.transactions[0].operations).toHaveLength(1)
@@ -1399,7 +1409,7 @@ describe('reveal operations', () => {
1399
1409
  makeReveal({ id: 501, hash: 'opReveal2' }),
1400
1410
  ])
1401
1411
 
1402
- const result = await getBlock(5_000_000)
1412
+ const result = await getBlock(context, 5_000_000)
1403
1413
 
1404
1414
  expect(result.transactions).toHaveLength(1)
1405
1415
  expect(result.transactions[0].hash).toBe('opReveal2')
@@ -1412,7 +1422,7 @@ describe('reveal operations', () => {
1412
1422
  ])
1413
1423
  mockFetchBlockReveals.mockResolvedValue([makeReveal({ hash: 'opBatchedHash', bakerFee: 1420 })])
1414
1424
 
1415
- const result = await getBlock(5_000_000)
1425
+ const result = await getBlock(context, 5_000_000)
1416
1426
 
1417
1427
  expect(result.transactions).toHaveLength(1)
1418
1428
  const tx = result.transactions[0]
@@ -1425,7 +1435,7 @@ describe('reveal operations', () => {
1425
1435
  mockGetBlockByLevel.mockResolvedValue(makeBlock())
1426
1436
  mockFetchBlockReveals.mockResolvedValue([makeReveal({ sender: null })])
1427
1437
 
1428
- const result = await getBlock(5_000_000)
1438
+ const result = await getBlock(context, 5_000_000)
1429
1439
 
1430
1440
  expect(result.transactions).toHaveLength(1)
1431
1441
  expect(result.transactions[0].operations).toEqual([])
@@ -1443,24 +1453,24 @@ describe('network calls', () => {
1443
1453
  mockGetBlockByLevel.mockResolvedValue(makeBlock(height))
1444
1454
 
1445
1455
  // When
1446
- await getBlock(height)
1456
+ await getBlock(context, height)
1447
1457
 
1448
1458
  // Then – getBlockByLevel is called once for the block and once for the parent
1449
1459
  expect(mockGetBlockByLevel).toHaveBeenCalledTimes(2)
1450
1460
  expect(mockGetBlockByLevel).toHaveBeenCalledWith(height)
1451
1461
  expect(mockGetBlockByLevel).toHaveBeenCalledWith(height - 1)
1452
1462
  expect(mockFetchBlockTransactions).toHaveBeenCalledTimes(1)
1453
- expect(mockFetchBlockTransactions).toHaveBeenCalledWith(height)
1463
+ expect(mockFetchBlockTransactions).toHaveBeenCalledWith(expect.anything(), height)
1454
1464
  expect(mockFetchBlockTokenTransfers).toHaveBeenCalledTimes(1)
1455
- expect(mockFetchBlockTokenTransfers).toHaveBeenCalledWith(height)
1465
+ expect(mockFetchBlockTokenTransfers).toHaveBeenCalledWith(expect.anything(), height)
1456
1466
  expect(mockFetchBlockDelegations).toHaveBeenCalledTimes(1)
1457
- expect(mockFetchBlockDelegations).toHaveBeenCalledWith(height)
1467
+ expect(mockFetchBlockDelegations).toHaveBeenCalledWith(expect.anything(), height)
1458
1468
  expect(mockFetchBlockStaking).toHaveBeenCalledTimes(1)
1459
- expect(mockFetchBlockStaking).toHaveBeenCalledWith(height)
1469
+ expect(mockFetchBlockStaking).toHaveBeenCalledWith(expect.anything(), height)
1460
1470
  expect(mockFetchBlockOriginations).toHaveBeenCalledTimes(1)
1461
- expect(mockFetchBlockOriginations).toHaveBeenCalledWith(height)
1471
+ expect(mockFetchBlockOriginations).toHaveBeenCalledWith(expect.anything(), height)
1462
1472
  expect(mockFetchBlockReveals).toHaveBeenCalledTimes(1)
1463
- expect(mockFetchBlockReveals).toHaveBeenCalledWith(height)
1473
+ expect(mockFetchBlockReveals).toHaveBeenCalledWith(expect.anything(), height)
1464
1474
  })
1465
1475
 
1466
1476
  it('propagates errors from getBlockByLevel', async () => {
@@ -1468,7 +1478,7 @@ describe('network calls', () => {
1468
1478
  mockGetBlockByLevel.mockRejectedValue(new Error('block fetch failed'))
1469
1479
 
1470
1480
  // When / Then
1471
- await expect(getBlock(1_000_000)).rejects.toThrow('block fetch failed')
1481
+ await expect(getBlock(context, 1_000_000)).rejects.toThrow('block fetch failed')
1472
1482
  })
1473
1483
 
1474
1484
  it('propagates errors from fetchBlockTransactions', async () => {
@@ -1477,7 +1487,7 @@ describe('network calls', () => {
1477
1487
  mockFetchBlockTransactions.mockRejectedValue(new Error('tx fetch failed'))
1478
1488
 
1479
1489
  // When / Then
1480
- await expect(getBlock(1_000_000)).rejects.toThrow('tx fetch failed')
1490
+ await expect(getBlock(context, 1_000_000)).rejects.toThrow('tx fetch failed')
1481
1491
  })
1482
1492
 
1483
1493
  it('propagates errors from fetchBlockTokenTransfers', async () => {
@@ -1486,7 +1496,7 @@ describe('network calls', () => {
1486
1496
  mockFetchBlockTokenTransfers.mockRejectedValue(new Error('token fetch failed'))
1487
1497
 
1488
1498
  // When / Then
1489
- await expect(getBlock(1_000_000)).rejects.toThrow('token fetch failed')
1499
+ await expect(getBlock(context, 1_000_000)).rejects.toThrow('token fetch failed')
1490
1500
  })
1491
1501
 
1492
1502
  it('propagates errors from fetchBlockDelegations', async () => {
@@ -1495,6 +1505,6 @@ describe('network calls', () => {
1495
1505
  mockFetchBlockDelegations.mockRejectedValue(new Error('delegation fetch failed'))
1496
1506
 
1497
1507
  // When / Then
1498
- await expect(getBlock(1_000_000)).rejects.toThrow('delegation fetch failed')
1508
+ await expect(getBlock(context, 1_000_000)).rejects.toThrow('delegation fetch failed')
1499
1509
  })
1500
1510
  })