From: Valentine Wallace Date: Wed, 3 Jul 2024 18:31:13 +0000 (-0400) Subject: Test router: support expecting blinded payment paths. X-Git-Tag: v0.0.124-beta~61^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c8888e6d6608081bdbe0c1883c3484a8e525acca;p=rust-lightning Test router: support expecting blinded payment paths. --- diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index f3090ffba..00b0febdb 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -118,6 +118,7 @@ pub struct TestRouter<'a> { >, pub network_graph: Arc>, pub next_routes: Mutex>)>>, + pub next_blinded_payment_paths: Mutex>, pub scorer: &'a RwLock, } @@ -131,6 +132,7 @@ impl<'a> TestRouter<'a> { router: DefaultRouter::new(network_graph.clone(), logger, entropy_source, scorer, ()), network_graph, next_routes: Mutex::new(VecDeque::new()), + next_blinded_payment_paths: Mutex::new(Vec::new()), scorer, } } @@ -144,6 +146,11 @@ impl<'a> TestRouter<'a> { let mut expected_routes = self.next_routes.lock().unwrap(); expected_routes.push_back((query, None)); } + + pub fn expect_blinded_payment_paths(&self, mut paths: Vec<(BlindedPayInfo, BlindedPath)>) { + let mut expected_paths = self.next_blinded_payment_paths.lock().unwrap(); + core::mem::swap(&mut *expected_paths, &mut paths); + } } impl<'a> Router for TestRouter<'a> { @@ -235,9 +242,14 @@ impl<'a> Router for TestRouter<'a> { &self, recipient: PublicKey, first_hops: Vec, tlvs: ReceiveTlvs, amount_msats: u64, secp_ctx: &Secp256k1, ) -> Result, ()> { - self.router.create_blinded_payment_paths( - recipient, first_hops, tlvs, amount_msats, secp_ctx - ) + let mut expected_paths = self.next_blinded_payment_paths.lock().unwrap(); + if expected_paths.is_empty() { + self.router.create_blinded_payment_paths( + recipient, first_hops, tlvs, amount_msats, secp_ctx + ) + } else { + Ok(core::mem::take(&mut *expected_paths)) + } } }