@@ -30,8 +30,8 @@ fn channel_full_cycle() {
3030 ) ;
3131 node_a. sync_wallets ( ) . unwrap ( ) ;
3232 node_b. sync_wallets ( ) . unwrap ( ) ;
33- assert_eq ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
34- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
33+ assert_eq ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
34+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
3535
3636 println ! ( "\n A -- connect_open_channel -> B" ) ;
3737 let funding_amount_sat = 80_000 ;
@@ -67,12 +67,12 @@ fn channel_full_cycle() {
6767 node_b. sync_wallets ( ) . unwrap ( ) ;
6868
6969 let onchain_fee_buffer_sat = 1500 ;
70- let node_a_balance = node_a. on_chain_balance ( ) . unwrap ( ) ;
70+ let node_a_balance = node_a. onchain_balance ( ) . unwrap ( ) ;
7171 let node_a_upper_bound_sat = premine_amount_sat - funding_amount_sat;
7272 let node_a_lower_bound_sat = premine_amount_sat - funding_amount_sat - onchain_fee_buffer_sat;
7373 assert ! ( node_a_balance. get_spendable( ) < node_a_upper_bound_sat) ;
7474 assert ! ( node_a_balance. get_spendable( ) > node_a_lower_bound_sat) ;
75- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
75+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
7676
7777 expect_event ! ( node_a, ChannelReady ) ;
7878
@@ -195,13 +195,10 @@ fn channel_full_cycle() {
195195 let node_a_upper_bound_sat =
196196 ( premine_amount_sat - funding_amount_sat) + ( funding_amount_sat - sum_of_all_payments_sat) ;
197197 let node_a_lower_bound_sat = node_a_upper_bound_sat - onchain_fee_buffer_sat;
198- assert ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) > node_a_lower_bound_sat) ;
199- assert ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) < node_a_upper_bound_sat) ;
198+ assert ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) > node_a_lower_bound_sat) ;
199+ assert ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) < node_a_upper_bound_sat) ;
200200 let expected_final_amount_node_b_sat = premine_amount_sat + sum_of_all_payments_sat;
201- assert_eq ! (
202- node_b. on_chain_balance( ) . unwrap( ) . get_spendable( ) ,
203- expected_final_amount_node_b_sat
204- ) ;
201+ assert_eq ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) , expected_final_amount_node_b_sat) ;
205202
206203 node_a. stop ( ) . unwrap ( ) ;
207204 println ! ( "\n A stopped" ) ;
@@ -235,8 +232,8 @@ fn channel_open_fails_when_funds_insufficient() {
235232 ) ;
236233 node_a. sync_wallets ( ) . unwrap ( ) ;
237234 node_b. sync_wallets ( ) . unwrap ( ) ;
238- assert_eq ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
239- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
235+ assert_eq ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
236+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
240237
241238 println ! ( "\n A -- connect_open_channel -> B" ) ;
242239 assert_eq ! (
@@ -276,13 +273,13 @@ fn start_stop_reinit() {
276273 let expected_amount = Amount :: from_sat ( 100000 ) ;
277274
278275 premine_and_distribute_funds ( & bitcoind, & electrsd, vec ! [ funding_address] , expected_amount) ;
279- assert_eq ! ( node. on_chain_balance ( ) . unwrap( ) . get_total( ) , 0 ) ;
276+ assert_eq ! ( node. onchain_balance ( ) . unwrap( ) . get_total( ) , 0 ) ;
280277
281278 node. start ( ) . unwrap ( ) ;
282279 assert_eq ! ( node. start( ) , Err ( Error :: AlreadyRunning ) ) ;
283280
284281 node. sync_wallets ( ) . unwrap ( ) ;
285- assert_eq ! ( node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
282+ assert_eq ! ( node. onchain_balance ( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
286283
287284 node. stop ( ) . unwrap ( ) ;
288285 assert_eq ! ( node. stop( ) , Err ( Error :: NotRunning ) ) ;
@@ -300,15 +297,67 @@ fn start_stop_reinit() {
300297 reinitialized_node. start ( ) . unwrap ( ) ;
301298
302299 assert_eq ! (
303- reinitialized_node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) ,
300+ reinitialized_node. onchain_balance ( ) . unwrap( ) . get_spendable( ) ,
304301 expected_amount. to_sat( )
305302 ) ;
306303
307304 reinitialized_node. sync_wallets ( ) . unwrap ( ) ;
308305 assert_eq ! (
309- reinitialized_node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) ,
306+ reinitialized_node. onchain_balance ( ) . unwrap( ) . get_spendable( ) ,
310307 expected_amount. to_sat( )
311308 ) ;
312309
313310 reinitialized_node. stop ( ) . unwrap ( ) ;
314311}
312+
313+ #[ test]
314+ fn onchain_spend_receive ( ) {
315+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
316+ let esplora_url = electrsd. esplora_url . as_ref ( ) . unwrap ( ) ;
317+
318+ let config_a = random_config ( esplora_url) ;
319+ let node_a = Builder :: from_config ( config_a) . build ( ) ;
320+ node_a. start ( ) . unwrap ( ) ;
321+ let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
322+
323+ let config_b = random_config ( esplora_url) ;
324+ let node_b = Builder :: from_config ( config_b) . build ( ) ;
325+ node_b. start ( ) . unwrap ( ) ;
326+ let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
327+
328+ premine_and_distribute_funds (
329+ & bitcoind,
330+ & electrsd,
331+ vec ! [ addr_b. clone( ) ] ,
332+ Amount :: from_sat ( 100000 ) ,
333+ ) ;
334+
335+ node_a. sync_wallets ( ) . unwrap ( ) ;
336+ node_b. sync_wallets ( ) . unwrap ( ) ;
337+ assert_eq ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
338+
339+ assert_eq ! ( Err ( Error :: InsufficientFunds ) , node_a. send_to_onchain_address( & addr_b, 1000 ) ) ;
340+
341+ let txid = node_b. send_to_onchain_address ( & addr_a, 1000 ) . unwrap ( ) ;
342+ generate_blocks_and_wait ( & bitcoind, & electrsd, 6 ) ;
343+ wait_for_tx ( & electrsd, txid) ;
344+
345+ node_a. sync_wallets ( ) . unwrap ( ) ;
346+ node_b. sync_wallets ( ) . unwrap ( ) ;
347+
348+ assert_eq ! ( node_a. onchain_balance( ) . unwrap( ) . get_spendable( ) , 1000 ) ;
349+ assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) > 98000 ) ;
350+ assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) < 100000 ) ;
351+
352+ let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
353+ let txid = node_a. send_all_to_onchain_address ( & addr_b) . unwrap ( ) ;
354+ generate_blocks_and_wait ( & bitcoind, & electrsd, 6 ) ;
355+ wait_for_tx ( & electrsd, txid) ;
356+
357+ node_a. sync_wallets ( ) . unwrap ( ) ;
358+ node_b. sync_wallets ( ) . unwrap ( ) ;
359+
360+ assert_eq ! ( node_a. onchain_balance( ) . unwrap( ) . get_total( ) , 0 ) ;
361+ assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) > 99000 ) ;
362+ assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) < 100000 ) ;
363+ }
0 commit comments