Skip to content

Commit 8bb1332

Browse files
committed
Move all-events check into framework instead of per-test
1 parent 46e8647 commit 8bb1332

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/ln/channelmanager.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,13 @@ mod tests {
23912391
network_payment_count: Rc<RefCell<u8>>,
23922392
network_chan_count: Rc<RefCell<u32>>,
23932393
}
2394+
impl Drop for Node {
2395+
fn drop(&mut self) {
2396+
// Check that we processed all pending events
2397+
assert_eq!(self.node.get_and_clear_pending_events().len(), 0);
2398+
assert_eq!(self.chan_monitor.added_monitors.lock().unwrap().len(), 0);
2399+
}
2400+
}
23942401

23952402
fn create_chan_between_nodes(node_a: &Node, node_b: &Node) -> (msgs::ChannelAnnouncement, msgs::ChannelUpdate, msgs::ChannelUpdate, [u8; 32], Transaction) {
23962403
node_a.node.create_channel(node_b.node.get_our_node_id(), 100000, 10001, 42).unwrap();
@@ -3037,12 +3044,6 @@ mod tests {
30373044
close_channel(&nodes[2], &nodes[3], &chan_3.2, chan_3.3, true);
30383045
close_channel(&nodes[1], &nodes[3], &chan_4.2, chan_4.3, false);
30393046
close_channel(&nodes[1], &nodes[3], &chan_5.2, chan_5.3, false);
3040-
3041-
// Check that we processed all pending events
3042-
for node in nodes {
3043-
assert_eq!(node.node.get_and_clear_pending_events().len(), 0);
3044-
assert_eq!(node.chan_monitor.added_monitors.lock().unwrap().len(), 0);
3045-
}
30463047
}
30473048

30483049
#[test]
@@ -3352,12 +3353,6 @@ mod tests {
33523353
get_announce_close_broadcast_events(&nodes, 0, 1);
33533354
assert_eq!(nodes[0].node.list_channels().len(), 0);
33543355
assert_eq!(nodes[1].node.list_channels().len(), 0);
3355-
3356-
// Check that we processed all pending events
3357-
for node in nodes {
3358-
assert_eq!(node.node.get_and_clear_pending_events().len(), 0);
3359-
assert_eq!(node.chan_monitor.added_monitors.lock().unwrap().len(), 0);
3360-
}
33613356
}
33623357

33633358
#[test]
@@ -3542,6 +3537,16 @@ mod tests {
35423537
while !headers.is_empty() {
35433538
nodes[0].node.block_disconnected(&headers.pop().unwrap());
35443539
}
3540+
{
3541+
let events = nodes[0].node.get_and_clear_pending_events();
3542+
assert_eq!(events.len(), 1);
3543+
match events[0] {
3544+
Event::BroadcastChannelUpdate { msg: msgs::ChannelUpdate { contents: msgs::UnsignedChannelUpdate { flags, .. }, .. } } => {
3545+
assert_eq!(flags & 0b10, 0b10);
3546+
},
3547+
_ => panic!("Unexpected event"),
3548+
}
3549+
}
35453550
let channel_state = nodes[0].node.channel_state.lock().unwrap();
35463551
assert_eq!(channel_state.by_id.len(), 0);
35473552
assert_eq!(channel_state.short_to_id.len(), 0);

0 commit comments

Comments
 (0)