@@ -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 ;
@@ -60,12 +60,12 @@ fn channel_full_cycle() {
6060 node_b. sync_wallets ( ) . unwrap ( ) ;
6161
6262 let onchain_fee_buffer_sat = 1500 ;
63- let node_a_balance = node_a. on_chain_balance ( ) . unwrap ( ) ;
63+ let node_a_balance = node_a. onchain_balance ( ) . unwrap ( ) ;
6464 let node_a_upper_bound_sat = premine_amount_sat - funding_amount_sat;
6565 let node_a_lower_bound_sat = premine_amount_sat - funding_amount_sat - onchain_fee_buffer_sat;
6666 assert ! ( node_a_balance. get_spendable( ) < node_a_upper_bound_sat) ;
6767 assert ! ( node_a_balance. get_spendable( ) > node_a_lower_bound_sat) ;
68- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
68+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
6969
7070 expect_event ! ( node_a, ChannelReady ) ;
7171
@@ -188,13 +188,10 @@ fn channel_full_cycle() {
188188 let node_a_upper_bound_sat =
189189 ( premine_amount_sat - funding_amount_sat) + ( funding_amount_sat - sum_of_all_payments_sat) ;
190190 let node_a_lower_bound_sat = node_a_upper_bound_sat - onchain_fee_buffer_sat;
191- assert ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) > node_a_lower_bound_sat) ;
192- assert ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) < node_a_upper_bound_sat) ;
191+ assert ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) > node_a_lower_bound_sat) ;
192+ assert ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) < node_a_upper_bound_sat) ;
193193 let expected_final_amount_node_b_sat = premine_amount_sat + sum_of_all_payments_sat;
194- assert_eq ! (
195- node_b. on_chain_balance( ) . unwrap( ) . get_spendable( ) ,
196- expected_final_amount_node_b_sat
197- ) ;
194+ assert_eq ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) , expected_final_amount_node_b_sat) ;
198195
199196 node_a. stop ( ) . unwrap ( ) ;
200197 println ! ( "\n A stopped" ) ;
@@ -228,8 +225,8 @@ fn channel_open_fails_when_funds_insufficient() {
228225 ) ;
229226 node_a. sync_wallets ( ) . unwrap ( ) ;
230227 node_b. sync_wallets ( ) . unwrap ( ) ;
231- assert_eq ! ( node_a. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
232- assert_eq ! ( node_b. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
228+ assert_eq ! ( node_a. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
229+ assert_eq ! ( node_b. onchain_balance ( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
233230
234231 println ! ( "\n A -- connect_open_channel -> B" ) ;
235232 let node_b_addr = format ! ( "{}@{}" , node_b. node_id( ) , node_b. listening_address( ) . unwrap( ) ) ;
@@ -264,13 +261,13 @@ fn start_stop_reinit() {
264261 let expected_amount = Amount :: from_sat ( 100000 ) ;
265262
266263 premine_and_distribute_funds ( & bitcoind, & electrsd, vec ! [ funding_address] , expected_amount) ;
267- assert_eq ! ( node. on_chain_balance ( ) . unwrap( ) . get_total( ) , 0 ) ;
264+ assert_eq ! ( node. onchain_balance ( ) . unwrap( ) . get_total( ) , 0 ) ;
268265
269266 node. start ( ) . unwrap ( ) ;
270267 assert_eq ! ( node. start( ) , Err ( Error :: AlreadyRunning ) ) ;
271268
272269 node. sync_wallets ( ) . unwrap ( ) ;
273- assert_eq ! ( node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
270+ assert_eq ! ( node. onchain_balance ( ) . unwrap( ) . get_spendable( ) , expected_amount. to_sat( ) ) ;
274271
275272 node. stop ( ) . unwrap ( ) ;
276273 assert_eq ! ( node. stop( ) , Err ( Error :: NotRunning ) ) ;
@@ -288,15 +285,55 @@ fn start_stop_reinit() {
288285 reinitialized_node. start ( ) . unwrap ( ) ;
289286
290287 assert_eq ! (
291- reinitialized_node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) ,
288+ reinitialized_node. onchain_balance ( ) . unwrap( ) . get_spendable( ) ,
292289 expected_amount. to_sat( )
293290 ) ;
294291
295292 reinitialized_node. sync_wallets ( ) . unwrap ( ) ;
296293 assert_eq ! (
297- reinitialized_node. on_chain_balance ( ) . unwrap( ) . get_spendable( ) ,
294+ reinitialized_node. onchain_balance ( ) . unwrap( ) . get_spendable( ) ,
298295 expected_amount. to_sat( )
299296 ) ;
300297
301298 reinitialized_node. stop ( ) . unwrap ( ) ;
302299}
300+
301+ #[ test]
302+ fn onchain_spend_receive ( ) {
303+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
304+ let esplora_url = electrsd. esplora_url . as_ref ( ) . unwrap ( ) ;
305+
306+ let config_a = random_config ( esplora_url) ;
307+ let node_a = Builder :: from_config ( config_a) . build ( ) ;
308+ node_a. start ( ) . unwrap ( ) ;
309+ let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
310+
311+ let config_b = random_config ( esplora_url) ;
312+ let node_b = Builder :: from_config ( config_b) . build ( ) ;
313+ node_b. start ( ) . unwrap ( ) ;
314+ let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
315+
316+ premine_and_distribute_funds (
317+ & bitcoind,
318+ & electrsd,
319+ vec ! [ addr_b. clone( ) ] ,
320+ Amount :: from_sat ( 100000 ) ,
321+ ) ;
322+
323+ node_a. sync_wallets ( ) . unwrap ( ) ;
324+ node_b. sync_wallets ( ) . unwrap ( ) ;
325+ assert_eq ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) , 100000 ) ;
326+
327+ assert_eq ! ( Err ( Error :: InsufficientFunds ) , node_a. send_onchain_payment( & addr_b, 1000 ) ) ;
328+
329+ let txid = node_b. send_onchain_payment ( & addr_a, 1000 ) . unwrap ( ) ;
330+ generate_blocks_and_wait ( & bitcoind, & electrsd, 6 ) ;
331+ wait_for_tx ( & electrsd, txid) ;
332+
333+ node_a. sync_wallets ( ) . unwrap ( ) ;
334+ node_b. sync_wallets ( ) . unwrap ( ) ;
335+
336+ assert_eq ! ( node_a. onchain_balance( ) . unwrap( ) . get_spendable( ) , 1000 ) ;
337+ assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) > 98000 ) ;
338+ assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) < 100000 ) ;
339+ }
0 commit comments