Skip to content

Commit

Permalink
Test router: support expecting blinded payment paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed Jul 3, 2024
1 parent c239b1c commit c8888e6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lightning/src/util/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}

Expand All @@ -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,
}
}
Expand All @@ -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> {
Expand Down Expand Up @@ -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))
}
}
}

Expand Down

0 comments on commit c8888e6

Please sign in to comment.