@@ -13,7 +13,7 @@ use bitcoin::util::{psbt, sighash};
1313use bitcoin:: { self , Amount , OutPoint , SchnorrSig , Script , Transaction , TxIn , TxOut , Txid } ;
1414use bitcoincore_rpc:: { json, Client , RpcApi } ;
1515use miniscript:: miniscript:: iter;
16- use miniscript:: psbt:: PbstOps ;
16+ use miniscript:: psbt:: PsbtExt ;
1717use miniscript:: { Descriptor , DescriptorTrait , Miniscript , ToPublicKey } ;
1818use miniscript:: { MiniscriptKey , ScriptContext } ;
1919use std:: collections:: BTreeMap ;
@@ -40,17 +40,17 @@ fn get_vout(cl: &Client, txid: Txid, value: u64, spk: Script) -> (OutPoint, TxOu
4040 unreachable ! ( "Only call get vout on functions which have the expected outpoint" ) ;
4141}
4242
43- pub fn test_desc_satisfy ( cl : & Client , testdata : & TestData , desc : String ) -> Witness {
43+ pub fn test_desc_satisfy ( cl : & Client , testdata : & TestData , desc : & str ) -> Witness {
4444 let secp = secp256k1:: Secp256k1 :: new ( ) ;
4545 let sks = & testdata. secretdata . sks ;
4646 let xonly_keypairs = & testdata. secretdata . x_only_keypairs ;
4747 let pks = & testdata. pubdata . pks ;
4848 let x_only_pks = & testdata. pubdata . x_only_pks ;
4949 // Generate some blocks
5050 let blocks = cl
51- . generate_to_address ( 500 , & cl. get_new_address ( None , None ) . unwrap ( ) )
51+ . generate_to_address ( 1 , & cl. get_new_address ( None , None ) . unwrap ( ) )
5252 . unwrap ( ) ;
53- assert_eq ! ( blocks. len( ) , 500 ) ;
53+ assert_eq ! ( blocks. len( ) , 1 ) ;
5454
5555 let desc = test_util:: parse_test_desc ( & desc, & testdata. pubdata ) ;
5656 let derived_desc = desc. derived_descriptor ( & secp, 0 ) . unwrap ( ) ;
@@ -69,9 +69,9 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: String) -> Witn
6969 . unwrap ( ) ;
7070 // Wait for the funds to mature.
7171 let blocks = cl
72- . generate_to_address ( 50 , & cl. get_new_address ( None , None ) . unwrap ( ) )
72+ . generate_to_address ( 2 , & cl. get_new_address ( None , None ) . unwrap ( ) )
7373 . unwrap ( ) ;
74- assert_eq ! ( blocks. len( ) , 50 ) ;
74+ assert_eq ! ( blocks. len( ) , 2 ) ;
7575 // Create a PSBT for each transaction.
7676 // Spend one input and spend one output for simplicity.
7777 let mut psbt = Psbt {
@@ -95,8 +95,8 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: String) -> Witn
9595 txin. previous_output = outpoint;
9696 // set the sequence to a non-final number for the locktime transactions to be
9797 // processed correctly.
98- // We waited 50 blocks, keep 49 for safety
99- txin. sequence = 49 ;
98+ // We waited 2 blocks, keep 1 for safety
99+ txin. sequence = 1 ;
100100 psbt. unsigned_tx . input . push ( txin) ;
101101 // Get a new script pubkey from the node so that
102102 // the node wallet tracks the receiving transaction
@@ -112,7 +112,7 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: String) -> Witn
112112 input. witness_utxo = Some ( witness_utxo. clone ( ) ) ;
113113 psbt. inputs . push ( input) ;
114114 psbt. outputs . push ( psbt:: Output :: default ( ) ) ;
115- psbt. update_desc ( 0 , & desc, 0 .. 0 ) . unwrap ( ) ;
115+ psbt. update_desc ( 0 , & desc, None ) . unwrap ( ) ;
116116
117117 // --------------------------------------------
118118 // Sign the transactions with all keys
@@ -134,7 +134,9 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: String) -> Witn
134134
135135 if let Some ( mut internal_keypair) = internal_keypair {
136136 // ---------------------- Tr key spend --------------------
137- internal_keypair. tweak_add_assign ( & secp, tr. spend_info ( ) . tap_tweak ( ) . as_ref ( ) ) ;
137+ internal_keypair
138+ . tweak_add_assign ( & secp, tr. spend_info ( ) . tap_tweak ( ) . as_ref ( ) )
139+ . expect ( "Tweaking failed" ) ;
138140 let sighash_msg = sighash_cache
139141 . taproot_key_spend_signature_hash ( 0 , & prevouts, hash_ty)
140142 . unwrap ( ) ;
@@ -218,7 +220,10 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: String) -> Witn
218220 } ,
219221 Descriptor :: Tr ( _tr) => unreachable ! ( "Tr checked earlier" ) ,
220222 } ;
221- let msg = psbt. sighash_msg ( 0 , & mut sighash_cache, None ) . unwrap ( ) . to_secp_msg ( ) ;
223+ let msg = psbt
224+ . sighash_msg ( 0 , & mut sighash_cache, None )
225+ . unwrap ( )
226+ . to_secp_msg ( ) ;
222227
223228 // Fixme: Take a parameter
224229 let hash_ty = bitcoin:: EcdsaSigHashType :: All ;
@@ -227,6 +232,7 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: String) -> Witn
227232 for sk in sks_reqd {
228233 let sig = secp. sign_ecdsa ( & msg, & sk) ;
229234 let pk = pks[ sks. iter ( ) . position ( |& x| x == sk) . unwrap ( ) ] ;
235+ assert ! ( secp. verify_ecdsa( & msg, & sig, & pk. inner) . is_ok( ) ) ;
230236 psbt. inputs [ 0 ] . partial_sigs . insert (
231237 pk. inner ,
232238 bitcoin:: EcdsaSig {
@@ -257,9 +263,12 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: String) -> Witn
257263 println ! ( "Testing descriptor: {}" , desc) ;
258264 // Finalize the transaction using psbt
259265 // Let miniscript do it's magic!
260- if let Err ( e) = psbt. finalize ( & secp) {
266+ if let Err ( e) = psbt. finalize_mut ( & secp) {
261267 // All miniscripts should satisfy
262- panic ! ( "Could not satisfy non-malleably: error{} desc:{} " , e, desc) ;
268+ panic ! (
269+ "Could not satisfy non-malleably: error{} desc:{} " ,
270+ e[ 0 ] , desc
271+ ) ;
263272 }
264273 let tx = psbt. extract ( & secp) . expect ( "Extraction error" ) ;
265274
@@ -272,7 +281,7 @@ pub fn test_desc_satisfy(cl: &Client, testdata: &TestData, desc: String) -> Witn
272281
273282 // Finally mine the blocks and await confirmations
274283 let _blocks = cl
275- . generate_to_address ( 10 , & cl. get_new_address ( None , None ) . unwrap ( ) )
284+ . generate_to_address ( 1 , & cl. get_new_address ( None , None ) . unwrap ( ) )
276285 . unwrap ( ) ;
277286 // Get the required transactions from the node mined in the blocks.
278287 // Check whether the transaction is mined in blocks
@@ -310,8 +319,6 @@ fn find_sks_ms<Ctx: ScriptContext>(
310319fn find_sk_single_key ( pk : bitcoin:: PublicKey , testdata : & TestData ) -> Vec < secp256k1:: SecretKey > {
311320 let sks = & testdata. secretdata . sks ;
312321 let pks = & testdata. pubdata . pks ;
313- let i = pks
314- . iter ( )
315- . position ( |& x| x. to_public_key ( ) == pk) ;
322+ let i = pks. iter ( ) . position ( |& x| x. to_public_key ( ) == pk) ;
316323 i. map ( |idx| vec ! [ sks[ idx] ] ) . unwrap_or ( Vec :: new ( ) )
317324}
0 commit comments