@@ -254,7 +254,7 @@ fn channel_open_fails_when_funds_insufficient() {
254254 node_b. listening_address( ) . unwrap( ) . into( ) ,
255255 120000 ,
256256 None ,
257- true
257+ true ,
258258 )
259259 ) ;
260260}
@@ -373,6 +373,96 @@ fn onchain_spend_receive() {
373373 assert ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) < 100000 ) ;
374374}
375375
376+ #[ test]
377+ fn channel_full_cycle_0conf ( ) {
378+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
379+ println ! ( "== Node A ==" ) ;
380+ let esplora_url = electrsd. esplora_url . as_ref ( ) . unwrap ( ) ;
381+ let config_a = random_config ( esplora_url) ;
382+ let node_a = Builder :: from_config ( config_a) . build ( ) ;
383+ node_a. start ( ) . unwrap ( ) ;
384+ let addr_a = node_a. new_funding_address ( ) . unwrap ( ) ;
385+
386+ println ! ( "\n == Node B ==" ) ;
387+ let mut config_b = random_config ( esplora_url) ;
388+ config_b. peers_trusted_0conf . push ( node_a. node_id ( ) ) ;
389+
390+ let node_b = Builder :: from_config ( config_b) . build ( ) ;
391+ node_b. start ( ) . unwrap ( ) ;
392+ let addr_b = node_b. new_funding_address ( ) . unwrap ( ) ;
393+
394+ let premine_amount_sat = 100_000 ;
395+
396+ premine_and_distribute_funds (
397+ & bitcoind,
398+ & electrsd,
399+ vec ! [ addr_a, addr_b] ,
400+ Amount :: from_sat ( premine_amount_sat) ,
401+ ) ;
402+ node_a. sync_wallets ( ) . unwrap ( ) ;
403+ node_b. sync_wallets ( ) . unwrap ( ) ;
404+ assert_eq ! ( node_a. onchain_balance( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
405+ assert_eq ! ( node_b. onchain_balance( ) . unwrap( ) . get_spendable( ) , premine_amount_sat) ;
406+
407+ println ! ( "\n A -- connect_open_channel -> B" ) ;
408+ let funding_amount_sat = 80_000 ;
409+ let push_msat = ( funding_amount_sat / 2 ) * 1000 ; // balance the channel
410+ node_a
411+ . connect_open_channel (
412+ node_b. node_id ( ) ,
413+ node_b. listening_address ( ) . unwrap ( ) ,
414+ funding_amount_sat,
415+ Some ( push_msat) ,
416+ true ,
417+ )
418+ . unwrap ( ) ;
419+
420+ node_a. sync_wallets ( ) . unwrap ( ) ;
421+ node_b. sync_wallets ( ) . unwrap ( ) ;
422+
423+ expect_event ! ( node_a, ChannelPending ) ;
424+
425+ let _funding_txo = match node_b. next_event ( ) {
426+ ref e @ Event :: ChannelPending { funding_txo, .. } => {
427+ println ! ( "{} got event {:?}" , std:: stringify!( node_b) , e) ;
428+ node_b. event_handled ( ) ;
429+ funding_txo
430+ }
431+ ref e => {
432+ panic ! ( "{} got unexpected event!: {:?}" , std:: stringify!( node_b) , e) ;
433+ }
434+ } ;
435+
436+ node_a. sync_wallets ( ) . unwrap ( ) ;
437+ node_b. sync_wallets ( ) . unwrap ( ) ;
438+
439+ expect_event ! ( node_a, ChannelReady ) ;
440+ let _channel_id = match node_b. next_event ( ) {
441+ ref e @ Event :: ChannelReady { ref channel_id, .. } => {
442+ println ! ( "{} got event {:?}" , std:: stringify!( node_b) , e) ;
443+ node_b. event_handled ( ) ;
444+ channel_id. clone ( )
445+ }
446+ ref e => {
447+ panic ! ( "{} got unexpected event!: {:?}" , std:: stringify!( node_b) , e) ;
448+ }
449+ } ;
450+
451+ node_a. sync_wallets ( ) . unwrap ( ) ;
452+ node_b. sync_wallets ( ) . unwrap ( ) ;
453+
454+ println ! ( "\n B receive_payment" ) ;
455+ let invoice_amount_1_msat = 1000000 ;
456+ let invoice = node_b. receive_payment ( invoice_amount_1_msat, & "asdf" , 9217 ) . unwrap ( ) ;
457+
458+ println ! ( "\n A send_payment" ) ;
459+ let payment_hash = node_a. send_payment ( & invoice) . unwrap ( ) ;
460+ expect_event ! ( node_a, PaymentSuccessful ) ;
461+ expect_event ! ( node_b, PaymentReceived ) ;
462+ assert_eq ! ( node_a. payment( & payment_hash) . unwrap( ) . status, PaymentStatus :: Succeeded ) ;
463+ assert_eq ! ( node_a. payment( & payment_hash) . unwrap( ) . direction, PaymentDirection :: Outbound ) ;
464+ }
465+
376466#[ test]
377467fn sign_verify_msg ( ) {
378468 let ( _, electrsd) = setup_bitcoind_and_electrsd ( ) ;
0 commit comments