@@ -244,7 +244,7 @@ fn channel_open_fails_when_funds_insufficient() {
244244 node_b. listening_address( ) . unwrap( ) ,
245245 120000 ,
246246 None ,
247- true
247+ true ,
248248 )
249249 ) ;
250250}
@@ -362,3 +362,93 @@ fn onchain_spend_receive() {
362362 assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) > 99000 ) ;
363363 assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) < 100000 ) ;
364364}
365+
366+ #[ test]
367+ fn channel_full_cycle_0conf ( ) {
368+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
369+ println ! ( "== Node A ==" ) ;
370+ let esplora_url = electrsd. esplora_url . as_ref ( ) . unwrap ( ) ;
371+ let config_a = random_config ( esplora_url) ;
372+ let node_a = Builder :: from_config ( config_a) . build ( ) ;
373+ node_a. start ( ) . unwrap ( ) ;
374+ let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
375+
376+ println ! ( "\n == Node B ==" ) ;
377+ let mut config_b = random_config ( esplora_url) ;
378+ config_b. peers_trusted_0conf . push ( node_a. node_id ( ) ) ;
379+
380+ let node_b = Builder :: from_config ( config_b) . build ( ) ;
381+ node_b. start ( ) . unwrap ( ) ;
382+ let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
383+
384+ let premine_amount_sat = 100_000 ;
385+
386+ premine_and_distribute_funds (
387+ & bitcoind,
388+ & electrsd,
389+ vec ! [ addr_a, addr_b] ,
390+ Amount :: from_sat ( premine_amount_sat) ,
391+ ) ;
392+ node_a. sync_wallets ( ) . unwrap ( ) ;
393+ node_b. sync_wallets ( ) . unwrap ( ) ;
394+ assert_eq ! ( node_a. onchain_balance( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
395+ assert_eq ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
396+
397+ println ! ( "\n A -- connect_open_channel -> B" ) ;
398+ let funding_amount_sat = 80_000 ;
399+ let push_msat = ( funding_amount_sat / 2 ) * 1000 ; // balance the channel
400+ node_a
401+ . connect_open_channel (
402+ node_b. node_id ( ) ,
403+ node_b. listening_address ( ) . unwrap ( ) ,
404+ funding_amount_sat,
405+ Some ( push_msat) ,
406+ true ,
407+ )
408+ . unwrap ( ) ;
409+
410+ node_a. sync_wallets ( ) . unwrap ( ) ;
411+ node_b. sync_wallets ( ) . unwrap ( ) ;
412+
413+ expect_event ! ( node_a, ChannelPending ) ;
414+
415+ let _funding_txo = match node_b. next_event ( ) {
416+ ref e @ Event :: ChannelPending { funding_txo, .. } => {
417+ println ! ( "{} got event {:?}" , std:: stringify!( node_b) , e) ;
418+ node_b. event_handled ( ) ;
419+ funding_txo
420+ }
421+ ref e => {
422+ panic ! ( "{} got unexpected event!: {:?}" , std:: stringify!( node_b) , e) ;
423+ }
424+ } ;
425+
426+ node_a. sync_wallets ( ) . unwrap ( ) ;
427+ node_b. sync_wallets ( ) . unwrap ( ) ;
428+
429+ expect_event ! ( node_a, ChannelReady ) ;
430+ let _channel_id = match node_b. next_event ( ) {
431+ ref e @ Event :: ChannelReady { ref channel_id, .. } => {
432+ println ! ( "{} got event {:?}" , std:: stringify!( node_b) , e) ;
433+ node_b. event_handled ( ) ;
434+ channel_id. clone ( )
435+ }
436+ ref e => {
437+ panic ! ( "{} got unexpected event!: {:?}" , std:: stringify!( node_b) , e) ;
438+ }
439+ } ;
440+
441+ node_a. sync_wallets ( ) . unwrap ( ) ;
442+ node_b. sync_wallets ( ) . unwrap ( ) ;
443+
444+ println ! ( "\n B receive_payment" ) ;
445+ let invoice_amount_1_msat = 1000000 ;
446+ let invoice = node_b. receive_payment ( invoice_amount_1_msat, & "asdf" , 9217 ) . unwrap ( ) ;
447+
448+ println ! ( "\n A send_payment" ) ;
449+ let payment_hash = node_a. send_payment ( & invoice) . unwrap ( ) ;
450+ expect_event ! ( node_a, PaymentSuccessful ) ;
451+ expect_event ! ( node_b, PaymentReceived ) ;
452+ assert_eq ! ( node_a. payment( & payment_hash) . unwrap( ) . status, PaymentStatus :: Succeeded ) ;
453+ assert_eq ! ( node_a. payment( & payment_hash) . unwrap( ) . direction, PaymentDirection :: Outbound ) ;
454+ }
0 commit comments