@bsv/wallet-toolbox 1.1.0 → 1.1.1

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.
@@ -2,19 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_client_1 = require("../../../src/index.client");
4
4
  const TestUtilsWalletStorage_1 = require("../../utils/TestUtilsWalletStorage");
5
- describe('listActions2 tests', () => {
5
+ const testName = 'listActions';
6
+ describe('listActions single action tests', () => {
6
7
  jest.setTimeout(99999999);
7
- const storages = [];
8
- const chain = 'test';
9
- const setups = [];
8
+ let ctxs = [];
9
+ let setups = [];
10
10
  const env = TestUtilsWalletStorage_1._tu.getEnv('test');
11
- const ctxs = [];
12
- const testName = () => expect.getState().currentTestName || 'test';
13
- beforeAll(async () => {
11
+ beforeEach(async () => {
12
+ setups = [];
13
+ ctxs = [];
14
+ await Promise.all(ctxs.map(async (ctx) => {
15
+ await ctx.storage.destroy();
16
+ }));
17
+ ctxs = [];
14
18
  if (env.runMySQL) {
15
- ctxs.push(await TestUtilsWalletStorage_1._tu.createLegacyWalletMySQLCopy(testName()));
19
+ ctxs.push(await TestUtilsWalletStorage_1._tu.createLegacyWalletMySQLCopy(testName));
16
20
  }
17
- ctxs.push(await TestUtilsWalletStorage_1._tu.createLegacyWalletSQLiteCopy(testName()));
21
+ ctxs.push(await TestUtilsWalletStorage_1._tu.createLegacyWalletSQLiteCopy(testName));
18
22
  const mockData = {
19
23
  actions: [
20
24
  {
@@ -25,9 +29,10 @@ describe('listActions2 tests', () => {
25
29
  description: 'Transaction',
26
30
  version: 1,
27
31
  lockTime: 0,
32
+ labels: ['label', 'label2'],
28
33
  inputs: [
29
34
  {
30
- sourceOutpoint: '0',
35
+ sourceOutpoint: 'tx.0',
31
36
  sourceSatoshis: 1,
32
37
  sourceLockingScript: '0123456789abcdef',
33
38
  unlockingScript: '0123456789abcdef',
@@ -35,13 +40,12 @@ describe('listActions2 tests', () => {
35
40
  sequenceNumber: 0
36
41
  }
37
42
  ],
38
- labels: ['label', 'label2'],
39
43
  outputs: [
40
44
  {
41
45
  satoshis: 1,
42
46
  spendable: false,
43
- tags: ['tag'],
44
- outputIndex: 0,
47
+ tags: ['tag', 'tag2'],
48
+ outputIndex: 2,
45
49
  outputDescription: 'description',
46
50
  basket: 'basket',
47
51
  lockingScript: '0123456789abcdef'
@@ -57,14 +61,14 @@ describe('listActions2 tests', () => {
57
61
  }
58
62
  expect(setups).toBeTruthy();
59
63
  for (const { activeStorage: storage, identityKey } of ctxs) {
60
- // Setup test environment with mock data
61
64
  await TestUtilsWalletStorage_1._tu.createTestSetup2(storage, identityKey, mockData);
62
65
  }
63
66
  });
64
- afterAll(async () => {
65
- for (const ctx of ctxs) {
67
+ afterEach(async () => {
68
+ await Promise.all(ctxs.map(async (ctx) => {
66
69
  await ctx.storage.destroy();
67
- }
70
+ }));
71
+ ctxs = [];
68
72
  });
69
73
  test('12_no labels default any', async () => {
70
74
  for (const { wallet } of ctxs) {
@@ -398,19 +402,720 @@ describe('listActions2 tests', () => {
398
402
  expect(await wallet.listActions(args)).toEqual(expectedResult);
399
403
  }
400
404
  });
405
+ test(`43_inputs requested`, async () => {
406
+ for (const { activeStorage: storage, wallet } of ctxs) {
407
+ await storage.updateTxLabel(1, { label: 'label' });
408
+ await storage.updateTxLabel(2, { label: 'label2' });
409
+ const args = {
410
+ labels: ['label2'],
411
+ includeInputs: true
412
+ };
413
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","inputs":[{"inputDescription":"description","sequenceNumber":0,"sourceOutpoint":"tx.0","sourceSatoshis":1}],"isOutgoing":true,"description":"Transaction","version":1,"lockTime":0}]}');
414
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
415
+ }
416
+ });
417
+ test(`44_inputs not requested`, async () => {
418
+ for (const { activeStorage: storage, wallet } of ctxs) {
419
+ await storage.updateTxLabel(1, { label: 'label' });
420
+ await storage.updateTxLabel(2, { label: 'label2' });
421
+ const args = {
422
+ labels: ['label2'],
423
+ includeInputs: false
424
+ };
425
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0}]}');
426
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
427
+ }
428
+ });
429
+ test(`45_inputs requested locking script`, async () => {
430
+ for (const { activeStorage: storage, wallet } of ctxs) {
431
+ await storage.updateTxLabel(1, { label: 'label' });
432
+ await storage.updateTxLabel(2, { label: 'label2' });
433
+ const args = {
434
+ labels: ['label2'],
435
+ includeInputs: true,
436
+ includeInputSourceLockingScripts: true
437
+ };
438
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","inputs":[{"inputDescription":"description","sequenceNumber":0,"sourceLockingScript":"0123456789abcdef","sourceOutpoint":"tx.0","sourceSatoshis":1}],"isOutgoing":true,"description":"Transaction","version":1,"lockTime":0}]}');
439
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
440
+ }
441
+ });
442
+ test(`46_inputs no locking script`, async () => {
443
+ for (const { activeStorage: storage, wallet } of ctxs) {
444
+ await storage.updateTxLabel(1, { label: 'label' });
445
+ await storage.updateTxLabel(2, { label: 'label2' });
446
+ const args = {
447
+ labels: ['label2'],
448
+ includeInputs: true,
449
+ includeInputSourceLockingScripts: false
450
+ };
451
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","inputs":[{"inputDescription":"description","sequenceNumber":0,"sourceOutpoint":"tx.0","sourceSatoshis":1}],"isOutgoing":true,"description":"Transaction","version":1,"lockTime":0}]}');
452
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
453
+ }
454
+ });
455
+ test(`47_inputs empty locking script`, async () => {
456
+ for (const { activeStorage: storage, wallet } of ctxs) {
457
+ await storage.updateTxLabel(1, { label: 'label' });
458
+ await storage.updateTxLabel(2, { label: 'label2' });
459
+ await storage.updateOutput(1, { lockingScript: [] });
460
+ const args = {
461
+ labels: ['label2'],
462
+ includeInputs: true,
463
+ includeInputSourceLockingScripts: true
464
+ };
465
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","inputs":[{"inputDescription":"description","sequenceNumber":0,"sourceLockingScript":"","sourceOutpoint":"tx.0","sourceSatoshis":1}],"isOutgoing":true,"description":"Transaction","version":1,"lockTime":0}]}');
466
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
467
+ }
468
+ });
469
+ // This requires genuine rawTx
470
+ // test(`48_inputs request unlocking script`, async () => {
471
+ // for (const { activeStorage: storage, wallet } of ctxs) {
472
+ // await storage.updateTxLabel(1, { label: 'label' })
473
+ // await storage.updateTxLabel(2, { label: 'label2' })
474
+ // await storage.updateOutput(1, {
475
+ // lockingScript: hexStringToNumberArray(
476
+ // '76a91489abcdefabbaabbaabbaabbaabbaabbaabbaabba88ac'
477
+ // )
478
+ // })
479
+ // const args: bsv.ListActionsArgs = {
480
+ // labels: ['label2'],
481
+ // includeInputs: true,
482
+ // includeInputSourceLockingScripts: true,
483
+ // includeInputUnlockingScripts: true
484
+ // }
485
+ // const expectedResult = JSON.parse(
486
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","inputs":[{"inputDescription":"description","sequenceNumber":0,"unlockingScript":"47304402207f2e9a6a6d8a5cf3f9d54b4e5fdfbb7a9c75c7e7a22be59d202c4baf1681c6140220219b1c07338fdfc60e949d0b426ce7b8f95de7a9d2e78f587db13fa7a6eb582301 0411db93e1dcdb8a016b49840f8c53bc1eb68a382fd70c81b7c4eeb4c1aab0eedda7e4a3c88ad097448a687ea1f90337e62c23f8cbb4cd7a7b20c54d7e0ceda220","sourceOutpoint":"tx.0","sourceSatoshis":1}],"isOutgoing":true,"description":"Transaction","version":1,"lockTime":0}]}'
487
+ // )
488
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
489
+ // }
490
+ // })
491
+ test(`49_outputs requested`, async () => {
492
+ for (const { activeStorage: storage, wallet } of ctxs) {
493
+ await storage.updateTxLabel(1, { label: 'label' });
494
+ await storage.updateTxLabel(2, { label: 'label2' });
495
+ await storage.updateOutputBasket(1, { name: 'new basket' });
496
+ await storage.updateOutput(2, {
497
+ satoshis: 1,
498
+ spendable: false,
499
+ vout: 2,
500
+ outputDescription: 'new description',
501
+ basketId: 1
502
+ });
503
+ await storage.updateOutputTag(2, { tag: 'new tag' });
504
+ await storage.updateOutputTagMap(1, 2, {});
505
+ const args = {
506
+ labels: ['label2'],
507
+ includeOutputs: true
508
+ };
509
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}');
510
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
511
+ }
512
+ });
513
+ test(`50_outputs requested`, async () => {
514
+ for (const { activeStorage: storage, wallet } of ctxs) {
515
+ await storage.updateTxLabel(1, { label: 'label' });
516
+ await storage.updateTxLabel(2, { label: 'label2' });
517
+ await storage.updateOutputBasket(1, { name: 'new basket' });
518
+ await storage.updateOutput(2, {
519
+ satoshis: 1,
520
+ spendable: false,
521
+ vout: 2,
522
+ outputDescription: 'new description',
523
+ basketId: 1
524
+ });
525
+ await storage.updateOutputTag(2, { tag: 'new tag' });
526
+ await storage.updateOutputTagMap(1, 2, {});
527
+ const args = {
528
+ labels: ['label2'],
529
+ includeOutputs: false
530
+ };
531
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0}]}');
532
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
533
+ }
534
+ });
535
+ // Cannot empty outputs at storage level
536
+ // test(`51_outputs empty requested`, async () => {
537
+ // for (const { activeStorage: storage, wallet } of ctxs) {
538
+ // await storage.updateTxLabel(1, { label: 'label' })
539
+ // await storage.updateTxLabel(2, { label: 'label2' })
540
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
541
+ // await storage.updateOutput(2, {})
542
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
543
+ // await storage.updateOutputTagMap(1, 2, {})
544
+ // const args: bsv.ListActionsArgs = {
545
+ // labels: ['label2'],
546
+ // includeOutputs: true
547
+ // }
548
+ // const expectedResult = JSON.parse(
549
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[]}]}'
550
+ // )
551
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
552
+ // }
553
+ // })
554
+ test(`52_outputs locking script requested`, async () => {
555
+ for (const { activeStorage: storage, wallet } of ctxs) {
556
+ await storage.updateTxLabel(1, { label: 'label' });
557
+ await storage.updateTxLabel(2, { label: 'label2' });
558
+ await storage.updateOutputBasket(1, { name: 'new basket' });
559
+ await storage.updateOutput(2, {
560
+ satoshis: 1,
561
+ spendable: false,
562
+ vout: 2,
563
+ outputDescription: 'new description',
564
+ basketId: 1,
565
+ lockingScript: (0, TestUtilsWalletStorage_1.hexStringToNumberArray)('0123456789abcdef')
566
+ });
567
+ await storage.updateOutputTag(2, { tag: 'new tag' });
568
+ await storage.updateOutputTagMap(1, 2, {});
569
+ const args = {
570
+ labels: ['label2'],
571
+ includeOutputs: true,
572
+ includeOutputLockingScripts: true
573
+ };
574
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"lockingScript":"0123456789abcdef","tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}');
575
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
576
+ }
577
+ });
578
+ test(`53_outputs locking script not requested`, async () => {
579
+ for (const { activeStorage: storage, wallet } of ctxs) {
580
+ await storage.updateTxLabel(1, { label: 'label' });
581
+ await storage.updateTxLabel(2, { label: 'label2' });
582
+ await storage.updateOutputBasket(1, { name: 'new basket' });
583
+ await storage.updateOutput(2, {
584
+ satoshis: 1,
585
+ spendable: false,
586
+ vout: 2,
587
+ outputDescription: 'new description',
588
+ basketId: 1,
589
+ lockingScript: (0, TestUtilsWalletStorage_1.hexStringToNumberArray)('0123456789abcdef')
590
+ });
591
+ await storage.updateOutputTag(2, { tag: 'new tag' });
592
+ await storage.updateOutputTagMap(1, 2, {});
593
+ const args = {
594
+ labels: ['label2'],
595
+ includeOutputs: true,
596
+ includeOutputLockingScripts: false
597
+ };
598
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}');
599
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
600
+ }
601
+ });
602
+ test(`54_outputs locking script undefined`, async () => {
603
+ for (const { activeStorage: storage, wallet } of ctxs) {
604
+ await storage.updateTxLabel(1, { label: 'label' });
605
+ await storage.updateTxLabel(2, { label: 'label2' });
606
+ await storage.updateOutputBasket(1, { name: 'new basket' });
607
+ await storage.updateOutput(2, {
608
+ satoshis: 1,
609
+ spendable: false,
610
+ vout: 2,
611
+ outputDescription: 'new description',
612
+ basketId: 1,
613
+ lockingScript: undefined
614
+ });
615
+ await storage.updateOutputTag(2, { tag: 'new tag' });
616
+ await storage.updateOutputTagMap(1, 2, {});
617
+ const args = {
618
+ labels: ['label2'],
619
+ includeOutputs: true,
620
+ includeOutputLockingScripts: false
621
+ };
622
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}');
623
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
624
+ }
625
+ });
626
+ //TBD requires many mock actions to be performed
627
+ // test(`55_limit is default`, async () => {
628
+ // for (const { activeStorage: storage, wallet } of ctxs) {
629
+ // await storage.updateTxLabel(1, { label: 'label' })
630
+ // await storage.updateTxLabel(2, { label: 'label2' })
631
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
632
+ // await storage.updateOutput(2, {
633
+ // satoshis: 1,
634
+ // spendable: false,
635
+ // vout: 2,
636
+ // outputDescription: 'new description',
637
+ // basketId: 1,
638
+ // lockingScript: undefined
639
+ // })
640
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
641
+ // await storage.updateOutputTagMap(1, 2, {})
642
+ // const args: bsv.ListActionsArgs = {
643
+ // labels: ['label2'],
644
+ // includeOutputs: true,
645
+ // includeOutputLockingScripts: false
646
+ // }
647
+ // const expectedResult = JSON.parse(
648
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}'
649
+ // )
650
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
651
+ // }
652
+ // })
653
+ // test(`56_limit 1`, async () => {
654
+ // for (const { activeStorage: storage, wallet } of ctxs) {
655
+ // await storage.updateTxLabel(1, { label: 'label' })
656
+ // await storage.updateTxLabel(2, { label: 'label2' })
657
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
658
+ // await storage.updateOutput(2, {
659
+ // satoshis: 1,
660
+ // spendable: false,
661
+ // vout: 2,
662
+ // outputDescription: 'new description',
663
+ // basketId: 1,
664
+ // lockingScript: undefined
665
+ // })
666
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
667
+ // await storage.updateOutputTagMap(1, 2, {})
668
+ // const args: bsv.ListActionsArgs = {
669
+ // labels: ['label2'],
670
+ // includeOutputs: true,
671
+ // includeOutputLockingScripts: false
672
+ // }
673
+ // const expectedResult = JSON.parse(
674
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}'
675
+ // )
676
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
677
+ // }
678
+ // })
679
+ test('57_limit 0', async () => {
680
+ for (const { wallet } of ctxs) {
681
+ const args = {
682
+ labels: ['label'],
683
+ limit: 0
684
+ };
685
+ await (0, TestUtilsWalletStorage_1.expectToThrowWERR)(index_client_1.sdk.WERR_INVALID_PARAMETER, async () => await wallet.listActions(args));
686
+ }
687
+ });
688
+ test('58_limit 10001', async () => {
689
+ for (const { wallet } of ctxs) {
690
+ const args = {
691
+ labels: ['label'],
692
+ limit: 10001
693
+ };
694
+ await (0, TestUtilsWalletStorage_1.expectToThrowWERR)(index_client_1.sdk.WERR_INVALID_PARAMETER, async () => await wallet.listActions(args));
695
+ }
696
+ });
697
+ // TBD requires many mock actions to be performed
698
+ // test(`59_offset less than number of actions`, async () => {
699
+ // for (const { activeStorage: storage, wallet } of ctxs) {
700
+ // await storage.updateTxLabel(1, { label: 'label' })
701
+ // await storage.updateTxLabel(2, { label: 'label2' })
702
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
703
+ // await storage.updateOutput(2, {
704
+ // satoshis: 1,
705
+ // spendable: false,
706
+ // vout: 2,
707
+ // outputDescription: 'new description',
708
+ // basketId: 1,
709
+ // lockingScript: undefined
710
+ // })
711
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
712
+ // await storage.updateOutputTagMap(1, 2, {})
713
+ // const args: bsv.ListActionsArgs = {
714
+ // labels: ['label2'],
715
+ // includeOutputs: true,
716
+ // includeOutputLockingScripts: false
717
+ // }
718
+ // const expectedResult = JSON.parse(
719
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}'
720
+ // )
721
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
722
+ // }
723
+ // })
724
+ // test(`60_offset equal to number of actions`, async () => {
725
+ // for (const { activeStorage: storage, wallet } of ctxs) {
726
+ // await storage.updateTxLabel(1, { label: 'label' })
727
+ // await storage.updateTxLabel(2, { label: 'label2' })
728
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
729
+ // await storage.updateOutput(2, {
730
+ // satoshis: 1,
731
+ // spendable: false,
732
+ // vout: 2,
733
+ // outputDescription: 'new description',
734
+ // basketId: 1,
735
+ // lockingScript: undefined
736
+ // })
737
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
738
+ // await storage.updateOutputTagMap(1, 2, {})
739
+ // const args: bsv.ListActionsArgs = {
740
+ // labels: ['label2'],
741
+ // includeOutputs: true,
742
+ // includeOutputLockingScripts: false
743
+ // }
744
+ // const expectedResult = JSON.parse(
745
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}'
746
+ // )
747
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
748
+ // }
749
+ // })
750
+ // test(`61_offset above number of actions`, async () => {
751
+ // for (const { activeStorage: storage, wallet } of ctxs) {
752
+ // await storage.updateTxLabel(1, { label: 'label' })
753
+ // await storage.updateTxLabel(2, { label: 'label2' })
754
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
755
+ // await storage.updateOutput(2, {
756
+ // satoshis: 1,
757
+ // spendable: false,
758
+ // vout: 2,
759
+ // outputDescription: 'new description',
760
+ // basketId: 1,
761
+ // lockingScript: undefined
762
+ // })
763
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
764
+ // await storage.updateOutputTagMap(1, 2, {})
765
+ // const args: bsv.ListActionsArgs = {
766
+ // labels: ['label2'],
767
+ // includeOutputs: true,
768
+ // includeOutputLockingScripts: false
769
+ // }
770
+ // const expectedResult = JSON.parse(
771
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}'
772
+ // )
773
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
774
+ // }
775
+ // })
776
+ test('62_offset is invalid', async () => {
777
+ for (const { wallet } of ctxs) {
778
+ const args = {
779
+ labels: ['label'],
780
+ offset: -1
781
+ };
782
+ await (0, TestUtilsWalletStorage_1.expectToThrowWERR)(index_client_1.sdk.WERR_INVALID_PARAMETER, async () => await wallet.listActions(args));
783
+ }
784
+ });
785
+ //TBD requires many mock actions to be performed
786
+ // test(`63_offset below limit with same number of actions`, async () => {
787
+ // for (const { activeStorage: storage, wallet } of ctxs) {
788
+ // await storage.updateTxLabel(1, { label: 'label' })
789
+ // await storage.updateTxLabel(2, { label: 'label2' })
790
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
791
+ // await storage.updateOutput(2, {
792
+ // satoshis: 1,
793
+ // spendable: false,
794
+ // vout: 2,
795
+ // outputDescription: 'new description',
796
+ // basketId: 1,
797
+ // lockingScript: undefined
798
+ // })
799
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
800
+ // await storage.updateOutputTagMap(1, 2, {})
801
+ // const args: bsv.ListActionsArgs = {
802
+ // labels: ['label2'],
803
+ // includeOutputs: true,
804
+ // includeOutputLockingScripts: false
805
+ // }
806
+ // const expectedResult = JSON.parse(
807
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}'
808
+ // )
809
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
810
+ // }
811
+ // })
812
+ // test(`64_offset below limit greater than number of actions`, async () => {
813
+ // for (const { activeStorage: storage, wallet } of ctxs) {
814
+ // await storage.updateTxLabel(1, { label: 'label' })
815
+ // await storage.updateTxLabel(2, { label: 'label2' })
816
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
817
+ // await storage.updateOutput(2, {
818
+ // satoshis: 1,
819
+ // spendable: false,
820
+ // vout: 2,
821
+ // outputDescription: 'new description',
822
+ // basketId: 1,
823
+ // lockingScript: undefined
824
+ // })
825
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
826
+ // await storage.updateOutputTagMap(1, 2, {})
827
+ // const args: bsv.ListActionsArgs = {
828
+ // labels: ['label2'],
829
+ // includeOutputs: true,
830
+ // includeOutputLockingScripts: false
831
+ // }
832
+ // const expectedResult = JSON.parse(
833
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}'
834
+ // )
835
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
836
+ // }
837
+ // })
838
+ // test(`65_offset skips all actions with limit set`, async () => {
839
+ // for (const { activeStorage: storage, wallet } of ctxs) {
840
+ // await storage.updateTxLabel(1, { label: 'label' })
841
+ // await storage.updateTxLabel(2, { label: 'label2' })
842
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
843
+ // await storage.updateOutput(2, {
844
+ // satoshis: 1,
845
+ // spendable: false,
846
+ // vout: 2,
847
+ // outputDescription: 'new description',
848
+ // basketId: 1,
849
+ // lockingScript: undefined
850
+ // })
851
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
852
+ // await storage.updateOutputTagMap(1, 2, {})
853
+ // const args: bsv.ListActionsArgs = {
854
+ // labels: ['label2'],
855
+ // includeOutputs: true,
856
+ // includeOutputLockingScripts: false
857
+ // }
858
+ // const expectedResult = JSON.parse(
859
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}'
860
+ // )
861
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
862
+ // }
863
+ // })
864
+ // test(`66_limit exceeds remaining actions after offset`, async () => {
865
+ // for (const { activeStorage: storage, wallet } of ctxs) {
866
+ // await storage.updateTxLabel(1, { label: 'label' })
867
+ // await storage.updateTxLabel(2, { label: 'label2' })
868
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
869
+ // await storage.updateOutput(2, {
870
+ // satoshis: 1,
871
+ // spendable: false,
872
+ // vout: 2,
873
+ // outputDescription: 'new description',
874
+ // basketId: 1,
875
+ // lockingScript: undefined
876
+ // })
877
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
878
+ // await storage.updateOutputTagMap(1, 2, {})
879
+ // const args: bsv.ListActionsArgs = {
880
+ // labels: ['label2'],
881
+ // includeOutputs: true,
882
+ // includeOutputLockingScripts: false
883
+ // }
884
+ // const expectedResult = JSON.parse(
885
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}'
886
+ // )
887
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
888
+ // }
889
+ // })
890
+ // test(`67_limit exceeds remaining actions after offset`, async () => {
891
+ // for (const { activeStorage: storage, wallet } of ctxs) {
892
+ // await storage.updateTxLabel(1, { label: 'label' })
893
+ // await storage.updateTxLabel(2, { label: 'label2' })
894
+ // await storage.updateOutputBasket(1, { name: 'new basket' })
895
+ // await storage.updateOutput(2, {
896
+ // satoshis: 1,
897
+ // spendable: false,
898
+ // vout: 2,
899
+ // outputDescription: 'new description',
900
+ // basketId: 1,
901
+ // lockingScript: undefined
902
+ // })
903
+ // await storage.updateOutputTag(2, { tag: 'new tag' })
904
+ // await storage.updateOutputTagMap(1, 2, {})
905
+ // const args: bsv.ListActionsArgs = {
906
+ // labels: ['label2'],
907
+ // includeOutputs: true,
908
+ // includeOutputLockingScripts: false
909
+ // }
910
+ // const expectedResult = JSON.parse(
911
+ // '{"totalActions":1,"actions":[{"txid":"tx","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction","version":1,"lockTime":0,"outputs":[{"satoshis":1,"spendable":false,"tags":["tag","new tag"],"outputIndex":2,"outputDescription":"new description","basket":"new basket"}]}]}'
912
+ // )
913
+ // expect(await wallet.listActions(args)).toEqual(expectedResult)
914
+ // }
915
+ // })
916
+ });
917
+ describe('listActions two action tests', () => {
918
+ jest.setTimeout(99999999);
919
+ let ctxs = [];
920
+ let setups = [];
921
+ const env = TestUtilsWalletStorage_1._tu.getEnv('test');
922
+ beforeEach(async () => {
923
+ setups = [];
924
+ ctxs = [];
925
+ await Promise.all(ctxs.map(async (ctx) => {
926
+ await ctx.storage.destroy();
927
+ }));
928
+ ctxs = [];
929
+ if (env.runMySQL) {
930
+ ctxs.push(await TestUtilsWalletStorage_1._tu.createLegacyWalletMySQLCopy(testName));
931
+ }
932
+ ctxs.push(await TestUtilsWalletStorage_1._tu.createLegacyWalletSQLiteCopy(testName));
933
+ const mockData = {
934
+ actions: [
935
+ {
936
+ txid: 'tx1',
937
+ satoshis: 1,
938
+ status: 'completed',
939
+ isOutgoing: true,
940
+ description: 'Transaction 1',
941
+ version: 1,
942
+ lockTime: 0,
943
+ labels: ['label 1', 'label a'],
944
+ inputs: [
945
+ {
946
+ sourceOutpoint: 'tx1.1',
947
+ sourceSatoshis: 1,
948
+ //sourceLockingScript: '0123456789abcdef',
949
+ //unlockingScript: '0123456789abcdef',
950
+ inputDescription: 'description 1',
951
+ sequenceNumber: 1
952
+ }
953
+ ],
954
+ outputs: [
955
+ {
956
+ satoshis: 1,
957
+ spendable: false,
958
+ tags: ['tag1'],
959
+ outputIndex: 1,
960
+ outputDescription: 'description 1',
961
+ basket: 'basket'
962
+ //lockingScript: '0123456789abcdef'
963
+ }
964
+ ]
965
+ },
966
+ {
967
+ txid: 'tx2',
968
+ satoshis: 2,
969
+ status: 'completed',
970
+ isOutgoing: true,
971
+ description: 'Transaction 2',
972
+ version: 1,
973
+ lockTime: 0,
974
+ labels: ['label2', 'label b'],
975
+ inputs: [
976
+ {
977
+ sourceOutpoint: 'tx2.2',
978
+ sourceSatoshis: 2,
979
+ //sourceLockingScript: '0123456789abcdef',
980
+ //unlockingScript: '0123456789abcdef',
981
+ inputDescription: 'description 2',
982
+ sequenceNumber: 2
983
+ }
984
+ ],
985
+ outputs: [
986
+ {
987
+ satoshis: 2,
988
+ spendable: false,
989
+ tags: ['tag2'],
990
+ outputIndex: 2,
991
+ outputDescription: 'description 2',
992
+ basket: 'basket 2'
993
+ //lockingScript: '0123456789abcdef'
994
+ }
995
+ ]
996
+ }
997
+ ]
998
+ };
999
+ for (const ctx of ctxs) {
1000
+ const { activeStorage } = ctx;
1001
+ await activeStorage.dropAllData();
1002
+ await activeStorage.migrate('insert tests', '3'.repeat(64));
1003
+ }
1004
+ expect(setups).toBeTruthy();
1005
+ for (const { activeStorage: storage, identityKey } of ctxs) {
1006
+ await TestUtilsWalletStorage_1._tu.createTestSetup2(storage, identityKey, mockData);
1007
+ }
1008
+ });
1009
+ afterEach(async () => {
1010
+ await Promise.all(ctxs.map(async (ctx) => {
1011
+ await ctx.storage.destroy();
1012
+ }));
1013
+ ctxs = [];
1014
+ });
1015
+ test('100_no labels (default) matched default any', async () => {
1016
+ for (const { wallet } of ctxs) {
1017
+ const args = {
1018
+ labels: []
1019
+ };
1020
+ const expectedResult = JSON.parse('{"totalActions":2,"actions":[{"txid":"tx1","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction 1","version":1,"lockTime":0},{"txid":"tx2","satoshis":2,"status":"completed","isOutgoing":true,"description":"Transaction 2","version":1,"lockTime":0}]}');
1021
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
1022
+ }
1023
+ });
1024
+ test('101_label 1 matched default any', async () => {
1025
+ for (const { activeStorage: storage, wallet } of ctxs) {
1026
+ const label = 'label 1';
1027
+ await storage.updateTxLabel(1, { label });
1028
+ await storage.updateTxLabel(2, { label: 'label a' });
1029
+ await storage.updateTxLabel(3, { label: 'label 2' });
1030
+ await storage.updateTxLabel(4, { label: 'label b' });
1031
+ const args = {
1032
+ labels: [label]
1033
+ };
1034
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx1","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction 1","version":1,"lockTime":0}]}');
1035
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
1036
+ }
1037
+ });
1038
+ test('102_label 2 matched default any', async () => {
1039
+ for (const { activeStorage: storage, wallet } of ctxs) {
1040
+ const label = 'label 2';
1041
+ await storage.updateTxLabel(1, { label: 'label 1' });
1042
+ await storage.updateTxLabel(2, { label: 'label a' });
1043
+ await storage.updateTxLabel(3, { label });
1044
+ await storage.updateTxLabel(4, { label: 'label b' });
1045
+ const args = {
1046
+ labels: [label]
1047
+ };
1048
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx2","satoshis":2,"status":"completed","isOutgoing":true,"description":"Transaction 2","version":1,"lockTime":0}]}');
1049
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
1050
+ }
1051
+ });
1052
+ test('103_no label matched default any', async () => {
1053
+ for (const { activeStorage: storage, wallet } of ctxs) {
1054
+ await storage.updateTxLabel(1, { label: 'label 1' });
1055
+ await storage.updateTxLabel(2, { label: 'label a' });
1056
+ await storage.updateTxLabel(3, { label: 'label 2' });
1057
+ await storage.updateTxLabel(4, { label: 'label b' });
1058
+ const args = {
1059
+ labels: ['label']
1060
+ };
1061
+ const expectedResult = JSON.parse('{"totalActions":0,"actions":[]}');
1062
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
1063
+ }
1064
+ });
1065
+ test('104_both labels matched default any', async () => {
1066
+ for (const { activeStorage: storage, wallet } of ctxs) {
1067
+ await storage.updateTxLabel(1, { label: 'label 1' });
1068
+ await storage.updateTxLabel(2, { label: 'label a' });
1069
+ await storage.updateTxLabel(3, { label: 'label 2' });
1070
+ await storage.updateTxLabel(4, { label: 'label b' });
1071
+ const args = {
1072
+ labels: ['label 1', 'label 2']
1073
+ };
1074
+ const expectedResult = JSON.parse('{"totalActions":2,"actions":[{"txid":"tx1","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction 1","version":1,"lockTime":0},{"txid":"tx2","satoshis":2,"status":"completed","isOutgoing":true,"description":"Transaction 2","version":1,"lockTime":0}]}');
1075
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
1076
+ }
1077
+ });
1078
+ test('105_first label pair matches mode all', async () => {
1079
+ for (const { activeStorage: storage, wallet } of ctxs) {
1080
+ await storage.updateTxLabel(1, { label: 'label 1' });
1081
+ await storage.updateTxLabel(2, { label: 'label a' });
1082
+ await storage.updateTxLabel(3, { label: 'label 2' });
1083
+ await storage.updateTxLabel(4, { label: 'label b' });
1084
+ const args = {
1085
+ labels: ['label 1', 'label a'],
1086
+ labelQueryMode: 'all'
1087
+ };
1088
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx1","satoshis":1,"status":"completed","isOutgoing":true,"description":"Transaction 1","version":1,"lockTime":0}]}');
1089
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
1090
+ }
1091
+ });
1092
+ test('106_second label pair matches mode all', async () => {
1093
+ for (const { activeStorage: storage, wallet } of ctxs) {
1094
+ await storage.updateTxLabel(1, { label: 'label 1' });
1095
+ await storage.updateTxLabel(2, { label: 'label a' });
1096
+ await storage.updateTxLabel(3, { label: 'label 2' });
1097
+ await storage.updateTxLabel(4, { label: 'label b' });
1098
+ const args = {
1099
+ labels: ['label 2', 'label b'],
1100
+ labelQueryMode: 'all'
1101
+ };
1102
+ const expectedResult = JSON.parse('{"totalActions":1,"actions":[{"txid":"tx2","satoshis":2,"status":"completed","isOutgoing":true,"description":"Transaction 2","version":1,"lockTime":0}]}');
1103
+ expect(await wallet.listActions(args)).toEqual(expectedResult);
1104
+ }
1105
+ });
401
1106
  });
402
1107
  const generateRandomEmojiString = (bytes) => {
403
1108
  const emojiRange = [
404
- '\u{1F600}', // Grinning face
405
- '\u{1F603}', // Smiling face
406
- '\u{1F604}', // Laughing face
407
- '\u{1F609}', // Winking face
408
- '\u{1F60A}', // Blushing face
409
- '\u{1F60D}', // Heart eyes
410
- '\u{1F618}', // Kissing face
411
- '\u{1F61C}', // Tongue out
412
- '\u{1F923}', // Rolling on the floor laughing
413
- '\u{1F44D}' // Thumbs up
1109
+ '\u{1F600}',
1110
+ '\u{1F603}',
1111
+ '\u{1F604}',
1112
+ '\u{1F609}',
1113
+ '\u{1F60A}',
1114
+ '\u{1F60D}',
1115
+ '\u{1F618}',
1116
+ '\u{1F61C}',
1117
+ '\u{1F923}',
1118
+ '\u{1F44D}'
414
1119
  ];
415
1120
  const bytesPerEmoji = 4; // Each emoji is 4 bytes in UTF-8
416
1121
  const numEmojis = Math.floor(bytes / bytesPerEmoji);