@ledgerhq/coin-tezos 10.2.0 → 10.2.2

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 (79) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/lib/api/index.d.ts +1 -1
  3. package/lib/api/index.d.ts.map +1 -1
  4. package/lib/api/index.js +1 -1
  5. package/lib/api/index.js.map +1 -1
  6. package/lib/logic/craftRawOperations.js +26 -17
  7. package/lib/logic/craftRawOperations.js.map +1 -1
  8. package/lib/logic/estimateFees.js +4 -4
  9. package/lib/logic/estimateFees.js.map +1 -1
  10. package/lib/logic/listOperations.d.ts.map +1 -1
  11. package/lib/logic/listOperations.js +9 -7
  12. package/lib/logic/listOperations.js.map +1 -1
  13. package/lib/logic/validateIntent.d.ts.map +1 -1
  14. package/lib/logic/validateIntent.js +26 -8
  15. package/lib/logic/validateIntent.js.map +1 -1
  16. package/lib/network/tzkt.js +1 -1
  17. package/lib/network/tzkt.js.map +1 -1
  18. package/lib/test/config.d.ts +2 -22
  19. package/lib/test/config.d.ts.map +1 -1
  20. package/lib/test/config.js.map +1 -1
  21. package/lib/utils.d.ts +0 -3
  22. package/lib/utils.d.ts.map +1 -1
  23. package/lib/utils.js +17 -3
  24. package/lib/utils.js.map +1 -1
  25. package/lib-es/api/index.d.ts +1 -1
  26. package/lib-es/api/index.d.ts.map +1 -1
  27. package/lib-es/api/index.js +1 -1
  28. package/lib-es/api/index.js.map +1 -1
  29. package/lib-es/logic/craftRawOperations.js +26 -17
  30. package/lib-es/logic/craftRawOperations.js.map +1 -1
  31. package/lib-es/logic/estimateFees.js +4 -4
  32. package/lib-es/logic/estimateFees.js.map +1 -1
  33. package/lib-es/logic/listOperations.d.ts.map +1 -1
  34. package/lib-es/logic/listOperations.js +9 -7
  35. package/lib-es/logic/listOperations.js.map +1 -1
  36. package/lib-es/logic/validateIntent.d.ts.map +1 -1
  37. package/lib-es/logic/validateIntent.js +27 -9
  38. package/lib-es/logic/validateIntent.js.map +1 -1
  39. package/lib-es/network/tzkt.js +1 -1
  40. package/lib-es/network/tzkt.js.map +1 -1
  41. package/lib-es/test/config.d.ts +2 -22
  42. package/lib-es/test/config.d.ts.map +1 -1
  43. package/lib-es/test/config.js.map +1 -1
  44. package/lib-es/utils.d.ts +0 -3
  45. package/lib-es/utils.d.ts.map +1 -1
  46. package/lib-es/utils.js +17 -3
  47. package/lib-es/utils.js.map +1 -1
  48. package/package.json +2 -2
  49. package/src/api/index-mainnet.integ.test.ts +40 -50
  50. package/src/api/index.integ.test.ts +60 -45
  51. package/src/api/index.test.ts +229 -180
  52. package/src/api/index.ts +5 -4
  53. package/src/logic/broadcast.integ.test.ts +2 -7
  54. package/src/logic/craftRawOperations.test.ts +11 -10
  55. package/src/logic/craftRawOperations.ts +35 -19
  56. package/src/logic/craftTransaction.integ.test.ts +2 -2
  57. package/src/logic/craftTransaction.test.ts +63 -95
  58. package/src/logic/estimateFees.integ.test.ts +19 -20
  59. package/src/logic/estimateFees.test.ts +30 -63
  60. package/src/logic/estimateFees.ts +4 -4
  61. package/src/logic/getBalance.test.ts +6 -6
  62. package/src/logic/getBlock.integ.test.ts +20 -21
  63. package/src/logic/getBlock.test.ts +44 -51
  64. package/src/logic/getBlockInfo.integ.test.ts +13 -14
  65. package/src/logic/getBlockInfo.test.ts +8 -7
  66. package/src/logic/getStakes.test.ts +17 -17
  67. package/src/logic/listOperations.integ.test.ts +40 -37
  68. package/src/logic/listOperations.test.ts +34 -31
  69. package/src/logic/listOperations.ts +19 -19
  70. package/src/logic/validateIntent.test.ts +145 -20
  71. package/src/logic/validateIntent.ts +32 -8
  72. package/src/network/bakers.integ.test.ts +1 -1
  73. package/src/network/bakers.test.ts +7 -15
  74. package/src/network/tzkt.integ.test.ts +13 -14
  75. package/src/network/tzkt.test.ts +194 -259
  76. package/src/network/tzkt.ts +1 -1
  77. package/src/test/config.ts +3 -1
  78. package/src/utils.ts +18 -3
  79. package/.oxlintrc.json +0 -20
@@ -3,8 +3,11 @@
3
3
 
4
4
  import type { TezosCoinConfig, TezosContext } from '../config'
5
5
  import type { APIAccount } from '../network/types'
6
- import type { BalanceOptions, Operation } from '@ledgerhq/coin-module-framework/api/types'
7
- import type { TransactionIntent } from '@ledgerhq/coin-module-framework/api/types'
6
+ import type { Operation } from '@ledgerhq/coin-module-framework/api/types'
7
+ import {
8
+ createSendTransactionIntentMockData,
9
+ createStakingTransactionIntentMockData,
10
+ } from '@ledgerhq/coin-module-framework/test-utils'
8
11
  import { createApi } from './index'
9
12
 
10
13
  // The tzkt factory `createTzktApi(config)` builds a fresh object on every call, so a spy on a
@@ -55,19 +58,20 @@ mockGetAccountByAddress.mockResolvedValue({
55
58
  delegationTime: '2021-01-01T00:00:00Z',
56
59
  numTransactions: 0,
57
60
  firstActivityTime: '2021-01-01T00:00:00Z',
58
- } as APIAccount)
61
+ })
59
62
 
60
63
  const api = createApi()
61
64
 
62
65
  /** Builds a TezosContext carrying the given coin config (see logic/getBalance.test.ts). */
63
- function makeContext(config: unknown): TezosContext {
66
+ function makeContext(config: TezosCoinConfig): TezosContext {
64
67
  return {
65
- config: async () => config as TezosCoinConfig,
68
+ config: async () => config,
66
69
  logger: () => undefined,
67
70
  }
68
71
  }
69
72
 
70
73
  const context = makeContext({
74
+ status: { type: 'active' },
71
75
  baker: {
72
76
  url: 'https://baker.example.com',
73
77
  },
@@ -178,13 +182,15 @@ describe('craftTransaction', () => {
178
182
  txFee: 500n,
179
183
  },
180
184
  })
181
- await api.craftTransaction(context, {
182
- intentType: 'transaction',
183
- type: 'send',
184
- sender: 'tz1test',
185
- recipient: 'tz1recipient',
186
- amount: 1000n,
187
- } as TransactionIntent)
185
+ await api.craftTransaction(
186
+ context,
187
+ createSendTransactionIntentMockData({
188
+ type: 'send',
189
+ sender: 'tz1test',
190
+ recipient: 'tz1recipient',
191
+ amount: 1000n,
192
+ })
193
+ )
188
194
  expect(logicEstimateFees).toHaveBeenCalledTimes(1)
189
195
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
190
196
  expect.anything(),
@@ -211,13 +217,15 @@ describe('craftTransaction', () => {
211
217
  txFee: 50n,
212
218
  },
213
219
  })
214
- await api.craftTransaction(context, {
215
- intentType: 'transaction',
216
- type: 'send',
217
- sender: 'tz1test',
218
- recipient: 'tz1recipient',
219
- amount: 1000n,
220
- } as TransactionIntent)
220
+ await api.craftTransaction(
221
+ context,
222
+ createSendTransactionIntentMockData({
223
+ type: 'send',
224
+ sender: 'tz1test',
225
+ recipient: 'tz1recipient',
226
+ amount: 1000n,
227
+ })
228
+ )
221
229
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
222
230
  expect.anything(),
223
231
  expect.any(Object),
@@ -243,13 +251,12 @@ describe('craftTransaction', () => {
243
251
  })
244
252
  await api.craftTransaction(
245
253
  context,
246
- {
247
- intentType: 'transaction',
254
+ createSendTransactionIntentMockData({
248
255
  type: 'send',
249
256
  sender: 'tz1test',
250
257
  recipient: 'tz1recipient',
251
258
  amount: 1000n,
252
- } as TransactionIntent,
259
+ }),
253
260
  { customFees: { value: customFee } }
254
261
  )
255
262
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
@@ -274,13 +281,12 @@ describe('craftTransaction', () => {
274
281
  })
275
282
  await api.craftTransaction(
276
283
  context,
277
- {
278
- intentType: 'transaction',
284
+ createSendTransactionIntentMockData({
279
285
  type: 'send',
280
286
  sender: 'tz1test',
281
287
  recipient: 'tz1recipient',
282
288
  amount: 1000n,
283
- } as TransactionIntent,
289
+ }),
284
290
  { customFees: { value: customFee } }
285
291
  )
286
292
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
@@ -299,6 +305,7 @@ describe('craftTransaction', () => {
299
305
  const totalCustomFee = BigInt(minFees * 2)
300
306
 
301
307
  const contextMinFees1000 = makeContext({
308
+ status: { type: 'active' },
302
309
  baker: { url: 'https://baker.example.com' },
303
310
  explorer: { url: 'foo', maxTxQuery: 1 },
304
311
  node: { url: 'bar' },
@@ -311,8 +318,8 @@ describe('craftTransaction', () => {
311
318
  },
312
319
  })
313
320
 
314
- const unrevealedAccount = {
315
- type: 'user' as const,
321
+ const unrevealedAccount: APIAccount = {
322
+ type: 'user',
316
323
  balance: 1000000,
317
324
  revealed: false,
318
325
  address: unrevealedSender,
@@ -322,7 +329,7 @@ describe('craftTransaction', () => {
322
329
  delegationTime: '2021-01-01T00:00:00Z',
323
330
  numTransactions: 0,
324
331
  firstActivityTime: '2021-01-01T00:00:00Z',
325
- } as APIAccount
332
+ }
326
333
  mockGetAccountByAddress
327
334
  .mockResolvedValueOnce(unrevealedAccount)
328
335
  .mockResolvedValueOnce(unrevealedAccount)
@@ -341,15 +348,15 @@ describe('craftTransaction', () => {
341
348
 
342
349
  await api.craftTransaction(
343
350
  contextMinFees1000,
344
- {
345
- intentType: 'staking',
351
+ createStakingTransactionIntentMockData({
346
352
  type: 'delegate',
353
+ mode: 'delegate',
347
354
  sender: unrevealedSender,
348
355
  senderPublicKey: '021bab48f41fc555e0fcf322a28e31b56f4369242f65324758ec8bbae3e84109a5',
349
356
  recipient: delegateRecipient,
350
- amount: 0n,
351
- } as TransactionIntent,
352
- { value: totalCustomFee }
357
+ valAddress: delegateRecipient,
358
+ }),
359
+ { customFees: { value: totalCustomFee } }
353
360
  )
354
361
 
355
362
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
@@ -375,13 +382,15 @@ describe('craftTransaction', () => {
375
382
  storageLimit: DEFAULT_STORAGE_LIMIT,
376
383
  })
377
384
 
378
- await api.craftTransaction(context, {
379
- intentType: 'staking',
380
- type,
381
- sender: 'tz1test',
382
- recipient: '',
383
- amount: 1234n,
384
- } as TransactionIntent)
385
+ await api.craftTransaction(
386
+ context,
387
+ createStakingTransactionIntentMockData({
388
+ type,
389
+ mode: 'delegate',
390
+ sender: 'tz1test',
391
+ amount: 1234n,
392
+ })
393
+ )
385
394
 
386
395
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
387
396
  expect.anything(),
@@ -402,13 +411,15 @@ describe('craftTransaction', () => {
402
411
  storageLimit: DEFAULT_STORAGE_LIMIT,
403
412
  })
404
413
 
405
- await api.craftTransaction(context, {
406
- intentType: 'staking',
407
- type: 'finalize_unstake',
408
- sender: 'tz1test',
409
- recipient: '',
410
- amount: 999n,
411
- } as TransactionIntent)
414
+ await api.craftTransaction(
415
+ context,
416
+ createStakingTransactionIntentMockData({
417
+ type: 'finalize_unstake',
418
+ mode: 'delegate',
419
+ sender: 'tz1test',
420
+ amount: 999n,
421
+ })
422
+ )
412
423
 
413
424
  expect(logicCraftTransactionMock).toHaveBeenCalledWith(
414
425
  expect.anything(),
@@ -432,13 +443,15 @@ describe('estimateFees', () => {
432
443
  gasLimit: DEFAULT_GAS_LIMIT,
433
444
  storageLimit: DEFAULT_STORAGE_LIMIT,
434
445
  })
435
- const result = await api.estimateFees(context, {
436
- intentType: 'transaction',
437
- type: 'send',
438
- sender: 'tz1test',
439
- recipient: 'tz1recipient',
440
- amount: 1000n,
441
- } as TransactionIntent)
446
+ const result = await api.estimateFees(
447
+ context,
448
+ createSendTransactionIntentMockData({
449
+ type: 'send',
450
+ sender: 'tz1test',
451
+ recipient: 'tz1recipient',
452
+ amount: 1000n,
453
+ })
454
+ )
442
455
  expect(result.value).toBe(estimatedFees)
443
456
  expect(result.parameters?.gasLimit).toBe(DEFAULT_GAS_LIMIT)
444
457
  expect(result.parameters?.storageLimit).toBe(DEFAULT_STORAGE_LIMIT)
@@ -451,13 +464,15 @@ describe('estimateFees', () => {
451
464
  gasLimit: DEFAULT_GAS_LIMIT,
452
465
  storageLimit: DEFAULT_STORAGE_LIMIT,
453
466
  })
454
- const result = await api.estimateFees(context, {
455
- intentType: 'transaction',
456
- type: 'send',
457
- sender: 'tz1test',
458
- recipient: 'tz1recipient',
459
- amount: 1000n,
460
- } as TransactionIntent)
467
+ const result = await api.estimateFees(
468
+ context,
469
+ createSendTransactionIntentMockData({
470
+ type: 'send',
471
+ sender: 'tz1test',
472
+ recipient: 'tz1recipient',
473
+ amount: 1000n,
474
+ })
475
+ )
461
476
  expect(result.value).toBe(estimatedFees)
462
477
  expect(result.parameters?.gasLimit).toBe(DEFAULT_GAS_LIMIT)
463
478
  expect(result.parameters?.storageLimit).toBe(DEFAULT_STORAGE_LIMIT)
@@ -470,13 +485,15 @@ describe('estimateFees', () => {
470
485
  gasLimit: DEFAULT_GAS_LIMIT,
471
486
  storageLimit: DEFAULT_STORAGE_LIMIT,
472
487
  })
473
- const result = await api.estimateFees(context, {
474
- intentType: 'transaction',
475
- type: 'send',
476
- sender: 'tz1test',
477
- recipient: 'tz1recipient',
478
- amount: 1000n,
479
- } as TransactionIntent)
488
+ const result = await api.estimateFees(
489
+ context,
490
+ createSendTransactionIntentMockData({
491
+ type: 'send',
492
+ sender: 'tz1test',
493
+ recipient: 'tz1recipient',
494
+ amount: 1000n,
495
+ })
496
+ )
480
497
  expect(result).toEqual({
481
498
  value: DEFAULT_ESTIMATED_FEES,
482
499
  parameters: {
@@ -508,14 +525,16 @@ describe('estimateFees', () => {
508
525
  amount: 500n,
509
526
  })
510
527
 
511
- await api.estimateFees(context, {
512
- intentType: 'transaction',
513
- type: 'send',
514
- sender: 'tz1test',
515
- recipient: 'tz1recipient',
516
- amount: 0n,
517
- useAllAmount: true,
518
- } as TransactionIntent)
528
+ await api.estimateFees(
529
+ context,
530
+ createSendTransactionIntentMockData({
531
+ type: 'send',
532
+ sender: 'tz1test',
533
+ recipient: 'tz1recipient',
534
+ amount: 0n,
535
+ useAllAmount: true,
536
+ })
537
+ )
519
538
 
520
539
  expect(logicEstimateFees).toHaveBeenCalledWith(
521
540
  expect.anything(),
@@ -533,13 +552,15 @@ describe('estimateFees', () => {
533
552
  taquitoError: 'test',
534
553
  })
535
554
  await expect(
536
- api.estimateFees(context, {
537
- intentType: 'transaction',
538
- type: 'send',
539
- sender: 'tz1test',
540
- recipient: 'tz1recipient',
541
- amount: 1000n,
542
- } as TransactionIntent)
555
+ api.estimateFees(
556
+ context,
557
+ createSendTransactionIntentMockData({
558
+ type: 'send',
559
+ sender: 'tz1test',
560
+ recipient: 'tz1recipient',
561
+ amount: 1000n,
562
+ })
563
+ )
543
564
  ).rejects.toThrow('Fees estimation failed: test')
544
565
  })
545
566
 
@@ -557,7 +578,7 @@ describe('estimateFees', () => {
557
578
  recipient: 'tz1recipient',
558
579
  amount: 1000n,
559
580
  asset: { type: 'token', assetReference: 'KT1CpeSQKdkhWi4pinYcseCFKmDhs5M74BkU:0' },
560
- } as TransactionIntent)
581
+ })
561
582
  expect(result.value).toBe(DEFAULT_ESTIMATED_FEES)
562
583
  expect(result.parameters?.gasLimit).toBe(DEFAULT_GAS_LIMIT)
563
584
  expect(result.parameters?.storageLimit).toBe(DEFAULT_STORAGE_LIMIT)
@@ -570,13 +591,17 @@ describe('estimateFees', () => {
570
591
  storageLimit: DEFAULT_STORAGE_LIMIT,
571
592
  taquitoError: 'proto.022-PsRiotum.delegate.unchanged',
572
593
  })
573
- const result = await api.estimateFees(context, {
574
- intentType: 'staking',
575
- type: 'delegate',
576
- sender: 'tz1test',
577
- recipient: 'tz1validator',
578
- amount: 0n,
579
- } as TransactionIntent)
594
+ const result = await api.estimateFees(
595
+ context,
596
+ createStakingTransactionIntentMockData({
597
+ type: 'delegate',
598
+ mode: 'delegate',
599
+ sender: 'tz1test',
600
+ recipient: 'tz1validator',
601
+ amount: 0n,
602
+ valAddress: 'tz1validator',
603
+ })
604
+ )
580
605
 
581
606
  expect(result).toEqual({
582
607
  value: DEFAULT_ESTIMATED_FEES,
@@ -595,13 +620,17 @@ describe('estimateFees', () => {
595
620
  taquitoError:
596
621
  'proto.alpha.cannot_stake_with_unfinalizable_unstake_requests_to_another_delegate',
597
622
  })
598
- const result = await api.estimateFees(context, {
599
- intentType: 'staking',
600
- type: 'stake',
601
- sender: 'tz1test',
602
- recipient: 'tz1validator',
603
- amount: 1000n,
604
- } as TransactionIntent)
623
+ const result = await api.estimateFees(
624
+ context,
625
+ createStakingTransactionIntentMockData({
626
+ type: 'stake',
627
+ mode: 'delegate',
628
+ sender: 'tz1test',
629
+ recipient: 'tz1validator',
630
+ amount: 1000n,
631
+ valAddress: 'tz1validator',
632
+ })
633
+ )
605
634
 
606
635
  expect(result).toEqual({
607
636
  value: DEFAULT_ESTIMATED_FEES,
@@ -625,7 +654,7 @@ describe('estimateFees', () => {
625
654
  delegationTime: '2021-01-01T00:00:00Z',
626
655
  numTransactions: 0,
627
656
  firstActivityTime: '2021-01-01T00:00:00Z',
628
- } as APIAccount)
657
+ })
629
658
 
630
659
  const expectedTotalFees = 2000n
631
660
  logicEstimateFees.mockResolvedValue({
@@ -635,17 +664,23 @@ describe('estimateFees', () => {
635
664
  storageLimit: DEFAULT_STORAGE_LIMIT,
636
665
  })
637
666
 
638
- const result = await api.estimateFees(context, {
639
- intentType: 'staking',
640
- type: 'delegate',
641
- sender: unrevealedSender,
642
- recipient: 'tz3Vq38qYD3GEbWcXHMLt5PaASZrkDtEiA8D',
643
- amount: 0n,
644
- } as TransactionIntent)
667
+ const result = await api.estimateFees(
668
+ context,
669
+ createStakingTransactionIntentMockData({
670
+ type: 'delegate',
671
+ mode: 'delegate',
672
+ sender: unrevealedSender,
673
+ recipient: 'tz3Vq38qYD3GEbWcXHMLt5PaASZrkDtEiA8D',
674
+ amount: 0n,
675
+ valAddress: 'tz3Vq38qYD3GEbWcXHMLt5PaASZrkDtEiA8D',
676
+ })
677
+ )
645
678
 
646
679
  expect(result.value).toBe(expectedTotalFees)
647
- expect(result.parameters.gasLimit).toBe(DEFAULT_GAS_LIMIT)
648
- expect(result.parameters.storageLimit).toBe(DEFAULT_STORAGE_LIMIT)
680
+ expect(result.parameters).toMatchObject({
681
+ gasLimit: DEFAULT_GAS_LIMIT,
682
+ storageLimit: DEFAULT_STORAGE_LIMIT,
683
+ })
649
684
  })
650
685
 
651
686
  it.each([
@@ -660,13 +695,15 @@ describe('estimateFees', () => {
660
695
  storageLimit: DEFAULT_STORAGE_LIMIT,
661
696
  })
662
697
 
663
- const result = await api.estimateFees(context, {
664
- intentType: 'staking',
665
- type,
666
- sender: 'tz1test',
667
- recipient: '',
668
- amount: intentAmount,
669
- } as TransactionIntent)
698
+ const result = await api.estimateFees(
699
+ context,
700
+ createStakingTransactionIntentMockData({
701
+ type,
702
+ mode: 'delegate',
703
+ sender: 'tz1test',
704
+ amount: intentAmount,
705
+ })
706
+ )
670
707
 
671
708
  expect(result.value).toBe(DEFAULT_ESTIMATED_FEES)
672
709
  expect(logicEstimateFees).toHaveBeenCalledWith(
@@ -686,6 +723,7 @@ describe('estimateFees', () => {
686
723
  const minFees = 1000
687
724
 
688
725
  const contextMinFees1000 = makeContext({
726
+ status: { type: 'active' },
689
727
  baker: { url: 'https://baker.example.com' },
690
728
  explorer: { url: 'foo', maxTxQuery: 1 },
691
729
  node: { url: 'bar' },
@@ -700,8 +738,8 @@ describe('estimateFees', () => {
700
738
 
701
739
  logicEstimateFees.mockImplementation(() => Promise.reject(new Error('Public key not found')))
702
740
 
703
- const defaultUserForTry = {
704
- type: 'user' as const,
741
+ const defaultUserForTry: APIAccount = {
742
+ type: 'user',
705
743
  balance: 1000,
706
744
  revealed: true,
707
745
  address: unrevealedSender,
@@ -711,19 +749,20 @@ describe('estimateFees', () => {
711
749
  delegationTime: '2021-01-01T00:00:00Z',
712
750
  numTransactions: 0,
713
751
  firstActivityTime: '2021-01-01T00:00:00Z',
714
- } as APIAccount
715
- const recipientAccount = {
716
- type: 'user' as const,
752
+ }
753
+ const recipientAccount: APIAccount = {
754
+ type: 'user',
717
755
  balance: 1000000,
756
+ revealed: true,
718
757
  address: delegateRecipient,
719
758
  counter: 0,
720
759
  delegationLevel: 0,
721
760
  delegationTime: '2021-01-01T00:00:00Z',
722
761
  numTransactions: 0,
723
762
  firstActivityTime: '2021-01-01T00:00:00Z',
724
- } as APIAccount
725
- const senderUnrevealedAccount = {
726
- type: 'user' as const,
763
+ }
764
+ const senderUnrevealedAccount: APIAccount = {
765
+ type: 'user',
727
766
  balance: 1000000,
728
767
  revealed: false,
729
768
  address: unrevealedSender,
@@ -733,7 +772,7 @@ describe('estimateFees', () => {
733
772
  delegationTime: '2021-01-01T00:00:00Z',
734
773
  numTransactions: 0,
735
774
  firstActivityTime: '2021-01-01T00:00:00Z',
736
- } as APIAccount
775
+ }
737
776
  mockGetAccountByAddress
738
777
  .mockImplementationOnce(() => Promise.resolve(defaultUserForTry))
739
778
  .mockImplementationOnce(() => Promise.resolve(recipientAccount))
@@ -751,13 +790,17 @@ describe('estimateFees', () => {
751
790
  },
752
791
  })
753
792
 
754
- const result = await api.estimateFees(contextMinFees1000, {
755
- intentType: 'staking',
756
- type: 'delegate',
757
- sender: unrevealedSender,
758
- recipient: delegateRecipient,
759
- amount: 0n,
760
- } as TransactionIntent)
793
+ const result = await api.estimateFees(
794
+ contextMinFees1000,
795
+ createStakingTransactionIntentMockData({
796
+ type: 'delegate',
797
+ mode: 'delegate',
798
+ sender: unrevealedSender,
799
+ recipient: delegateRecipient,
800
+ amount: 0n,
801
+ valAddress: delegateRecipient,
802
+ })
803
+ )
761
804
 
762
805
  expect(result.value).toBe(2000n)
763
806
  expect(result.parameters?.txFee).toBe(1000n)
@@ -772,6 +815,7 @@ describe('estimateFees', () => {
772
815
  // baseTxFee = max(minFees=1, ceil(120 + 0.1*2500 + 154)) = max(1, 524) = 524
773
816
  // createApi here to reset the global coinConfig to minFees=1 (other tests may leave it at a higher value)
774
817
  const contextLowMinFees = makeContext({
818
+ status: { type: 'active' },
775
819
  baker: { url: 'https://baker.example.com' },
776
820
  explorer: { url: 'foo', maxTxQuery: 1 },
777
821
  node: { url: 'bar' },
@@ -786,8 +830,8 @@ describe('estimateFees', () => {
786
830
  const revealedSender = 'tz1test'
787
831
  const recipient = 'tz2recipient'
788
832
 
789
- const revealedAccount = {
790
- type: 'user' as const,
833
+ const revealedAccount: APIAccount = {
834
+ type: 'user',
791
835
  balance: 1000000,
792
836
  revealed: true,
793
837
  address: revealedSender,
@@ -797,9 +841,9 @@ describe('estimateFees', () => {
797
841
  delegationTime: '2021-01-01T00:00:00Z',
798
842
  numTransactions: 0,
799
843
  firstActivityTime: '2021-01-01T00:00:00Z',
800
- } as APIAccount
801
- const recipientAccount = {
802
- type: 'user' as const,
844
+ }
845
+ const recipientAccount: APIAccount = {
846
+ type: 'user',
803
847
  balance: 1000000,
804
848
  revealed: true,
805
849
  address: recipient,
@@ -809,8 +853,7 @@ describe('estimateFees', () => {
809
853
  delegationTime: '2021-01-01T00:00:00Z',
810
854
  numTransactions: 0,
811
855
  firstActivityTime: '2021-01-01T00:00:00Z',
812
- } as APIAccount
813
-
856
+ }
814
857
  mockGetAccountByAddress
815
858
  .mockResolvedValueOnce(revealedAccount) // initial sender lookup
816
859
  .mockResolvedValueOnce(recipientAccount) // recipient lookup in catch block
@@ -824,13 +867,15 @@ describe('estimateFees', () => {
824
867
  },
825
868
  })
826
869
 
827
- const result = await api.estimateFees(contextLowMinFees, {
828
- intentType: 'transaction',
829
- type: 'send',
830
- sender: revealedSender,
831
- recipient,
832
- amount: 1000n,
833
- } as TransactionIntent)
870
+ const result = await api.estimateFees(
871
+ contextLowMinFees,
872
+ createSendTransactionIntentMockData({
873
+ type: 'send',
874
+ sender: revealedSender,
875
+ recipient,
876
+ amount: 1000n,
877
+ })
878
+ )
834
879
 
835
880
  // No reveal needed → revealFee = 0 → total = baseTxFee = 524
836
881
  expect(result.value).toBe(524n)
@@ -846,6 +891,7 @@ describe('estimateFees', () => {
846
891
  // revealFee = max(0, getRevealFee(tz2address)) — tz2 addresses have a non-zero reveal fee
847
892
  // createApi here to reset the global coinConfig to minFees=1 (other tests may leave it at a higher value)
848
893
  const contextLowMinFees = makeContext({
894
+ status: { type: 'active' },
849
895
  baker: { url: 'https://baker.example.com' },
850
896
  explorer: { url: 'foo', maxTxQuery: 1 },
851
897
  node: { url: 'bar' },
@@ -860,8 +906,8 @@ describe('estimateFees', () => {
860
906
  const unrevealedSender = 'tz2TaTpo31sAiX2HBJUTLLdUnqVJR4QjLy1V'
861
907
  const recipient = 'tz1recipient'
862
908
 
863
- const unrevealedAccount = {
864
- type: 'user' as const,
909
+ const unrevealedAccount: APIAccount = {
910
+ type: 'user',
865
911
  balance: 1000000,
866
912
  revealed: false,
867
913
  address: unrevealedSender,
@@ -871,9 +917,9 @@ describe('estimateFees', () => {
871
917
  delegationTime: '2021-01-01T00:00:00Z',
872
918
  numTransactions: 0,
873
919
  firstActivityTime: '2021-01-01T00:00:00Z',
874
- } as APIAccount
875
- const recipientAccount = {
876
- type: 'user' as const,
920
+ }
921
+ const recipientAccount: APIAccount = {
922
+ type: 'user',
877
923
  balance: 1000000,
878
924
  revealed: true,
879
925
  address: recipient,
@@ -883,8 +929,7 @@ describe('estimateFees', () => {
883
929
  delegationTime: '2021-01-01T00:00:00Z',
884
930
  numTransactions: 0,
885
931
  firstActivityTime: '2021-01-01T00:00:00Z',
886
- } as APIAccount
887
-
932
+ }
888
933
  mockGetAccountByAddress
889
934
  .mockResolvedValueOnce(unrevealedAccount) // initial sender lookup
890
935
  .mockResolvedValueOnce(recipientAccount) // recipient lookup in catch block
@@ -898,13 +943,15 @@ describe('estimateFees', () => {
898
943
  },
899
944
  })
900
945
 
901
- const result = await api.estimateFees(contextLowMinFees, {
902
- intentType: 'transaction',
903
- type: 'send',
904
- sender: unrevealedSender,
905
- recipient,
906
- amount: 1000n,
907
- } as TransactionIntent)
946
+ const result = await api.estimateFees(
947
+ contextLowMinFees,
948
+ createSendTransactionIntentMockData({
949
+ type: 'send',
950
+ sender: unrevealedSender,
951
+ recipient,
952
+ amount: 1000n,
953
+ })
954
+ )
908
955
 
909
956
  // baseTxFee = 524n; revealFee > 0 (tz2 secp256k1 address)
910
957
  // total > 524n and txFee stays at 524n
@@ -920,6 +967,7 @@ describe('estimateFees', () => {
920
967
  // With minFees = 2000 > ceil(120 + 0.1*2500 + 154) = 524 → baseTxFee = 2000
921
968
  const minFees = 2000
922
969
  const contextHighMinFees = makeContext({
970
+ status: { type: 'active' },
923
971
  baker: { url: 'https://baker.example.com' },
924
972
  explorer: { url: 'foo', maxTxQuery: 1 },
925
973
  node: { url: 'bar' },
@@ -932,8 +980,8 @@ describe('estimateFees', () => {
932
980
  },
933
981
  })
934
982
 
935
- const revealedAccount = {
936
- type: 'user' as const,
983
+ const revealedAccount: APIAccount = {
984
+ type: 'user',
937
985
  balance: 1000000,
938
986
  revealed: true,
939
987
  address: 'tz1test',
@@ -943,9 +991,9 @@ describe('estimateFees', () => {
943
991
  delegationTime: '2021-01-01T00:00:00Z',
944
992
  numTransactions: 0,
945
993
  firstActivityTime: '2021-01-01T00:00:00Z',
946
- } as APIAccount
947
- const recipientAccount = {
948
- type: 'user' as const,
994
+ }
995
+ const recipientAccount: APIAccount = {
996
+ type: 'user',
949
997
  balance: 1000000,
950
998
  revealed: true,
951
999
  address: 'tz2recipient',
@@ -955,8 +1003,7 @@ describe('estimateFees', () => {
955
1003
  delegationTime: '2021-01-01T00:00:00Z',
956
1004
  numTransactions: 0,
957
1005
  firstActivityTime: '2021-01-01T00:00:00Z',
958
- } as APIAccount
959
-
1006
+ }
960
1007
  mockGetAccountByAddress
961
1008
  .mockResolvedValueOnce(revealedAccount)
962
1009
  .mockResolvedValueOnce(recipientAccount)
@@ -970,13 +1017,15 @@ describe('estimateFees', () => {
970
1017
  },
971
1018
  })
972
1019
 
973
- const result = await api.estimateFees(contextHighMinFees, {
974
- intentType: 'transaction',
975
- type: 'send',
976
- sender: 'tz1test',
977
- recipient: 'tz2recipient',
978
- amount: 1000n,
979
- } as TransactionIntent)
1020
+ const result = await api.estimateFees(
1021
+ contextHighMinFees,
1022
+ createSendTransactionIntentMockData({
1023
+ type: 'send',
1024
+ sender: 'tz1test',
1025
+ recipient: 'tz2recipient',
1026
+ amount: 1000n,
1027
+ })
1028
+ )
980
1029
 
981
1030
  expect(result.value).toBe(BigInt(minFees))
982
1031
  expect(result.parameters?.txFee).toBe(BigInt(minFees))
@@ -988,9 +1037,9 @@ describe('estimateFees', () => {
988
1037
 
989
1038
  describe('getBalance', () => {
990
1039
  it('should throw an exception when options is provided', async () => {
991
- await expect(
992
- api.getBalance(context, 'random address', {} as unknown as BalanceOptions)
993
- ).rejects.toMatchObject({ name: 'InvalidParameterError' })
1040
+ await expect(api.getBalance(context, 'random address', {})).rejects.toMatchObject({
1041
+ name: 'InvalidParameterError',
1042
+ })
994
1043
  })
995
1044
  })
996
1045
 
@@ -1013,7 +1062,7 @@ describe('getAccountInfo', () => {
1013
1062
  delegationTime: '2021-01-01T00:00:00Z',
1014
1063
  numTransactions: 0,
1015
1064
  firstActivityTime: '2021-01-01T00:00:00Z',
1016
- } as APIAccount)
1065
+ })
1017
1066
 
1018
1067
  await expect(api.getAccountInfo!(context, 'tz1test')).resolves.toEqual({
1019
1068
  type: 'tezos',
@@ -1034,7 +1083,7 @@ describe('getAccountInfo', () => {
1034
1083
  delegationTime: '2021-01-01T00:00:00Z',
1035
1084
  numTransactions: 0,
1036
1085
  firstActivityTime: '2021-01-01T00:00:00Z',
1037
- } as APIAccount)
1086
+ })
1038
1087
 
1039
1088
  await expect(api.getAccountInfo!(context, 'tz2unrevealed')).resolves.toEqual({
1040
1089
  type: 'tezos',
@@ -1053,7 +1102,7 @@ describe('getAccountInfo', () => {
1053
1102
  address: 'tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9',
1054
1103
  publicKey: 'p2pktest',
1055
1104
  counter: 18,
1056
- } as APIAccount)
1105
+ })
1057
1106
 
1058
1107
  await expect(
1059
1108
  api.getAccountInfo!(context, 'tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9')
@@ -1069,7 +1118,7 @@ describe('getAccountInfo', () => {
1069
1118
  type: 'empty',
1070
1119
  address: 'tz1empty',
1071
1120
  counter: 0,
1072
- } as APIAccount)
1121
+ })
1073
1122
 
1074
1123
  await expect(api.getAccountInfo!(context, 'tz1empty')).resolves.toEqual({
1075
1124
  type: 'tezos',