Skip to content

Commit b9e52f5

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 4bfd89e commit b9e52f5

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

lightning/src/ln/blinded_payment_tests.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,23 @@ 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 via_channel_ids, mut via_user_channel_ids, .. } => {
248+
let channels = nodes[3].node.list_channels();
249+
250+
// Convert to HashSets for order-agnostic comparison
251+
let expected_chan_ids: HashSet<_> = channels.iter().map(|d| d.channel_id).collect();
252+
let expected_user_chan_ids: HashSet<_> = channels.iter().map(|d| d.user_channel_id).collect();
253+
254+
assert_eq!(via_channel_ids.into_iter().collect::<HashSet<_>>(), expected_chan_ids);
255+
assert_eq!(via_user_channel_ids.into_iter().collect::<HashSet<_>>(), expected_user_chan_ids);
256+
}
257+
_ => panic!("Unexpected event"),
258+
}
259+
245260
claim_payment_along_route(
246261
ClaimAlongRouteArgs::new(&nodes[0], expected_route, payment_preimage)
247262
);

lightning/src/ln/channelmanager.rs

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

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

0 commit comments

Comments
 (0)