@@ -364,3 +364,96 @@ fn onchain_spend_receive() {
364364 assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) > 99000 ) ;
365365 assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) < 100000 ) ;
366366}
367+
368+ #[ test]
369+ fn channel_full_cycle_0conf ( ) {
370+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
371+ println ! ( "== Node A ==" ) ;
372+ let esplora_url = electrsd. esplora_url . as_ref ( ) . unwrap ( ) ;
373+ let config_a = random_config ( esplora_url) ;
374+ let node_a = Builder :: from_config ( config_a) . build ( ) ;
375+ node_a. start ( ) . unwrap ( ) ;
376+ let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
377+
378+ println ! ( "\n == Node B ==" ) ;
379+ let config_b = random_config ( esplora_url) ;
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+ println ! ( "\n B -- connect -> A" ) ;
397+ node_b. connect ( node_a. node_id ( ) , node_a. listening_address ( ) . unwrap ( ) , true , true ) . unwrap ( ) ;
398+
399+ std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
400+
401+ println ! ( "\n A -- connect_open_channel -> B" ) ;
402+ let funding_amount_sat = 80_000 ;
403+ let push_msat = ( funding_amount_sat / 2 ) * 1000 ; // balance the channel
404+ node_a
405+ . connect_open_channel (
406+ node_b. node_id ( ) ,
407+ node_b. listening_address ( ) . unwrap ( ) ,
408+ funding_amount_sat,
409+ Some ( push_msat) ,
410+ true ,
411+ true ,
412+ )
413+ . unwrap ( ) ;
414+
415+ node_a. sync_wallets ( ) . unwrap ( ) ;
416+ node_b. sync_wallets ( ) . unwrap ( ) ;
417+
418+ expect_event ! ( node_a, ChannelPending ) ;
419+
420+ let _funding_txo = match node_b. next_event ( ) {
421+ ref e @ Event :: ChannelPending { funding_txo, .. } => {
422+ println ! ( "{} got event {:?}" , std:: stringify!( node_b) , e) ;
423+ node_b. event_handled ( ) ;
424+ funding_txo
425+ }
426+ ref e => {
427+ panic ! ( "{} got unexpected event!: {:?}" , std:: stringify!( node_b) , e) ;
428+ }
429+ } ;
430+
431+ node_a. sync_wallets ( ) . unwrap ( ) ;
432+ node_b. sync_wallets ( ) . unwrap ( ) ;
433+
434+ expect_event ! ( node_a, ChannelReady ) ;
435+ let _channel_id = match node_b. next_event ( ) {
436+ ref e @ Event :: ChannelReady { ref channel_id, .. } => {
437+ println ! ( "{} got event {:?}" , std:: stringify!( node_b) , e) ;
438+ node_b. event_handled ( ) ;
439+ channel_id. clone ( )
440+ }
441+ ref e => {
442+ panic ! ( "{} got unexpected event!: {:?}" , std:: stringify!( node_b) , e) ;
443+ }
444+ } ;
445+
446+ node_a. sync_wallets ( ) . unwrap ( ) ;
447+ node_b. sync_wallets ( ) . unwrap ( ) ;
448+
449+ println ! ( "\n B receive_payment" ) ;
450+ let invoice_amount_1_msat = 1000000 ;
451+ let invoice = node_b. receive_payment ( invoice_amount_1_msat, & "asdf" , 9217 ) . unwrap ( ) ;
452+
453+ println ! ( "\n A send_payment" ) ;
454+ let payment_hash = node_a. send_payment ( & invoice) . unwrap ( ) ;
455+ expect_event ! ( node_a, PaymentSuccessful ) ;
456+ expect_event ! ( node_b, PaymentReceived ) ;
457+ assert_eq ! ( node_a. payment( & payment_hash) . unwrap( ) . status, PaymentStatus :: Succeeded ) ;
458+ assert_eq ! ( node_a. payment( & payment_hash) . unwrap( ) . direction, PaymentDirection :: Outbound ) ;
459+ }
0 commit comments