Skip to content

Commit 24d02ff

Browse files
committed
Test Route serialization round-trip
This adds testing for the previous two commits by testing that all routes generated in testing are able to survive a serialization round-trip.
1 parent 4026d4e commit 24d02ff

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

lightning/src/util/test_utils.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ impl<'a> Router for TestRouter<'a> {
143143
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>,
144144
inflight_htlcs: InFlightHtlcs
145145
) -> Result<Route, msgs::LightningError> {
146-
if let Some((find_route_query, find_route_res)) = self.next_routes.lock().unwrap().pop_front() {
146+
let route_res;
147+
let next_route_opt = self.next_routes.lock().unwrap().pop_front();
148+
if let Some((find_route_query, find_route_res)) = next_route_opt {
147149
assert_eq!(find_route_query, *params);
148150
if let Ok(ref route) = find_route_res {
149151
assert_eq!(route.route_params, Some(find_route_query));
@@ -201,10 +203,18 @@ impl<'a> Router for TestRouter<'a> {
201203
}
202204
}
203205
}
204-
return find_route_res;
205-
}
206+
route_res = find_route_res;
207+
} else {
208+
route_res = self.router.find_route(payer, params, first_hops, inflight_htlcs);
209+
};
206210

207-
self.router.find_route(payer, params, first_hops, inflight_htlcs)
211+
if let Ok(route) = &route_res {
212+
// Previously, `Route`s failed to round-trip through serialization due to a write/read
213+
// mismatch. Thus, here we test all test-generated routes round-trip:
214+
let ser = route.encode();
215+
assert_eq!(Route::read(&mut &ser[..]).unwrap(), *route);
216+
}
217+
route_res
208218
}
209219

210220
fn create_blinded_payment_paths<

0 commit comments

Comments
 (0)