@@ -936,6 +936,69 @@ async fn onchain_wallet_recovery() {
936936 ) ;
937937}
938938
939+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
940+ async fn onchain_wallet_force_full_scan_rediscovers_esplora_funds ( ) {
941+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
942+ let chain_source = TestChainSource :: Esplora ( & electrsd) ;
943+
944+ premine_blocks ( & bitcoind. client , & electrsd. client ) . await ;
945+
946+ let address_source_config = random_config ( true ) ;
947+ let node_entropy = address_source_config. node_entropy ;
948+ let address_source_node = setup_node ( & chain_source, address_source_config) ;
949+ let addr_1 = address_source_node. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
950+ let addr_2 = address_source_node. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
951+ address_source_node. stop ( ) . unwrap ( ) ;
952+ drop ( address_source_node) ;
953+
954+ let premine_amount_sat = 100_000 ;
955+ let mut stale_config = random_config ( true ) ;
956+ stale_config. node_entropy = node_entropy;
957+ stale_config. store_type = TestStoreType :: Sqlite ;
958+ let stale_node = setup_node ( & chain_source, stale_config. clone ( ) ) ;
959+ stale_node. sync_wallets ( ) . unwrap ( ) ;
960+ assert_eq ! ( stale_node. list_balances( ) . spendable_onchain_balance_sats, 0 ) ;
961+ stale_node. stop ( ) . unwrap ( ) ;
962+ drop ( stale_node) ;
963+
964+ let txid_1 = bitcoind
965+ . client
966+ . send_to_address ( & addr_1, Amount :: from_sat ( premine_amount_sat) )
967+ . unwrap ( )
968+ . 0
969+ . parse ( )
970+ . unwrap ( ) ;
971+ wait_for_tx ( & electrsd. client , txid_1) . await ;
972+ let txid_2 = bitcoind
973+ . client
974+ . send_to_address ( & addr_2, Amount :: from_sat ( premine_amount_sat) )
975+ . unwrap ( )
976+ . 0
977+ . parse ( )
978+ . unwrap ( ) ;
979+ wait_for_tx ( & electrsd. client , txid_2) . await ;
980+ generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 1 ) . await ;
981+
982+ let normal_node = setup_node ( & chain_source, stale_config. clone ( ) ) ;
983+ normal_node. sync_wallets ( ) . unwrap ( ) ;
984+ assert_eq ! (
985+ normal_node. list_balances( ) . spendable_onchain_balance_sats,
986+ 0 ,
987+ "normal incremental sync should not rediscover previously-unknown addresses"
988+ ) ;
989+ normal_node. stop ( ) . unwrap ( ) ;
990+ drop ( normal_node) ;
991+
992+ stale_config. force_wallet_full_scan = true ;
993+ let recovered_node = setup_node ( & chain_source, stale_config) ;
994+ recovered_node. sync_wallets ( ) . unwrap ( ) ;
995+ assert_eq ! (
996+ recovered_node. list_balances( ) . spendable_onchain_balance_sats,
997+ premine_amount_sat * 2 ,
998+ "forced full scan should rediscover funds sent to previously-unknown addresses"
999+ ) ;
1000+ }
1001+
9391002#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
9401003async fn onchain_wallet_recovery_rescans_from_birthday_height ( ) {
9411004 // End-to-end test for `wallet_rescan_from_height` against a bitcoind chain source. The
0 commit comments