Skip to content

Commit 477393c

Browse files
committed
Expand Test suite
- Expand testing to ensure proper serialise-deserialise round-trip for all events. - Expand a multi-Part payment test to ensure that all the channel ids & user channel ids are present in the PaymentClaimable event
1 parent d85a29d commit 477393c

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lightning/src/ln/blinded_payment_tests.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,26 @@ fn mpp_to_one_hop_blinded_path() {
240240
Some(payment_secret), ev.clone(), false, None);
241241

242242
let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events);
243-
pass_along_path(&nodes[0], expected_route[1], amt_msat, payment_hash.clone(),
243+
let event = pass_along_path(&nodes[0], expected_route[1], amt_msat, payment_hash.clone(),
244244
Some(payment_secret), ev.clone(), true, None);
245+
246+
match event.unwrap() {
247+
Event::PaymentClaimable { mut inbound_channel_ids, .. } => {
248+
let mut expected_inbound_channel_ids = nodes[3].node.list_channels()
249+
.iter()
250+
.map(|d| (d.channel_id, Some(d.user_channel_id)))
251+
.collect::<Vec<(_, _)>>();
252+
253+
// `list_channels` returns channels in arbitrary order, so we sort both vectors
254+
// to ensure the comparison is order-agnostic.
255+
inbound_channel_ids.sort();
256+
expected_inbound_channel_ids.sort();
257+
258+
assert_eq!(inbound_channel_ids, expected_inbound_channel_ids);
259+
}
260+
_ => panic!("Unexpected event"),
261+
}
262+
245263
claim_payment_along_route(
246264
ClaimAlongRouteArgs::new(&nodes[0], expected_route, payment_preimage)
247265
);

lightning/src/ln/channelmanager.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -10925,7 +10925,18 @@ where
1092510925
let events = core::cell::RefCell::new(Vec::new());
1092610926
let event_handler = |event: events::Event| Ok(events.borrow_mut().push(event));
1092710927
self.process_pending_events(&event_handler);
10928-
events.into_inner()
10928+
let collected_events = events.into_inner();
10929+
10930+
// To expand the coverage and make sure all events are properly serialised and deserialised,
10931+
// we test all generated events round-trip:
10932+
for event in &collected_events {
10933+
let ser = event.encode();
10934+
if let Some(deser) = events::Event::read(&mut &ser[..]).expect("event should deserialize") {
10935+
assert_eq!(&deser, event, "event should roundtrip correctly");
10936+
}
10937+
}
10938+
10939+
collected_events
1092910940
}
1093010941

1093110942
#[cfg(feature = "_test_utils")]

0 commit comments

Comments
 (0)