@@ -363,20 +363,33 @@ fn list_wallet_dir(client: &Client) -> Result<Vec<String>, Error> {
363363 Ok ( result. wallets . into_iter ( ) . map ( |n| n. name ) . collect ( ) )
364364}
365365
366- #[ cfg( test) ]
367- #[ cfg( feature = "test-rpc" ) ]
368- #[ bdk_blockchain_tests( crate ) ]
369- fn local_rpc ( ) -> RpcBlockchain {
370- let exe = std:: env:: var ( "BITCOIND_EXE" ) . unwrap ( ) ;
371- let bitcoind = bitcoind:: BitcoinD :: new ( exe) . unwrap ( ) ;
372- let config = RpcConfig {
373- url : bitcoind. url . clone ( ) ,
374- auth : Auth :: CookieFile ( bitcoind. cookie_file . clone ( ) ) ,
375- network : Network :: Regtest ,
376- wallet_name : "bdk-test" . to_string ( ) ,
377- skip_blocks : None ,
378- } ;
379- RpcBlockchain :: from_config ( & config) . unwrap ( )
366+ #[ cfg( feature = "test-blockchains" ) ]
367+ crate :: bdk_blockchain_tests! {
368+
369+ fn test_instance( ) -> RpcBlockchain {
370+ let url = std:: env:: var( "BDK_RPC_URL" ) . unwrap_or_else( |_| "127.0.0.1:18443" . to_string( ) ) ;
371+ let url = format!( "http://{}" , url) ;
372+
373+ // TODO same code in `fn get_auth` in testutils, make it public there
374+ let auth = match std:: env:: var( "BDK_RPC_AUTH" ) . as_ref( ) . map( String :: as_ref) {
375+ Ok ( "USER_PASS" ) => Auth :: UserPass (
376+ std:: env:: var( "BDK_RPC_USER" ) . unwrap( ) ,
377+ std:: env:: var( "BDK_RPC_PASS" ) . unwrap( ) ,
378+ ) ,
379+ _ => Auth :: CookieFile ( std:: path:: PathBuf :: from(
380+ std:: env:: var( "BDK_RPC_COOKIEFILE" )
381+ . unwrap_or_else( |_| "/home/user/.bitcoin/regtest/.cookie" . to_string( ) ) ,
382+ ) ) ,
383+ } ;
384+ let config = RpcConfig {
385+ url,
386+ auth,
387+ network: Network :: Regtest ,
388+ wallet_name: "client-wallet-test" . to_string( ) ,
389+ skip_blocks: None ,
390+ } ;
391+ RpcBlockchain :: from_config( & config) . unwrap( )
392+ }
380393}
381394
382395#[ cfg( feature = "test-rpc" ) ]
@@ -417,14 +430,15 @@ mod test {
417430 }
418431 fn create_bitcoind ( args : Vec < String > ) -> BitcoinD {
419432 let exe = std:: env:: var ( "BITCOIND_EXE" ) . unwrap ( ) ;
420- bitcoind:: BitcoinD :: with_args ( exe, args, false ) . unwrap ( )
433+ bitcoind:: BitcoinD :: with_args ( exe, args, false , bitcoind :: P2P :: No ) . unwrap ( )
421434 }
422435
423436 const DESCRIPTOR_PUB : & ' static str = "wpkh(tpubD6NzVbkrYhZ4X2yy78HWrr1M9NT8dKeWfzNiQqDdMqqa9UmmGztGGz6TaLFGsLfdft5iu32gxq1T4eMNxExNNWzVCpf9Y6JZi5TnqoC9wJq/*)" ;
424437 const DESCRIPTOR_PRIV : & ' static str = "wpkh(tprv8ZgxMBicQKsPdZxBDUcvTSMEaLwCTzTc6gmw8KBKwa3BJzWzec4g6VUbQBHJcutDH6mMEmBeVyN27H1NF3Nu8isZ1Sts4SufWyfLE6Mf1MB/*)" ;
425438
426439 #[ test]
427440 fn test_rpc_wallet_setup ( ) {
441+ env_logger:: try_init ( ) . unwrap ( ) ;
428442 let bitcoind = create_bitcoind ( vec ! [ ] ) ;
429443 let node_address = bitcoind. client . get_new_address ( None , None ) . unwrap ( ) ;
430444 let blockchain = create_rpc ( & bitcoind, DESCRIPTOR_PUB , Network :: Regtest ) . unwrap ( ) ;
@@ -435,6 +449,8 @@ mod test {
435449 generate ( & bitcoind, 101 ) ;
436450 wallet. sync ( noop_progress ( ) , None ) . unwrap ( ) ;
437451 let address = wallet. get_address ( AddressIndex :: New ) . unwrap ( ) ;
452+ let expected_address = "bcrt1q8dyvgt4vhr8ald4xuwewcxhdjha9a5k78wxm5t" ;
453+ assert_eq ! ( expected_address, address. to_string( ) ) ;
438454 send_to_address ( & bitcoind, & address, 100_000 ) ;
439455 wallet. sync ( noop_progress ( ) , None ) . unwrap ( ) ;
440456 assert_eq ! ( wallet. get_balance( ) . unwrap( ) , 100_000 ) ;
@@ -467,11 +483,6 @@ mod test {
467483 let wallet_skip =
468484 Wallet :: new ( DESCRIPTOR_PRIV , None , Network :: Regtest , db, blockchain_skip) . unwrap ( ) ;
469485 send_to_address ( & bitcoind, & address, 100_000 ) ;
470- assert_eq ! (
471- "bcrt1q8dyvgt4vhr8ald4xuwewcxhdjha9a5k78wxm5t" ,
472- address. to_string( )
473- ) ;
474- println ! ( "address:{}" , & address) ;
475486 generate ( & bitcoind, 1 ) ; // TODO why this is needed even if list_unspent should include zero conf and unsafe?
476487 wallet_skip. sync ( noop_progress ( ) , None ) . unwrap ( ) ;
477488 assert_eq ! ( wallet_skip. get_balance( ) . unwrap( ) , 100_000 ) ;
0 commit comments