@@ -720,7 +720,9 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for CovenantDescripto
720
720
mod tests {
721
721
722
722
use super :: * ;
723
- use elements:: confidential;
723
+ use elements:: hashes:: hex:: ToHex ;
724
+ use elements:: { confidential, opcodes:: all:: OP_PUSHNUM_1 } ;
725
+ use elements:: { opcodes, script} ;
724
726
use elements:: { AssetId , AssetIssuance , OutPoint , TxIn , TxInWitness , Txid } ;
725
727
use interpreter:: SatisfiedConstraint ;
726
728
use std:: str:: FromStr ;
@@ -734,12 +736,20 @@ mod tests {
734
736
0xe1 , 0xb2 ,
735
737
] ;
736
738
739
+ fn string_rtt ( desc_str : & str ) {
740
+ let desc = Descriptor :: < String > :: from_str ( desc_str) . unwrap ( ) ;
741
+ assert_eq ! ( desc. to_string_no_chksum( ) , desc_str) ;
742
+ let cov_desc = desc. as_cov ( ) ;
743
+ assert_eq ! ( cov_desc. to_string( ) , desc. to_string( ) ) ;
744
+ }
737
745
#[ test]
738
746
fn parse_cov ( ) {
739
- Descriptor :: < String > :: from_str ( "elcovwsh(A,pk(B))" ) . unwrap ( ) ;
740
- Descriptor :: < String > :: from_str ( "elcovwsh(A,or_i(pk(B),pk(C)))" ) . expect ( "Failed" ) ;
741
- Descriptor :: < String > :: from_str ( "elcovwsh(A,multi(2,B,C,D))" ) . unwrap ( ) ;
742
- Descriptor :: < String > :: from_str ( "elcovwsh(A,and_v(v:pk(B),pk(C)))" ) . unwrap ( ) ;
747
+ string_rtt ( "elcovwsh(A,pk(B))" ) ;
748
+ string_rtt ( "elcovwsh(A,or_i(pk(B),pk(C)))" ) ;
749
+ string_rtt ( "elcovwsh(A,multi(2,B,C,D))" ) ;
750
+ string_rtt ( "elcovwsh(A,and_v(v:pk(B),pk(C)))" ) ;
751
+ string_rtt ( "elcovwsh(A,thresh(2,ver_eq(1),s:pk(C),s:pk(B)))" ) ;
752
+ string_rtt ( "elcovwsh(A,outputs_pref(01020304))" ) ;
743
753
}
744
754
745
755
fn script_rtt ( desc_str : & str ) {
@@ -768,6 +778,14 @@ mod tests {
768
778
"elcovwsh({},and_v(v:pk({}),pk({})))" ,
769
779
pks[ 0 ] , pks[ 1 ] , pks[ 2 ]
770
780
) ) ;
781
+ script_rtt ( & format ! (
782
+ "elcovwsh({},and_v(v:ver_eq(2),pk({})))" ,
783
+ pks[ 0 ] , pks[ 1 ]
784
+ ) ) ;
785
+ script_rtt ( & format ! (
786
+ "elcovwsh({},and_v(v:outputs_pref(f2f233),pk({})))" ,
787
+ pks[ 0 ] , pks[ 1 ]
788
+ ) ) ;
771
789
}
772
790
773
791
// Some deterministic keys for ease of testing
@@ -831,7 +849,10 @@ mod tests {
831
849
} ;
832
850
833
851
spend_tx. output . push ( TxOut :: default ( ) ) ;
834
- spend_tx. output [ 0 ] . script_pubkey = desc. script_pubkey ( ) ; // send back to self
852
+ spend_tx. output [ 0 ] . script_pubkey = script:: Builder :: new ( )
853
+ . push_opcode ( opcodes:: all:: OP_PUSHNUM_1 )
854
+ . into_script ( )
855
+ . to_v0_p2wsh ( ) ;
835
856
spend_tx. output [ 0 ] . value = confidential:: Value :: Explicit ( 99_000 ) ;
836
857
spend_tx. output [ 0 ] . asset =
837
858
confidential:: Asset :: Explicit ( AssetId :: from_slice ( & BTC_ASSET ) . unwrap ( ) ) ;
@@ -934,6 +955,39 @@ mod tests {
934
955
sks[ 0 ] ,
935
956
)
936
957
. unwrap_err ( ) ;
958
+
959
+ // Outputs Pref test
960
+ // 1. Correct case
961
+ let mut out = TxOut :: default ( ) ;
962
+ out. script_pubkey = script:: Builder :: new ( )
963
+ . push_opcode ( opcodes:: all:: OP_PUSHNUM_1 )
964
+ . into_script ( )
965
+ . to_v0_p2wsh ( ) ;
966
+ out. value = confidential:: Value :: Explicit ( 99_000 ) ;
967
+ out. asset = confidential:: Asset :: Explicit ( AssetId :: from_slice ( & BTC_ASSET ) . unwrap ( ) ) ;
968
+ let desc = Descriptor :: < bitcoin:: PublicKey > :: from_str ( & format ! (
969
+ "elcovwsh({},outputs_pref({}))" ,
970
+ pks[ 0 ] ,
971
+ serialize( & out) . to_hex( ) ,
972
+ ) )
973
+ . unwrap ( ) ;
974
+ _satisfy_and_interpret ( desc, sks[ 0 ] ) . unwrap ( ) ;
975
+
976
+ // 2. Chaning the amount should fail the test
977
+ let mut out = TxOut :: default ( ) ;
978
+ out. script_pubkey = script:: Builder :: new ( )
979
+ . push_opcode ( opcodes:: all:: OP_PUSHNUM_1 )
980
+ . into_script ( )
981
+ . to_v0_p2wsh ( ) ;
982
+ out. value = confidential:: Value :: Explicit ( 99_001 ) ; // Changed to +1
983
+ out. asset = confidential:: Asset :: Explicit ( AssetId :: from_slice ( & BTC_ASSET ) . unwrap ( ) ) ;
984
+ let desc = Descriptor :: < bitcoin:: PublicKey > :: from_str ( & format ! (
985
+ "elcovwsh({},outputs_pref({}))" ,
986
+ pks[ 0 ] ,
987
+ serialize( & out) . to_hex( ) ,
988
+ ) )
989
+ . unwrap ( ) ;
990
+ _satisfy_and_interpret ( desc, sks[ 0 ] ) . unwrap_err ( ) ;
937
991
}
938
992
939
993
// Fund output and spend tx are tests handy with code for
0 commit comments