@@ -7,14 +7,10 @@ use bdk_chain::{
77} ;
88use bdk_core:: bitcoin:: {
99 key:: { Secp256k1 , UntweakedPublicKey } ,
10- Network ,
10+ Denomination , Network ,
1111} ;
1212use bdk_electrum:: BdkElectrumClient ;
13- use bdk_testenv:: {
14- anyhow,
15- bitcoincore_rpc:: { json:: CreateRawTransactionInput , RawTx , RpcApi } ,
16- TestEnv ,
17- } ;
13+ use bdk_testenv:: { anyhow, TestEnv } ;
1814use core:: time:: Duration ;
1915use electrum_client:: ElectrumApi ;
2016use std:: collections:: { BTreeSet , HashMap , HashSet } ;
@@ -88,7 +84,8 @@ pub fn detect_receive_tx_cancel() -> anyhow::Result<()> {
8884 let client = BdkElectrumClient :: new ( electrum_client) ;
8985
9086 let mut graph = IndexedTxGraph :: < ConfirmationBlockTime , _ > :: new ( SpkTxOutIndex :: < ( ) > :: default ( ) ) ;
91- let ( chain, _) = LocalChain :: from_genesis_hash ( env. bitcoind . client . get_block_hash ( 0 ) ?) ;
87+ let ( chain, _) =
88+ LocalChain :: from_genesis_hash ( env. bitcoind . client . get_block_hash ( 0 ) ?. block_hash ( ) ?) ;
9289
9390 // Get receiving address.
9491 let receiver_spk = get_test_spk ( ) ;
@@ -198,7 +195,7 @@ pub fn chained_mempool_tx_sync() -> anyhow::Result<()> {
198195 let electrum_client = electrum_client:: Client :: new ( env. electrsd . electrum_url . as_str ( ) ) ?;
199196
200197 let tracked_addr = rpc_client
201- . get_new_address ( None , None ) ?
198+ . new_address ( ) ?
202199 . require_network ( Network :: Regtest ) ?;
203200
204201 env. mine_blocks ( 100 , None ) ?;
@@ -271,26 +268,16 @@ pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
271268 ] ;
272269
273270 let _block_hashes = env. mine_blocks ( 101 , None ) ?;
274- let txid1 = env. bitcoind . client . send_to_address (
275- & receive_address1,
276- Amount :: from_sat ( 10000 ) ,
277- None ,
278- None ,
279- None ,
280- None ,
281- Some ( 1 ) ,
282- None ,
283- ) ?;
284- let txid2 = env. bitcoind . client . send_to_address (
285- & receive_address0,
286- Amount :: from_sat ( 20000 ) ,
287- None ,
288- None ,
289- None ,
290- None ,
291- Some ( 1 ) ,
292- None ,
293- ) ?;
271+ let txid1 = env
272+ . bitcoind
273+ . client
274+ . send_to_address ( & receive_address1, Amount :: from_sat ( 10000 ) ) ?
275+ . txid ( ) ;
276+ let txid2 = env
277+ . bitcoind
278+ . client
279+ . send_to_address ( & receive_address0, Amount :: from_sat ( 20000 ) ) ?
280+ . txid ( ) ;
294281 env. mine_blocks ( 1 , None ) ?;
295282 env. wait_until_electrum_sees_block ( Duration :: from_secs ( 6 ) ) ?;
296283
@@ -337,7 +324,8 @@ pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> {
337324 let tx_fee = env
338325 . bitcoind
339326 . client
340- . get_transaction ( & tx. compute_txid ( ) , None )
327+ . get_transaction ( & tx. compute_txid ( ) ) ?
328+ . into
341329 . expect ( "Tx must exist" )
342330 . fee
343331 . expect ( "Fee must exist" )
@@ -393,16 +381,11 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
393381 . collect ( ) ;
394382
395383 // Then receive coins on the 4th address.
396- let txid_4th_addr = env. bitcoind . client . send_to_address (
397- & addresses[ 3 ] ,
398- Amount :: from_sat ( 10000 ) ,
399- None ,
400- None ,
401- None ,
402- None ,
403- Some ( 1 ) ,
404- None ,
405- ) ?;
384+ let txid_4th_addr = env
385+ . bitcoind
386+ . client
387+ . send_to_address ( & addresses[ 3 ] , Amount :: from_sat ( 10000 ) ) ?
388+ . txid ( ) ?;
406389 env. mine_blocks ( 1 , None ) ?;
407390 env. wait_until_electrum_sees_block ( Duration :: from_secs ( 6 ) ) ?;
408391
@@ -437,16 +420,11 @@ pub fn test_update_tx_graph_stop_gap() -> anyhow::Result<()> {
437420 assert_eq ! ( full_scan_update. last_active_indices[ & 0 ] , 3 ) ;
438421
439422 // Now receive a coin on the last address.
440- let txid_last_addr = env. bitcoind . client . send_to_address (
441- & addresses[ addresses. len ( ) - 1 ] ,
442- Amount :: from_sat ( 10000 ) ,
443- None ,
444- None ,
445- None ,
446- None ,
447- Some ( 1 ) ,
448- None ,
449- ) ?;
423+ let txid_last_addr = env
424+ . bitcoind
425+ . client
426+ . send_to_address ( & addresses[ addresses. len ( ) - 1 ] , Amount :: from_sat ( 10000 ) ) ?
427+ . txid ( ) ?;
450428 env. mine_blocks ( 1 , None ) ?;
451429 env. wait_until_electrum_sees_block ( Duration :: from_secs ( 6 ) ) ?;
452430
@@ -498,11 +476,7 @@ fn test_sync() -> anyhow::Result<()> {
498476 let client = BdkElectrumClient :: new ( electrum_client) ;
499477
500478 // Setup addresses.
501- let addr_to_mine = env
502- . bitcoind
503- . client
504- . get_new_address ( None , None ) ?
505- . assume_checked ( ) ;
479+ let addr_to_mine = env. bitcoind . client . new_address ( ) ?;
506480 let spk_to_track = ScriptBuf :: new_p2wsh ( & WScriptHash :: all_zeros ( ) ) ;
507481 let addr_to_track = Address :: from_script ( & spk_to_track, bdk_chain:: bitcoin:: Network :: Regtest ) ?;
508482
@@ -610,7 +584,7 @@ fn test_sync() -> anyhow::Result<()> {
610584 let tx_fee = env
611585 . bitcoind
612586 . client
613- . get_transaction ( & tx. txid , None )
587+ . get_transaction ( & tx. txid ) ?
614588 . expect ( "Tx must exist" )
615589 . fee
616590 . expect ( "Fee must exist" )
@@ -641,11 +615,7 @@ fn tx_can_become_unconfirmed_after_reorg() -> anyhow::Result<()> {
641615 let client = BdkElectrumClient :: new ( electrum_client) ;
642616
643617 // Setup addresses.
644- let addr_to_mine = env
645- . bitcoind
646- . client
647- . get_new_address ( None , None ) ?
648- . assume_checked ( ) ;
618+ let addr_to_mine = env. bitcoind . client . new_address ( ) ?;
649619 let spk_to_track = ScriptBuf :: new_p2wsh ( & WScriptHash :: all_zeros ( ) ) ;
650620 let addr_to_track = Address :: from_script ( & spk_to_track, bdk_chain:: bitcoin:: Network :: Regtest ) ?;
651621
@@ -784,10 +754,7 @@ fn test_check_fee_calculation() -> anyhow::Result<()> {
784754
785755 // Send a preliminary tx such that the new utxo in Core's wallet
786756 // becomes the input of the next tx
787- let new_addr = env
788- . rpc_client ( )
789- . get_new_address ( None , None ) ?
790- . assume_checked ( ) ;
757+ let new_addr = env. rpc_client ( ) . new_address ( ) ?;
791758 let prev_amt = SEND_AMOUNT + FEE_AMOUNT ;
792759 env. send ( & new_addr, prev_amt) ?;
793760 let prev_block_hash = env. mine_blocks ( 1 , None ) ?. into_iter ( ) . next ( ) ;
@@ -864,11 +831,12 @@ fn test_check_fee_calculation() -> anyhow::Result<()> {
864831 let tx_fee = env
865832 . bitcoind
866833 . client
867- . get_transaction ( & tx. txid , None )
834+ . get_transaction ( tx. txid )
868835 . expect ( "Tx must exist" )
869836 . fee
837+ . map ( |fee| Amount :: from_float_in ( fee. abs ( ) , Denomination :: BTC ) )
870838 . expect ( "Fee must exist" )
871- . abs ( )
839+ . expect ( "Amount parsing should succeed" )
872840 . to_sat ( ) as u64 ;
873841
874842 // Check that the calculated fee matches the fee from the transaction data.
0 commit comments