X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Ftest_utils.rs;h=15cc07466d603b4f049d00fc52df7bb546765107;hb=c14fbb49ebe9a1ddc1478347c22ee778c230be7e;hp=09a8c3a26612725c07fedadc7cbb269814b54f88;hpb=73da722d18af7b510711c405154d81c1c9458942;p=rust-lightning diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 09a8c3a2..15cc0746 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -143,7 +143,9 @@ impl<'a> Router for TestRouter<'a> { &self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs ) -> Result { - 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); if let Ok(ref route) = find_route_res { 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< @@ -632,6 +642,9 @@ impl KVStore for TestStore { } } +unsafe impl Sync for TestStore {} +unsafe impl Send for TestStore {} + pub struct TestBroadcaster { pub txn_broadcasted: Mutex>, pub blocks: Arc>>,