projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1976 from tnull/2023-01-expose-impl-writeable-msg
[rust-lightning]
/
lightning
/
src
/
util
/
test_utils.rs
diff --git
a/lightning/src/util/test_utils.rs
b/lightning/src/util/test_utils.rs
index 7b4037bec10969e572311b1438252b6402cfc5d4..1dae61ab3ef5b1841241b069612f71c7e5cc8f38 100644
(file)
--- a/
lightning/src/util/test_utils.rs
+++ b/
lightning/src/util/test_utils.rs
@@
-20,6
+20,7
@@
use crate::chain::keysinterface;
use crate::ln::channelmanager;
use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
use crate::ln::{msgs, wire};
use crate::ln::channelmanager;
use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
use crate::ln::{msgs, wire};
+use crate::ln::msgs::LightningError;
use crate::ln::script::ShutdownScript;
use crate::routing::gossip::NetworkGraph;
use crate::routing::router::{find_route, InFlightHtlcs, Route, RouteHop, RouteParameters, Router, ScorerAccountingForInFlightHtlcs};
use crate::ln::script::ShutdownScript;
use crate::routing::gossip::NetworkGraph;
use crate::routing::router::{find_route, InFlightHtlcs, Route, RouteHop, RouteParameters, Router, ScorerAccountingForInFlightHtlcs};
@@
-76,11
+77,17
@@
impl chaininterface::FeeEstimator for TestFeeEstimator {
pub struct TestRouter<'a> {
pub network_graph: Arc<NetworkGraph<&'a TestLogger>>,
pub struct TestRouter<'a> {
pub network_graph: Arc<NetworkGraph<&'a TestLogger>>,
+ pub next_routes: Mutex<VecDeque<Result<Route, LightningError>>>,
}
impl<'a> TestRouter<'a> {
pub fn new(network_graph: Arc<NetworkGraph<&'a TestLogger>>) -> Self {
}
impl<'a> TestRouter<'a> {
pub fn new(network_graph: Arc<NetworkGraph<&'a TestLogger>>) -> Self {
- Self { network_graph }
+ Self { network_graph, next_routes: Mutex::new(VecDeque::new()), }
+ }
+
+ pub fn expect_find_route(&self, result: Result<Route, LightningError>) {
+ let mut expected_routes = self.next_routes.lock().unwrap();
+ expected_routes.push_back(result);
}
}
}
}
@@
-89,6
+96,9
@@
impl<'a> Router for TestRouter<'a> {
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&channelmanager::ChannelDetails]>,
inflight_htlcs: &InFlightHtlcs
) -> Result<Route, msgs::LightningError> {
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&channelmanager::ChannelDetails]>,
inflight_htlcs: &InFlightHtlcs
) -> Result<Route, msgs::LightningError> {
+ if let Some(find_route_res) = self.next_routes.lock().unwrap().pop_front() {
+ return find_route_res
+ }
let logger = TestLogger::new();
find_route(
payer, params, &self.network_graph, first_hops, &logger,
let logger = TestLogger::new();
find_route(
payer, params, &self.network_graph, first_hops, &logger,
@@
-102,6
+112,16
@@
impl<'a> Router for TestRouter<'a> {
fn notify_payment_probe_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
}
fn notify_payment_probe_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
}
+#[cfg(feature = "std")] // If we put this on the `if`, we get "attributes are not yet allowed on `if` expressions" on 1.41.1
+impl<'a> Drop for TestRouter<'a> {
+ fn drop(&mut self) {
+ if std::thread::panicking() {
+ return;
+ }
+ assert!(self.next_routes.lock().unwrap().is_empty());
+ }
+}
+
pub struct OnlyReadsKeysInterface {}
impl EntropySource for OnlyReadsKeysInterface {
pub struct OnlyReadsKeysInterface {}
impl EntropySource for OnlyReadsKeysInterface {