Skip to content

Commit

Permalink
Add test to check the introduced behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
shaavan committed Dec 3, 2023
1 parent dd0b927 commit 10fabf4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11293,6 +11293,36 @@ mod tests {
}
}

#[test]
fn test_channel_close_when_not_timely_accepted() {
// Create network of two nodes
let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);

// Try to create a channel from node 0, to 1.
// The channel is initiated from the node 0 side,
// But the accept channel message was never back sent by node 1
// And hence never handled.
let create_chan_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap();
let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
assert_eq!(open_channel_msg.temporary_channel_id, create_chan_id);

// In the meantime, two timer tick passed
nodes[0].node.timer_tick_occurred();
nodes[0].node.timer_tick_occurred();

// Since accept channel message was never received
// The channel should be forced close by now from node 0 side
let events = nodes[0].node.get_and_clear_pending_msg_events();
assert_eq!(events.len(), 1);

let node_0_per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
let per_peer_state = node_0_per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
assert_eq!(per_peer_state.channel_by_id.len(), 0);
}

#[test]
fn test_drop_disconnected_peers_when_removing_channels() {
let chanmon_cfgs = create_chanmon_cfgs(2);
Expand Down

0 comments on commit 10fabf4

Please sign in to comment.