33//! CheckSigFromStack integration tests
44//!
55
6- use miniscript:: extensions:: { sighash_msg_price_oracle_1, check_sig_price_oracle_1} ;
7- use miniscript:: { elements, bitcoin, TxEnv } ;
86use elements:: pset:: PartiallySignedTransaction as Psbt ;
97use elements:: sighash:: SigHashCache ;
108use elements:: taproot:: { LeafVersion , TapLeafHash } ;
119use elements:: {
12- confidential, pset as psbt, secp256k1_zkp as secp256k1, sighash, OutPoint , Script ,
13- Sequence , TxIn , TxOut , Txid ,
10+ confidential, pset as psbt, secp256k1_zkp as secp256k1, sighash, OutPoint , Script , Sequence ,
11+ TxIn , TxOut , Txid ,
1412} ;
1513use elementsd:: ElementsD ;
14+ use miniscript:: extensions:: { check_sig_price_oracle_1, sighash_msg_price_oracle_1} ;
1615use miniscript:: psbt:: { PsbtInputExt , PsbtInputSatisfier } ;
17- use miniscript:: { Descriptor , Satisfier , ToPublicKey } ;
16+ use miniscript:: { bitcoin , elements , Descriptor , Satisfier , ToPublicKey , TxEnv } ;
1817use rand:: RngCore ;
1918mod setup;
2019use setup:: test_util:: { self , TestData , PARAMS } ;
@@ -137,10 +136,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
137136 let x_only_pk = secp256k1:: XOnlyPublicKey :: from_keypair ( & keypair) . 0 ;
138137 psbt. inputs_mut ( ) [ 0 ] . tap_script_sigs . insert (
139138 ( x_only_pk, leaf_hash) ,
140- elements:: SchnorrSig {
141- sig,
142- hash_ty,
143- } ,
139+ elements:: SchnorrSig { sig, hash_ty } ,
144140 ) ;
145141 }
146142 }
@@ -181,10 +177,10 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
181177 }
182178
183179 fn lookup_price_oracle_sig (
184- & self ,
185- pk : & bitcoin:: key:: XOnlyPublicKey ,
186- time : u64 ,
187- ) -> Option < ( secp256k1:: schnorr:: Signature , i64 , u64 ) > {
180+ & self ,
181+ pk : & bitcoin:: key:: XOnlyPublicKey ,
182+ time : u64 ,
183+ ) -> Option < ( secp256k1:: schnorr:: Signature , i64 , u64 ) > {
188184 let xpk = pk. to_x_only_pubkey ( ) ;
189185 let known_xpks = & self . 0 . pubdata . x_only_pks ;
190186 let i = known_xpks. iter ( ) . position ( |& x| x == xpk) . unwrap ( ) ;
@@ -199,7 +195,13 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
199195
200196 let secp = secp256k1:: Secp256k1 :: new ( ) ;
201197 let sig = secp. sign_schnorr_with_aux_rand ( & sighash_msg, keypair, & aux_rand) ;
202- assert ! ( check_sig_price_oracle_1( & secp, & sig, & xpk, time_signed, price) ) ;
198+ assert ! ( check_sig_price_oracle_1(
199+ & secp,
200+ & sig,
201+ & xpk,
202+ time_signed,
203+ price
204+ ) ) ;
203205 Some ( ( sig, self . 0 . pubdata . price , time_signed) )
204206 }
205207 }
@@ -210,7 +212,7 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
210212 let mut tx = psbt. extract_tx ( ) . unwrap ( ) ;
211213 let txouts = vec ! [ psbt. inputs( ) [ 0 ] . witness_utxo. clone( ) . unwrap( ) ] ;
212214 let extracted_tx = tx. clone ( ) ; // Possible to optimize this, but we don't care for this
213- // Env requires reference of tx, while satisfaction requires mutable access to inputs.
215+ // Env requires reference of tx, while satisfaction requires mutable access to inputs.
214216 let cov_sat = TxEnv :: new ( & extracted_tx, & txouts, 0 ) . unwrap ( ) ;
215217 derived_desc
216218 . satisfy ( & mut tx. input [ 0 ] , ( psbt_sat, csfs_sat, cov_sat) )
@@ -220,7 +222,6 @@ pub fn test_desc_satisfy(cl: &ElementsD, testdata: &TestData, desc: &str) -> Vec
220222 println ! ( "Witness: {} {:x?}" , wit. len( ) , wit) ;
221223 }
222224
223-
224225 // Send the transactions to bitcoin node for mining.
225226 // Regtest mode has standardness checks
226227 // Check whether the node accepts the transactions
@@ -258,14 +259,36 @@ fn test_descs(cl: &ElementsD, testdata: &TestData) {
258259
259260 // test price oracle 1
260261 let price = testdata. pubdata . price ;
261- let wit = test_desc_satisfy ( cl, testdata, & format ! ( "tr(X!,and_v(v:pk(X2),num64_eq(price_oracle1(X1,123213),{})))" , price) ) ;
262+ let wit = test_desc_satisfy (
263+ cl,
264+ testdata,
265+ & format ! (
266+ "tr(X!,and_v(v:pk(X2),num64_eq(price_oracle1(X1,123213),{})))" ,
267+ price
268+ ) ,
269+ ) ;
262270 assert_eq ! ( wit. len( ) , 4 + 2 ) ; // 4 witness elements + 1 for price oracle + 1 for time
263271
264272 // More complex tests
265- test_desc_satisfy ( cl, testdata, "tr(X!,and_v(v:pk(X1),num64_eq(price_oracle1(X2,1),price_oracle1_w(X3,2))))" ) ;
266- test_desc_satisfy ( cl, testdata, & format ! ( "tr(X!,and_v(v:pk(X1),num64_eq({},price_oracle1_w(X3,2))))" , price) ) ;
273+ test_desc_satisfy (
274+ cl,
275+ testdata,
276+ "tr(X!,and_v(v:pk(X1),num64_eq(price_oracle1(X2,1),price_oracle1_w(X3,2))))" ,
277+ ) ;
278+ test_desc_satisfy (
279+ cl,
280+ testdata,
281+ & format ! (
282+ "tr(X!,and_v(v:pk(X1),num64_eq({},price_oracle1_w(X3,2))))" ,
283+ price
284+ ) ,
285+ ) ;
267286 // Different keys and different times
268- test_desc_satisfy ( cl, testdata, "tr(X!,and_v(v:pk(X2),num64_eq(price_oracle1(X3,1),price_oracle1_w(X4,23))))" ) ;
287+ test_desc_satisfy (
288+ cl,
289+ testdata,
290+ "tr(X!,and_v(v:pk(X2),num64_eq(price_oracle1(X3,1),price_oracle1_w(X4,23))))" ,
291+ ) ;
269292 // Combination with other arith fragments
270293 test_desc_satisfy ( cl, testdata, "tr(X!,and_v(v:pk(X2),num64_eq(div(add(price_oracle1(X3,1),price_oracle1_w(X4,2)),2),price_oracle1_w(X5,2))))" ) ;
271294}
0 commit comments