Skip to content

Commit d71ea73

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 9df9156 commit d71ea73

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lightning/src/ln/blinded_payment_tests.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,28 @@ 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_id_pairs, .. } => {
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+
let actual_chan_ids: HashSet<_> = via_channel_id_pairs.iter().map(|(chan_id, _)| *chan_id).collect();
255+
let actual_user_chan_ids: HashSet<_> = via_channel_id_pairs.iter()
256+
.filter_map(|(_, user_id_opt)| *user_id_opt)
257+
.collect();
258+
259+
assert_eq!(actual_chan_ids, expected_chan_ids);
260+
assert_eq!(actual_user_chan_ids, expected_user_chan_ids);
261+
}
262+
_ => panic!("Unexpected event"),
263+
}
264+
245265
claim_payment_along_route(
246266
ClaimAlongRouteArgs::new(&nodes[0], expected_route, payment_preimage)
247267
);

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)