]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Test router: support expecting blinded payment paths.
authorValentine Wallace <vwallace@protonmail.com>
Wed, 3 Jul 2024 18:31:13 +0000 (14:31 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 3 Jul 2024 18:31:13 +0000 (14:31 -0400)
lightning/src/util/test_utils.rs

index f3090ffbae14e1fb53c883ecaad92c8f25c4e720..00b0febdbfe4927b49b61dd1239b7f55b7709736 100644 (file)
@@ -118,6 +118,7 @@ pub struct TestRouter<'a> {
        >,
        pub network_graph: Arc<NetworkGraph<&'a TestLogger>>,
        pub next_routes: Mutex<VecDeque<(RouteParameters, Option<Result<Route, LightningError>>)>>,
+       pub next_blinded_payment_paths: Mutex<Vec<(BlindedPayInfo, BlindedPath)>>,
        pub scorer: &'a RwLock<TestScorer>,
 }
 
@@ -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<ChannelDetails>, tlvs: ReceiveTlvs,
                amount_msats: u64, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
-               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))
+               }
        }
 }