@@ -493,6 +493,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
493
493
assert ! ( found_err) ;
494
494
}
495
495
496
+ #[ cfg( feature = "std" ) ]
496
497
fn do_test_data_loss_protect ( reconnect_panicing : bool ) {
497
498
// When we get a data_loss_protect proving we're behind, we immediately panic as the
498
499
// chain::Watch API requirements have been violated (e.g. the user restored from a backup). The
@@ -539,18 +540,32 @@ fn do_test_data_loss_protect(reconnect_panicing: bool) {
539
540
// Check that we sent the warning message when we detected that A has fallen behind,
540
541
// and give the possibility for A to recover from the warning.
541
542
nodes[ 1 ] . node . handle_channel_reestablish ( & nodes[ 0 ] . node . get_our_node_id ( ) , & reestablish_1[ 0 ] ) ;
542
- let warn_msg = "Peer attempted to reestablish channel with a very old local commitment transaction" . to_owned ( ) ;
543
- assert ! ( check_warn_msg!( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) , chan. 2 ) . contains( & warn_msg) ) ;
543
+ let warn_msg = "Peer attempted to reestablish channel with a very old local commitment transaction: 0 (received) vs 4 (expected)" . to_owned ( ) ;
544
+
545
+ let warn_reestablish = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
546
+ assert_eq ! ( warn_reestablish. len( ) , 2 ) ;
547
+ match warn_reestablish[ 1 ] {
548
+ MessageSendEvent :: HandleError { action : ErrorAction :: SendWarningMessage { ref msg, .. } , .. } => {
549
+ assert_eq ! ( msg. data, warn_msg) ;
550
+ } ,
551
+ _ => panic ! ( "Unexpected event" ) ,
552
+ }
553
+ let reestablish_msg = match & warn_reestablish[ 0 ] {
554
+ MessageSendEvent :: SendChannelReestablish { msg, .. } => msg. clone ( ) ,
555
+ _ => panic ! ( "Unexpected event" ) ,
556
+ } ;
544
557
545
558
{
546
559
let mut node_txn = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . clone ( ) ;
547
560
// The node B should not broadcast the transaction to force close the channel!
548
561
assert ! ( node_txn. is_empty( ) ) ;
549
562
}
550
563
551
- let reestablish_0 = get_chan_reestablish_msgs ! ( nodes[ 1 ] , nodes[ 0 ] ) ;
552
564
// Check A panics upon seeing proof it has fallen behind.
553
- nodes[ 0 ] . node . handle_channel_reestablish ( & nodes[ 1 ] . node . get_our_node_id ( ) , & reestablish_0[ 0 ] ) ;
565
+ assert ! ( std:: panic:: catch_unwind( || {
566
+ nodes[ 0 ] . node. handle_channel_reestablish( & nodes[ 1 ] . node. get_our_node_id( ) , & reestablish_msg) ;
567
+ } ) . is_err( ) ) ;
568
+ std:: mem:: forget ( nodes) ; // Skip the `Drop` handler for `Node`
554
569
return ; // By this point we should have panic'ed!
555
570
}
556
571
@@ -610,13 +625,9 @@ fn do_test_data_loss_protect(reconnect_panicing: bool) {
610
625
}
611
626
612
627
#[ test]
613
- #[ should_panic ]
614
- fn test_data_loss_protect_showing_stale_state_panics ( ) {
628
+ #[ cfg ( feature = "std" ) ]
629
+ fn test_data_loss_protect ( ) {
615
630
do_test_data_loss_protect ( true ) ;
616
- }
617
-
618
- #[ test]
619
- fn test_force_close_without_broadcast ( ) {
620
631
do_test_data_loss_protect ( false ) ;
621
632
}
622
633
0 commit comments