@@ -846,4 +846,71 @@ describe(`Psbt`, () => {
846
846
assert . ok ( ( psbt as any ) . data . inputs [ index ] . nonWitnessUtxo . equals ( value ) ) ;
847
847
} ) ;
848
848
} ) ;
849
+
850
+ describe ( 'Transaction properties' , ( ) => {
851
+ it ( '.version is exposed and is settable' , ( ) => {
852
+ const psbt = new Psbt ( ) ;
853
+
854
+ assert . strictEqual ( psbt . version , 2 ) ;
855
+ assert . strictEqual ( psbt . version , ( psbt as any ) . __CACHE . __TX . version ) ;
856
+
857
+ psbt . version = 1 ;
858
+ assert . strictEqual ( psbt . version , 1 ) ;
859
+ assert . strictEqual ( psbt . version , ( psbt as any ) . __CACHE . __TX . version ) ;
860
+ } ) ;
861
+
862
+ it ( '.locktime is exposed and is settable' , ( ) => {
863
+ const psbt = new Psbt ( ) ;
864
+
865
+ assert . strictEqual ( psbt . locktime , 0 ) ;
866
+ assert . strictEqual ( psbt . locktime , ( psbt as any ) . __CACHE . __TX . locktime ) ;
867
+
868
+ psbt . locktime = 123 ;
869
+ assert . strictEqual ( psbt . locktime , 123 ) ;
870
+ assert . strictEqual ( psbt . locktime , ( psbt as any ) . __CACHE . __TX . locktime ) ;
871
+ } ) ;
872
+
873
+ it ( '.txInputs is exposed as a readonly clone' , ( ) => {
874
+ const psbt = new Psbt ( ) ;
875
+ const hash = Buffer . alloc ( 32 ) ;
876
+ const index = 0 ;
877
+ psbt . addInput ( { hash, index } ) ;
878
+
879
+ const input = psbt . txInputs [ 0 ] ;
880
+ const internalInput = ( psbt as any ) . __CACHE . __TX . ins [ 0 ] ;
881
+
882
+ assert . ok ( input . hash . equals ( internalInput . hash ) ) ;
883
+ assert . strictEqual ( input . index , internalInput . index ) ;
884
+ assert . strictEqual ( input . sequence , internalInput . sequence ) ;
885
+
886
+ input . hash [ 0 ] = 123 ;
887
+ input . index = 123 ;
888
+ input . sequence = 123 ;
889
+
890
+ assert . ok ( ! input . hash . equals ( internalInput . hash ) ) ;
891
+ assert . notEqual ( input . index , internalInput . index ) ;
892
+ assert . notEqual ( input . sequence , internalInput . sequence ) ;
893
+ } ) ;
894
+
895
+ it ( '.txOutputs is exposed as a readonly clone' , ( ) => {
896
+ const psbt = new Psbt ( ) ;
897
+ const address = '1LukeQU5jwebXbMLDVydeH4vFSobRV9rkj' ;
898
+ const value = 100000 ;
899
+ psbt . addOutput ( { address, value } ) ;
900
+
901
+ const output = psbt . txOutputs [ 0 ] ;
902
+ const internalInput = ( psbt as any ) . __CACHE . __TX . outs [ 0 ] ;
903
+
904
+ assert . strictEqual ( output . address , address ) ;
905
+
906
+ assert . ok ( output . script . equals ( internalInput . script ) ) ;
907
+ assert . strictEqual ( output . value , internalInput . value ) ;
908
+
909
+ output . script [ 0 ] = 123 ;
910
+ output . value = 123 ;
911
+
912
+ assert . ok ( ! output . script . equals ( internalInput . script ) ) ;
913
+ assert . notEqual ( output . value , internalInput . value ) ;
914
+ } ) ;
915
+ } ) ;
849
916
} ) ;
0 commit comments