@@ -413,37 +413,8 @@ pub mod test {
413413 TaprootScriptSpend3 ,
414414 }
415415
416- fn init_wallet (
417- ty : WalletType ,
418- chain_type : BlockchainType ,
419- ) -> (
420- Wallet < MemoryDatabase > ,
421- AnyBlockchain ,
422- ( String , Option < String > ) ,
423- TestClient ,
424- ) {
425- let _ = env_logger:: try_init ( ) ;
426-
427- let descriptors = match ty {
428- WalletType :: WpkhSingleSig => testutils ! {
429- @descriptors ( "wpkh(Alice)" ) ( "wpkh(Alice)" ) ( @keys ( "Alice" => ( @generate_xprv "/44'/0'/0'/0/*" , "/44'/0'/0'/1/*" ) ) )
430- } ,
431- WalletType :: TaprootKeySpend => testutils ! {
432- @descriptors ( "tr(Alice)" ) ( "tr(Alice)" ) ( @keys ( "Alice" => ( @generate_xprv "/44'/0'/0'/0/*" , "/44'/0'/0'/1/*" ) ) )
433- } ,
434- WalletType :: TaprootScriptSpend => testutils ! {
435- @descriptors ( "tr(Key,and_v(v:pk(Script),older(6)))" ) ( "tr(Key,and_v(v:pk(Script),older(6)))" ) ( @keys ( "Key" => ( @literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788" ) , "Script" => ( @generate_xprv "/0/*" , "/1/*" ) ) )
436- } ,
437- WalletType :: TaprootScriptSpend2 => testutils ! {
438- @descriptors ( "tr(Alice,pk(Bob))" ) ( "tr(Alice,pk(Bob))" ) ( @keys ( "Alice" => ( @literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788" ) , "Bob" => ( @generate_xprv "/0/*" , "/1/*" ) ) )
439- } ,
440- WalletType :: TaprootScriptSpend3 => testutils ! {
441- @descriptors ( "tr(Alice,{pk(Bob),pk(Carol)})" ) ( "tr(Alice,{pk(Bob),pk(Carol)})" ) ( @keys ( "Alice" => ( @literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788" ) , "Bob" => ( @generate_xprv "/0/*" , "/1/*" ) , "Carol" => ( @generate_xprv "/0/*" , "/1/*" ) ) )
442- } ,
443- } ;
444-
445- let test_client = TestClient :: default ( ) ;
446- let blockchain: AnyBlockchain = match chain_type {
416+ fn get_blockchain ( test_client : & TestClient , chain_type : BlockchainType ) -> AnyBlockchain {
417+ match chain_type {
447418 #[ cfg( any( feature = "test-rpc" , feature = "test-rpc-legacy" ) ) ]
448419 BlockchainType :: RpcBlockchain => {
449420 let config = RpcConfig {
@@ -481,7 +452,40 @@ pub mod test {
481452 electrum_client:: new ( & test_client. electrsd . electrum_url ) . unwrap ( ) ,
482453 ) ) )
483454 }
455+ }
456+ }
457+
458+ fn init_wallet (
459+ ty : WalletType ,
460+ chain_type : BlockchainType ,
461+ ) -> (
462+ Wallet < MemoryDatabase > ,
463+ AnyBlockchain ,
464+ ( String , Option < String > ) ,
465+ TestClient ,
466+ ) {
467+ let _ = env_logger:: try_init ( ) ;
468+
469+ let descriptors = match ty {
470+ WalletType :: WpkhSingleSig => testutils ! {
471+ @descriptors ( "wpkh(Alice)" ) ( "wpkh(Alice)" ) ( @keys ( "Alice" => ( @generate_xprv "/44'/0'/0'/0/*" , "/44'/0'/0'/1/*" ) ) )
472+ } ,
473+ WalletType :: TaprootKeySpend => testutils ! {
474+ @descriptors ( "tr(Alice)" ) ( "tr(Alice)" ) ( @keys ( "Alice" => ( @generate_xprv "/44'/0'/0'/0/*" , "/44'/0'/0'/1/*" ) ) )
475+ } ,
476+ WalletType :: TaprootScriptSpend => testutils ! {
477+ @descriptors ( "tr(Key,and_v(v:pk(Script),older(6)))" ) ( "tr(Key,and_v(v:pk(Script),older(6)))" ) ( @keys ( "Key" => ( @literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788" ) , "Script" => ( @generate_xprv "/0/*" , "/1/*" ) ) )
478+ } ,
479+ WalletType :: TaprootScriptSpend2 => testutils ! {
480+ @descriptors ( "tr(Alice,pk(Bob))" ) ( "tr(Alice,pk(Bob))" ) ( @keys ( "Alice" => ( @literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788" ) , "Bob" => ( @generate_xprv "/0/*" , "/1/*" ) ) )
481+ } ,
482+ WalletType :: TaprootScriptSpend3 => testutils ! {
483+ @descriptors ( "tr(Alice,{pk(Bob),pk(Carol)})" ) ( "tr(Alice,{pk(Bob),pk(Carol)})" ) ( @keys ( "Alice" => ( @literal "30e14486f993d5a2d222770e97286c56cec5af115e1fb2e0065f476a0fcf8788" ) , "Bob" => ( @generate_xprv "/0/*" , "/1/*" ) , "Carol" => ( @generate_xprv "/0/*" , "/1/*" ) ) )
484+ } ,
484485 } ;
486+
487+ let test_client = TestClient :: default ( ) ;
488+ let blockchain: AnyBlockchain = get_blockchain ( & test_client, chain_type) ;
485489 let wallet = get_wallet_from_descriptors ( & descriptors) ;
486490
487491 // rpc need to call import_multi before receiving any tx, otherwise will not see tx in the mempool
@@ -491,49 +495,6 @@ pub mod test {
491495 ( wallet, blockchain, descriptors, test_client)
492496 }
493497
494- fn get_blockchain ( test_client : & TestClient , chain_type : BlockchainType ) -> AnyBlockchain {
495- let blockchain: AnyBlockchain = match chain_type {
496- #[ cfg( any( feature = "test-rpc" , feature = "test-rpc-legacy" ) ) ]
497- BlockchainType :: RpcBlockchain => {
498- let config = RpcConfig {
499- url : test_client. bitcoind . rpc_url ( ) ,
500- auth : Auth :: Cookie {
501- file : test_client. bitcoind . params . cookie_file . clone ( ) ,
502- } ,
503- network : Network :: Regtest ,
504- wallet_name : format ! (
505- "client-wallet-test-{}" ,
506- std:: time:: SystemTime :: now( )
507- . duration_since( std:: time:: UNIX_EPOCH )
508- . unwrap( )
509- . as_nanos( )
510- ) ,
511- skip_blocks : None ,
512- } ;
513- AnyBlockchain :: Rpc ( Box :: new ( RpcBlockchain :: from_config ( & config) . unwrap ( ) ) )
514- }
515-
516- #[ cfg( feature = "test-esplora" ) ]
517- BlockchainType :: EsploraBlockchain => {
518- AnyBlockchain :: Esplora ( Box :: new ( EsploraBlockchain :: new (
519- & format ! (
520- "http://{}" ,
521- test_client. electrsd. esplora_url. as_ref( ) . unwrap( )
522- ) ,
523- 20 ,
524- ) ) )
525- }
526-
527- #[ cfg( feature = "test-electrum" ) ]
528- BlockchainType :: ElectrumBlockchain => {
529- AnyBlockchain :: Electrum ( Box :: new ( ElectrumBlockchain :: from (
530- electrum_client:: new ( & test_client. electrsd . electrum_url ) . unwrap ( ) ,
531- ) ) )
532- }
533- } ;
534- blockchain
535- }
536-
537498 fn init_single_sig (
538499 chain_type : BlockchainType ,
539500 ) -> (
@@ -1822,10 +1783,11 @@ pub mod test {
18221783 assert_eq ! ( finalized, true ) ;
18231784 }
18241785}
1786+
18251787#[ macro_export]
18261788#[ doc( hidden) ]
18271789macro_rules! make_blockchain_tests {
1828- ( @ type $chain_type: expr, @ tests ( $( $x: tt) , + $( , ) ? ) ) => {
1790+ ( blockchain $chain_type: expr, tests ( $( $x: tt) , + $( , ) ? ) ) => {
18291791 $(
18301792 #[ test]
18311793 fn $x( )
0 commit comments