@@ -622,4 +622,68 @@ mod tests {
622
622
b"\x25 \x0e \xc8 \x02 \xb6 \xd3 \xdb \x98 \x42 \xd1 \xbd \xbe \x0e \xe4 \x8d \x52 \xf9 \xa4 \xb4 \x6e \x60 \xcb \xbb \xab \x3b \xcc \x4e \xe9 \x15 \x73 \xfc \xe8 "
623
623
) ;
624
624
}
625
+
626
+ #[ test]
627
+ fn test_pkscript ( ) {
628
+ let params = super :: super :: params:: get ( pb:: BtcCoin :: Btc ) ;
629
+
630
+ let payload = Payload {
631
+ data : vec ! [ ] ,
632
+ output_type : BtcOutputType :: Unknown ,
633
+ } ;
634
+ assert_eq ! ( payload. pk_script( params) , Err ( Error :: InvalidInput ) ) ;
635
+
636
+ struct Test {
637
+ payload : & ' static str ,
638
+ output_type : BtcOutputType ,
639
+ expected_pkscript : & ' static str ,
640
+ }
641
+
642
+ let tests = [
643
+ Test {
644
+ payload : "669c6cb1883c50a1b10c34bd1693c1f34fe3d798" ,
645
+ output_type : BtcOutputType :: P2pkh ,
646
+ expected_pkscript : "76a914669c6cb1883c50a1b10c34bd1693c1f34fe3d79888ac" ,
647
+ } ,
648
+ Test {
649
+ payload : "b59e844a19063a882b3c34b64b941a8acdad74ee" ,
650
+ output_type : BtcOutputType :: P2sh ,
651
+ expected_pkscript : "a914b59e844a19063a882b3c34b64b941a8acdad74ee87" ,
652
+ } ,
653
+ Test {
654
+ payload : "b7cfb87a9806bb232e64f64e714785bd8366596b" ,
655
+ output_type : BtcOutputType :: P2wpkh ,
656
+ expected_pkscript : "0014b7cfb87a9806bb232e64f64e714785bd8366596b" ,
657
+ } ,
658
+ Test {
659
+ payload : "526e8e589b4bf1de80774986d972aed96ae70f17572d35fe89e61e9e88e2dd4a" ,
660
+ output_type : BtcOutputType :: P2wsh ,
661
+ expected_pkscript : "0020526e8e589b4bf1de80774986d972aed96ae70f17572d35fe89e61e9e88e2dd4a" ,
662
+ } ,
663
+ Test {
664
+ payload : "a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c" ,
665
+ output_type : BtcOutputType :: P2tr ,
666
+ expected_pkscript : "5120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c" ,
667
+ } ,
668
+ ] ;
669
+
670
+ for test in tests {
671
+ // OK
672
+ let payload = Payload {
673
+ data : hex:: decode ( test. payload ) . unwrap ( ) ,
674
+ output_type : test. output_type ,
675
+ } ;
676
+ assert_eq ! (
677
+ hex:: encode( payload. pk_script( params) . unwrap( ) ) ,
678
+ test. expected_pkscript
679
+ ) ;
680
+
681
+ // Payload of wrong size
682
+ let payload = Payload {
683
+ data : hex:: decode ( & test. payload [ 2 ..] ) . unwrap ( ) ,
684
+ output_type : test. output_type ,
685
+ } ;
686
+ assert_eq ! ( payload. pk_script( params) , Err ( Error :: Generic ) ) ;
687
+ }
688
+ }
625
689
}
0 commit comments