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.
This commit is contained in:
Matt Corallo 2024-02-16 19:26:32 +00:00
parent 4026d4efd1
commit 24d02ff287

View file

@ -143,7 +143,9 @@ impl<'a> Router for TestRouter<'a> {
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>, &self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>,
inflight_htlcs: InFlightHtlcs inflight_htlcs: InFlightHtlcs
) -> Result<Route, msgs::LightningError> { ) -> Result<Route, msgs::LightningError> {
if let Some((find_route_query, find_route_res)) = self.next_routes.lock().unwrap().pop_front() { let route_res;
let next_route_opt = self.next_routes.lock().unwrap().pop_front();
if let Some((find_route_query, find_route_res)) = next_route_opt {
assert_eq!(find_route_query, *params); assert_eq!(find_route_query, *params);
if let Ok(ref route) = find_route_res { if let Ok(ref route) = find_route_res {
assert_eq!(route.route_params, Some(find_route_query)); assert_eq!(route.route_params, Some(find_route_query));
@ -201,10 +203,18 @@ impl<'a> Router for TestRouter<'a> {
} }
} }
} }
return find_route_res; route_res = find_route_res;
} } else {
route_res = self.router.find_route(payer, params, first_hops, inflight_htlcs);
};
self.router.find_route(payer, params, first_hops, inflight_htlcs) if let Ok(route) = &route_res {
// Previously, `Route`s failed to round-trip through serialization due to a write/read
// mismatch. Thus, here we test all test-generated routes round-trip:
let ser = route.encode();
assert_eq!(Route::read(&mut &ser[..]).unwrap(), *route);
}
route_res
} }
fn create_blinded_payment_paths< fn create_blinded_payment_paths<