Skip to content

Commit

Permalink
update functional test and check warn message instead of a close channel
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Apr 22, 2022
1 parent 8c7dca8 commit d04ca27
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7380,22 +7380,23 @@ fn test_data_loss_protect() {
}

// Check we close channel detecting A is fallen-behind
nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]);
check_closed_event!(nodes[1], 1, ClosureReason::ProcessingError { err: "Peer attempted to reestablish channel with a very old local commitment transaction".to_string() });
assert_eq!(check_closed_broadcast!(nodes[1], true).unwrap().data, "Peer attempted to reestablish channel with a very old local commitment transaction");
check_added_monitors!(nodes[1], 1);
// Check if we sent the warning message when we detecting that A is fallen-behind,
// and we give the possibility to A to be able to recover from error.
for msg in nodes[1].node.get_and_clear_pending_msg_events() {
if let MessageSendEvent::HandleError { ref action, .. } = msg {
match action {
&ErrorAction::SendWarningMessage { ref msg, .. } => {
assert!(msg.data.contains(&"Peer attempted to reestablish channel with a very old local commitment transaction".to_owned()));
},
_ => panic!("Unexpected event!"),
}
} else {
panic!("Unexpected event")
}
}

// Check A is able to claim to_remote output
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
assert_eq!(node_txn.len(), 1);
check_spends!(node_txn[0], chan.3);
assert_eq!(node_txn[0].output.len(), 2);
mine_transaction(&nodes[0], &node_txn[0]);
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1);
check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: "We have fallen behind - we have received proof that if we broadcast remote is going to claim our funds - we can\'t do any automated broadcasting".to_string() });
let spend_txn = check_spendable_outputs!(nodes[0], node_cfgs[0].keys_manager);
assert_eq!(spend_txn.len(), 1);
check_spends!(spend_txn[0], node_txn[0]);
// Clear the event received by the node A, the failure need to be handled by the API user.
assert!(!nodes[0].node.get_and_clear_pending_msg_events().is_empty());
}

#[test]
Expand Down

0 comments on commit d04ca27

Please sign in to comment.