@psf/bch-js 5.4.0 → 6.2.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.
@@ -497,476 +497,6 @@ describe('#SLP', () => {
497
497
  })
498
498
  })
499
499
 
500
- describe('#tokenUtxoDetailsWL', () => {
501
- it('should return details for a simple SEND SLP token utxo', async () => {
502
- const utxos = [
503
- {
504
- height: 660554,
505
- tx_hash:
506
- '89b3f0c84efe8b01b24e2d7ac08636de5781f31dbb84478e3de868ca0a7ed93a',
507
- tx_pos: 1,
508
- value: 546
509
- }
510
- ]
511
-
512
- const data = await bchjs.SLP.Utils.tokenUtxoDetailsWL(utxos)
513
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
514
-
515
- assert.property(data[0], 'txid')
516
- assert.property(data[0], 'vout')
517
- assert.property(data[0], 'height')
518
- assert.property(data[0], 'utxoType')
519
- assert.property(data[0], 'tokenId')
520
- assert.property(data[0], 'tokenTicker')
521
- assert.property(data[0], 'tokenName')
522
- assert.property(data[0], 'tokenDocumentUrl')
523
- assert.property(data[0], 'tokenDocumentHash')
524
- assert.property(data[0], 'decimals')
525
- assert.property(data[0], 'tokenQty')
526
- assert.property(data[0], 'isValid')
527
- assert.equal(data[0].isValid, true)
528
- })
529
-
530
- it('should return false for BCH-only UTXOs', async () => {
531
- const utxos = [
532
- {
533
- txid:
534
- 'a937f792c7c9eb23b4f344ce5c233d1ac0909217d0a504d71e6b1e4efb864a3b',
535
- vout: 0,
536
- amount: 0.00001,
537
- satoshis: 1000,
538
- confirmations: 0,
539
- ts: 1578424704
540
- },
541
- {
542
- txid:
543
- '53fd141c2e999e080a5860887441a2c45e9cbe262027e2bd2ac998fc76e43c44',
544
- vout: 0,
545
- amount: 0.00001,
546
- satoshis: 1000,
547
- confirmations: 0,
548
- ts: 1578424634
549
- }
550
- ]
551
-
552
- const data = await bchjs.SLP.Utils.tokenUtxoDetailsWL(utxos)
553
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
554
-
555
- assert.isArray(data)
556
- assert.equal(data[0].isValid, false)
557
- assert.equal(data[1].isValid, false)
558
- })
559
-
560
- it('should handle a dust attack', async () => {
561
- // it("#dustattack", async () => {
562
- const utxos = [
563
- {
564
- height: 655965,
565
- tx_hash:
566
- 'a675af87dcd8d39be782737aa52e0076b52eb2f5ce355ffcb5567a64dd96b77e',
567
- tx_pos: 151,
568
- value: 547,
569
- satoshis: 547,
570
- txid:
571
- 'a675af87dcd8d39be782737aa52e0076b52eb2f5ce355ffcb5567a64dd96b77e',
572
- vout: 151,
573
- address: 'bitcoincash:qq4dw3sm8qvglspy6w2qg0u2ugsy9zcfcqrpeflwww',
574
- hdIndex: 11
575
- }
576
- ]
577
-
578
- const data = await bchjs.SLP.Utils.tokenUtxoDetailsWL(utxos)
579
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
580
-
581
- assert.equal(data[0].isValid, false)
582
- })
583
-
584
- it('should handle null SLPDB validations', async () => {
585
- const utxos = [
586
- {
587
- height: 665577,
588
- tx_hash:
589
- '4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419',
590
- tx_pos: 1,
591
- value: 546
592
- },
593
- {
594
- height: 665577,
595
- tx_hash:
596
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488',
597
- tx_pos: 1,
598
- value: 546
599
- }
600
- ]
601
-
602
- const data = await bchjs.SLP.Utils.tokenUtxoDetailsWL(utxos)
603
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
604
-
605
- assert.isArray(data)
606
- // assert.equal(data[0].isValid, null)
607
- })
608
- })
609
-
610
- describe('#balancesForAddress', () => {
611
- it('should fetch all balances for address: simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9', async () => {
612
- const balances = await bchjs.SLP.Utils.balancesForAddress(
613
- 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9'
614
- )
615
- // console.log(`balances: ${JSON.stringify(balances, null, 2)}`)
616
-
617
- assert.isArray(balances)
618
- assert.hasAllKeys(balances[0], [
619
- 'tokenId',
620
- 'balanceString',
621
- 'balance',
622
- 'decimalCount',
623
- 'slpAddress'
624
- ])
625
- })
626
-
627
- it('should fetch balances for multiple addresses', async () => {
628
- const addresses = [
629
- 'simpleledger:qzv3zz2trz0xgp6a96lu4m6vp2nkwag0kvyucjzqt9',
630
- 'simpleledger:qqss4zp80hn6szsa4jg2s9fupe7g5tcg5ucdyl3r57'
631
- ]
632
-
633
- const balances = await bchjs.SLP.Utils.balancesForAddress(addresses)
634
- // console.log(`balances: ${JSON.stringify(balances, null, 2)}`)
635
-
636
- assert.isArray(balances)
637
- assert.isArray(balances[0])
638
- assert.hasAllKeys(balances[0][0], [
639
- 'tokenId',
640
- 'balanceString',
641
- 'balance',
642
- 'decimalCount',
643
- 'slpAddress'
644
- ])
645
- })
646
- })
647
-
648
- describe('#hydrateUtxos-', () => {
649
- it('should hydrate UTXOs', async () => {
650
- const utxos = [
651
- {
652
- utxos: [
653
- {
654
- txid:
655
- 'd56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56',
656
- vout: 3,
657
- value: '6816',
658
- height: 606848,
659
- confirmations: 13,
660
- satoshis: 6816
661
- },
662
- {
663
- txid:
664
- 'd56a2b446d8149c39ca7e06163fe8097168c3604915f631bc58777d669135a56',
665
- vout: 2,
666
- value: '546',
667
- height: 606848,
668
- confirmations: 13,
669
- satoshis: 546
670
- }
671
- ]
672
- }
673
- ]
674
-
675
- const result = await bchjs.SLP.Utils.hydrateUtxos(utxos)
676
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
677
-
678
- // Test the general structure of the output.
679
- assert.isArray(result.slpUtxos)
680
- assert.equal(result.slpUtxos.length, 1)
681
- assert.equal(result.slpUtxos[0].utxos.length, 2)
682
-
683
- // Test the non-slp UTXO.
684
- assert.property(result.slpUtxos[0].utxos[0], 'txid')
685
- assert.property(result.slpUtxos[0].utxos[0], 'vout')
686
- assert.property(result.slpUtxos[0].utxos[0], 'value')
687
- assert.property(result.slpUtxos[0].utxos[0], 'height')
688
- assert.property(result.slpUtxos[0].utxos[0], 'confirmations')
689
- assert.property(result.slpUtxos[0].utxos[0], 'satoshis')
690
- assert.property(result.slpUtxos[0].utxos[0], 'isValid')
691
- assert.equal(result.slpUtxos[0].utxos[0].isValid, false)
692
-
693
- // Test the slp UTXO.
694
- assert.property(result.slpUtxos[0].utxos[1], 'txid')
695
- assert.property(result.slpUtxos[0].utxos[1], 'vout')
696
- assert.property(result.slpUtxos[0].utxos[1], 'value')
697
- assert.property(result.slpUtxos[0].utxos[1], 'height')
698
- assert.property(result.slpUtxos[0].utxos[1], 'confirmations')
699
- assert.property(result.slpUtxos[0].utxos[1], 'satoshis')
700
- assert.property(result.slpUtxos[0].utxos[1], 'isValid')
701
- assert.equal(result.slpUtxos[0].utxos[1].isValid, true)
702
- assert.property(result.slpUtxos[0].utxos[1], 'transactionType')
703
- assert.property(result.slpUtxos[0].utxos[1], 'tokenId')
704
- assert.property(result.slpUtxos[0].utxos[1], 'tokenTicker')
705
- assert.property(result.slpUtxos[0].utxos[1], 'tokenName')
706
- assert.property(result.slpUtxos[0].utxos[1], 'tokenDocumentUrl')
707
- assert.property(result.slpUtxos[0].utxos[1], 'tokenDocumentHash')
708
- assert.property(result.slpUtxos[0].utxos[1], 'decimals')
709
- assert.property(result.slpUtxos[0].utxos[1], 'tokenType')
710
- assert.property(result.slpUtxos[0].utxos[1], 'tokenQty')
711
- })
712
-
713
- it('should process data directly from Electrumx', async () => {
714
- const addrs = [
715
- 'bitcoincash:qqnt53cfw990u6y38xgezm0lfa8hknw0wueezcpagp',
716
- 'bitcoincash:qrh3qgtax6adegzc7zxm6m4sgrv9wq28yqnfn33ce5',
717
- 'bitcoincash:qqcaee5w4ws77n8s2gzy6fwtma6uxd7ctq8553e495'
718
- ]
719
-
720
- const utxos = await bchjs.Electrumx.utxo(addrs)
721
- // console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
722
-
723
- const result = await bchjs.SLP.Utils.hydrateUtxos(utxos.utxos)
724
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
725
-
726
- // Test the general structure of the output.
727
- assert.isArray(result.slpUtxos)
728
- assert.equal(result.slpUtxos.length, 3)
729
- assert.equal(result.slpUtxos[0].utxos.length, 1)
730
- assert.equal(result.slpUtxos[1].utxos.length, 1)
731
- assert.equal(result.slpUtxos[2].utxos.length, 2)
732
-
733
- try {
734
- // Test the expected values.
735
- assert.equal(result.slpUtxos[0].utxos[0].isValid, false)
736
- assert.equal(result.slpUtxos[1].utxos[0].isValid, true)
737
- assert.equal(result.slpUtxos[1].utxos[0].tokenTicker, 'TROUT')
738
- assert.equal(result.slpUtxos[2].utxos[0].isValid, false)
739
- assert.equal(result.slpUtxos[2].utxos[1].isValid, true)
740
- assert.equal(result.slpUtxos[2].utxos[1].tokenTicker, 'VALENTINE')
741
- } catch (err) {
742
- console.error(
743
- 'The hydrateUtxos call may hitting rate limits, or SLPDB may be having issues if "isValid" results are "null"'
744
- )
745
- console.log('Error: ', err)
746
- }
747
- })
748
-
749
- it('should handle null SLPDB validations', async () => {
750
- const utxos = [
751
- {
752
- height: 665577,
753
- tx_hash:
754
- '4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419',
755
- tx_pos: 1,
756
- value: 546
757
- },
758
- {
759
- height: 665577,
760
- tx_hash:
761
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
762
- tx_pos: 1,
763
- value: 546
764
- }
765
- ]
766
-
767
- const data = await bchjs.SLP.Utils.hydrateUtxos([{ utxos: utxos }])
768
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
769
-
770
- assert.isArray(data.slpUtxos)
771
- assert.equal(data.slpUtxos[0].isValid, null)
772
- })
773
- })
774
-
775
- describe('#hydrateUtxosWL', () => {
776
- it('should hydrate UTXOs', async () => {
777
- const utxos = [
778
- {
779
- utxos: [
780
- {
781
- txid:
782
- '89b3f0c84efe8b01b24e2d7ac08636de5781f31dbb84478e3de868ca0a7ed93a',
783
- vout: 1,
784
- value: 546
785
- }
786
- ]
787
- }
788
- ]
789
-
790
- const result = await bchjs.SLP.Utils.hydrateUtxosWL(utxos)
791
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
792
-
793
- // Test the general structure of the output.
794
- assert.isArray(result.slpUtxos)
795
- assert.equal(result.slpUtxos.length, 1)
796
- assert.equal(result.slpUtxos[0].utxos.length, 1)
797
-
798
- // Test the non-slp UTXO.
799
- assert.property(result.slpUtxos[0].utxos[0], 'txid')
800
- assert.property(result.slpUtxos[0].utxos[0], 'vout')
801
- assert.property(result.slpUtxos[0].utxos[0], 'value')
802
- assert.property(result.slpUtxos[0].utxos[0], 'isValid')
803
- assert.equal(result.slpUtxos[0].utxos[0].isValid, true)
804
- })
805
-
806
- it('should process data directly from Electrumx', async () => {
807
- const addrs = [
808
- 'bitcoincash:qqnt53cfw990u6y38xgezm0lfa8hknw0wueezcpagp',
809
- 'bitcoincash:qrh3qgtax6adegzc7zxm6m4sgrv9wq28yqnfn33ce5',
810
- 'bitcoincash:qqcaee5w4ws77n8s2gzy6fwtma6uxd7ctq8553e495'
811
- ]
812
-
813
- const utxos = await bchjs.Electrumx.utxo(addrs)
814
- // console.log(`utxos: ${JSON.stringify(utxos, null, 2)}`)
815
-
816
- const result = await bchjs.SLP.Utils.hydrateUtxosWL(utxos.utxos)
817
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
818
-
819
- // Test the general structure of the output.
820
- assert.isArray(result.slpUtxos)
821
- assert.equal(result.slpUtxos.length, 3)
822
- assert.equal(result.slpUtxos[0].utxos.length, 1)
823
- assert.equal(result.slpUtxos[1].utxos.length, 1)
824
- assert.equal(result.slpUtxos[2].utxos.length, 2)
825
-
826
- try {
827
- // Test the expected values.
828
- assert.equal(result.slpUtxos[0].utxos[0].isValid, false)
829
- assert.equal(result.slpUtxos[1].utxos[0].isValid, true)
830
- assert.equal(result.slpUtxos[1].utxos[0].tokenTicker, 'TROUT')
831
- assert.equal(result.slpUtxos[2].utxos[0].isValid, false)
832
- // assert.equal(result.slpUtxos[2].utxos[1].isValid, null)
833
- assert.equal(result.slpUtxos[2].utxos[1].tokenTicker, 'VALENTINE')
834
- } catch (err) {
835
- console.error(
836
- 'The hydrateUtxos call may hitting rate limits, or SLPDB may be having issues if "isValid" results are "null"'
837
- )
838
- console.log('Error: ', err)
839
- }
840
- })
841
-
842
- it('should handle null SLPDB validations', async () => {
843
- const utxos = [
844
- {
845
- height: 665577,
846
- tx_hash:
847
- '4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419',
848
- tx_pos: 1,
849
- value: 546
850
- },
851
- {
852
- height: 665577,
853
- tx_hash:
854
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a',
855
- tx_pos: 1,
856
- value: 546
857
- }
858
- ]
859
-
860
- const data = await bchjs.SLP.Utils.hydrateUtxosWL([{ utxos: utxos }])
861
- // console.log(`data: ${JSON.stringify(data, null, 2)}`)
862
-
863
- assert.isArray(data.slpUtxos)
864
- assert.equal(data.slpUtxos[0].isValid, null)
865
- })
866
- })
867
-
868
- describe('#validateTxid', () => {
869
- // This test is not necessary.
870
- it('should handle a null response from SLPDB', async () => {
871
- const txid =
872
- '4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419'
873
-
874
- const result = await bchjs.SLP.Utils.validateTxid(txid)
875
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
876
-
877
- assert.isArray(result)
878
- assert.equal(result[0].txid, txid)
879
- // assert.equal(result[0].valid, null)
880
- })
881
-
882
- it('should handle a null response from SLPDB', async () => {
883
- const txid = [
884
- '4b89405c54d1c0bde8aa476a47561a42a6e7a5e927daa2ec69d428810eae3419',
885
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488'
886
- ]
887
-
888
- const result = await bchjs.SLP.Utils.validateTxid(txid)
889
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
890
-
891
- assert.isArray(result)
892
- assert.equal(result[0].txid, txid[0])
893
- // assert.equal(result[0].valid, null)
894
- })
895
- })
896
-
897
- describe('#validateTxid2', () => {
898
- it('should invalidate a known invalid TXID', async () => {
899
- const txid =
900
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a'
901
-
902
- const result = await bchjs.SLP.Utils.validateTxid2(txid)
903
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
904
-
905
- assert.property(result, 'txid')
906
- assert.equal(result.txid, txid)
907
-
908
- assert.property(result, 'isValid')
909
- assert.equal(result.isValid, false)
910
- })
911
-
912
- it('should validate a known valid TXID', async () => {
913
- const txid =
914
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488'
915
-
916
- const result = await bchjs.SLP.Utils.validateTxid2(txid)
917
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
918
-
919
- assert.property(result, 'txid')
920
- assert.equal(result.txid, txid)
921
-
922
- assert.property(result, 'isValid')
923
- assert.equal(result.isValid, true)
924
- })
925
- })
926
-
927
- describe('#getWhitelist', () => {
928
- it('should get the whitelist', async () => {
929
- const result = await bchjs.SLP.Utils.getWhitelist()
930
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
931
-
932
- assert.isArray(result)
933
- assert.property(result[0], 'name')
934
- assert.property(result[1], 'tokenId')
935
- })
936
- })
937
-
938
- describe('#getStatus', () => {
939
- it('should return the current block height of the SLPDB indexer', async () => {
940
- const result = await bchjs.SLP.Utils.getStatus()
941
-
942
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
943
-
944
- assert.property(result, 'bchBlockHeight')
945
- assert.property(result, 'slpProcessedBlockHeight')
946
- })
947
- })
948
-
949
- describe('#waterfallValidateTxid', () => {
950
- it('should validate known good txid not in whitelist', async () => {
951
- const txid =
952
- '3a4b628cbcc183ab376d44ce5252325f042268307ffa4a53443e92b6d24fb488'
953
-
954
- const result = await bchjs.SLP.Utils.waterfallValidateTxid(txid)
955
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
956
-
957
- assert.equal(result, true)
958
- })
959
-
960
- it('should invalidate a known invalid TXID', async () => {
961
- const txid =
962
- 'f7e5199ef6669ad4d078093b3ad56e355b6ab84567e59ad0f08a5ad0244f783a'
963
-
964
- const result = await bchjs.SLP.Utils.waterfallValidateTxid(txid)
965
- // console.log(`result: ${JSON.stringify(result, null, 2)}`)
966
-
967
- assert.equal(result, false)
968
- })
969
- })
970
500
  describe('#tokentype1', () => {
971
501
  describe('#getHexOpReturn', () => {
972
502
  it('should return OP_RETURN object ', async () => {