@@ -7282,8 +7282,20 @@ fn test_user_configurable_csv_delay() {
7282
7282
} else { assert ! ( false ) ; }
7283
7283
}
7284
7284
7285
- #[ test]
7286
- fn test_data_loss_protect ( ) {
7285
+ /// describe the test case as a enum, istead as boolean in this case!
7286
+ /// with the enum there is the possibility to pass more data and
7287
+ /// check more corner case.
7288
+ #[ derive( Debug ) ]
7289
+ enum DataLossProtectTestCase {
7290
+ /// The node that send the warning message, will try to
7291
+ /// use the channel, but it can't, because after the
7292
+ /// warning message we don't change the channel state.
7293
+ UseChannel ,
7294
+ /// Try to reconnect to the node that have send the warning message
7295
+ TryToReconnect ,
7296
+ }
7297
+
7298
+ fn do_test_data_loss_protect ( case : DataLossProtectTestCase ) {
7287
7299
// We want to be sure that :
7288
7300
// * we don't broadcast our Local Commitment Tx in case of fallen behind
7289
7301
// (but this is not quite true - we broadcast during Drop because chanmon is out of sync with chanmgr)
@@ -7382,17 +7394,27 @@ fn test_data_loss_protect() {
7382
7394
// Check we close channel detecting A is fallen-behind
7383
7395
// Check if we sent the warning message when we detecting that A is fallen-behind,
7384
7396
// and we give the possibility to A to be able to recover from error.
7385
- for msg in nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) {
7386
- if let MessageSendEvent :: HandleError { ref action, .. } = msg {
7387
- match action {
7388
- & ErrorAction :: SendWarningMessage { ref msg, .. } => {
7389
- assert ! ( msg. data. contains( & "Peer attempted to reestablish channel with a very old local commitment transaction" . to_owned( ) ) ) ;
7390
- } ,
7391
- _ => panic ! ( "Unexpected event!" ) ,
7392
- }
7393
- } else {
7394
- panic ! ( "Unexpected event" )
7395
- }
7397
+ expect_warning_due_wrong_channel_reestablish ! ( nodes[ 1 ] ) ;
7398
+
7399
+ // after the waring message sent by B, we should not able to
7400
+ // use the channel, or reconnect with success to the channel.
7401
+ match case {
7402
+ DataLossProtectTestCase :: UseChannel => {
7403
+ // try to make a payment, but this should not be allowed
7404
+ // from A -> B
7405
+ let result = fail_to_get_route ! ( nodes[ 0 ] , nodes[ 1 ] , 1000000 ) ;
7406
+ match result {
7407
+ Ok ( _) => panic ! ( "Unexpected event" ) ,
7408
+ Err ( msgs:: LightningError { ref err, ..} ) =>
7409
+ assert_eq ! ( err, "Cannot route when there are no outbound routes away from us" ) ,
7410
+ } ;
7411
+ } ,
7412
+ DataLossProtectTestCase :: TryToReconnect => {
7413
+ // FIXME: We sent the warning message to give the possibility to restore
7414
+ // from the error, so we should be able to allow the reconnection here!
7415
+ nodes[ 0 ] . node . peer_connected ( & nodes[ 1 ] . node . get_our_node_id ( ) , & msgs:: Init { features : InitFeatures :: empty ( ) , remote_network_address : None } ) ;
7416
+ expect_warning_due_wrong_channel_reestablish ! ( nodes[ 1 ] ) ;
7417
+ } ,
7396
7418
}
7397
7419
7398
7420
// Check A is able to claim to_remote output
@@ -7406,6 +7428,12 @@ fn test_data_loss_protect() {
7406
7428
check_closed_event ! ( nodes[ 0 ] , 1 , ClosureReason :: ProcessingError { err: exp_err. to_string( ) } ) ;
7407
7429
}
7408
7430
7431
+ #[ test]
7432
+ fn test_data_loss_protect ( ) {
7433
+ do_test_data_loss_protect ( DataLossProtectTestCase :: UseChannel ) ;
7434
+ do_test_data_loss_protect ( DataLossProtectTestCase :: TryToReconnect ) ;
7435
+ }
7436
+
7409
7437
#[ test]
7410
7438
fn test_check_htlc_underpaying ( ) {
7411
7439
// Send payment through A -> B but A is maliciously
0 commit comments