Skip to content

Commit 4f36f37

Browse files
committed
Move all-events check into framework instead of per-test
1 parent adee671 commit 4f36f37

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
@@ -2390,6 +2390,13 @@ mod tests {
23902390
network_payment_count: Rc<RefCell<u8>>,
23912391
network_chan_count: Rc<RefCell<u32>>,
23922392
}
2393+
impl Drop for Node {
2394+
fn drop(&mut self) {
2395+
// Check that we processed all pending events
2396+
assert_eq!(self.node.get_and_clear_pending_events().len(), 0);
2397+
assert_eq!(self.chan_monitor.added_monitors.lock().unwrap().len(), 0);
2398+
}
2399+
}
23932400

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

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

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

0 commit comments

Comments
 (0)