Skip to content

Commit c8888e6

Browse files
Test router: support expecting blinded payment paths.
1 parent c239b1c commit c8888e6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lightning/src/util/test_utils.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub struct TestRouter<'a> {
118118
>,
119119
pub network_graph: Arc<NetworkGraph<&'a TestLogger>>,
120120
pub next_routes: Mutex<VecDeque<(RouteParameters, Option<Result<Route, LightningError>>)>>,
121+
pub next_blinded_payment_paths: Mutex<Vec<(BlindedPayInfo, BlindedPath)>>,
121122
pub scorer: &'a RwLock<TestScorer>,
122123
}
123124

@@ -131,6 +132,7 @@ impl<'a> TestRouter<'a> {
131132
router: DefaultRouter::new(network_graph.clone(), logger, entropy_source, scorer, ()),
132133
network_graph,
133134
next_routes: Mutex::new(VecDeque::new()),
135+
next_blinded_payment_paths: Mutex::new(Vec::new()),
134136
scorer,
135137
}
136138
}
@@ -144,6 +146,11 @@ impl<'a> TestRouter<'a> {
144146
let mut expected_routes = self.next_routes.lock().unwrap();
145147
expected_routes.push_back((query, None));
146148
}
149+
150+
pub fn expect_blinded_payment_paths(&self, mut paths: Vec<(BlindedPayInfo, BlindedPath)>) {
151+
let mut expected_paths = self.next_blinded_payment_paths.lock().unwrap();
152+
core::mem::swap(&mut *expected_paths, &mut paths);
153+
}
147154
}
148155

149156
impl<'a> Router for TestRouter<'a> {
@@ -235,9 +242,14 @@ impl<'a> Router for TestRouter<'a> {
235242
&self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
236243
amount_msats: u64, secp_ctx: &Secp256k1<T>,
237244
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
238-
self.router.create_blinded_payment_paths(
239-
recipient, first_hops, tlvs, amount_msats, secp_ctx
240-
)
245+
let mut expected_paths = self.next_blinded_payment_paths.lock().unwrap();
246+
if expected_paths.is_empty() {
247+
self.router.create_blinded_payment_paths(
248+
recipient, first_hops, tlvs, amount_msats, secp_ctx
249+
)
250+
} else {
251+
Ok(core::mem::take(&mut *expected_paths))
252+
}
241253
}
242254
}
243255

0 commit comments

Comments
 (0)