X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Ftest_utils.rs;h=a34cb0cf323a337edc757579c761d1363948212b;hb=a5ecb851716bc0819586894232653ec4b5e2c67f;hp=e50576e1a83960d41d4ab973d8bf943e777465f7;hpb=73e2fdf332ed095e641625311d2851f6ecbc0691;p=rust-lightning diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index e50576e1..a34cb0cf 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -17,6 +17,7 @@ use crate::chain::channelmonitor; use crate::chain::channelmonitor::MonitorEvent; use crate::chain::transaction::OutPoint; use crate::chain::keysinterface; +use crate::events; use crate::ln::channelmanager; use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures}; use crate::ln::{msgs, wire}; @@ -28,7 +29,6 @@ use crate::routing::router::{find_route, InFlightHtlcs, Route, RouteHop, RoutePa use crate::routing::scoring::{ChannelUsage, Score}; use crate::util::config::UserConfig; use crate::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState}; -use crate::util::events; use crate::util::logger::{Logger, Level, Record}; use crate::util::ser::{Readable, ReadableArgs, Writer, Writeable}; @@ -137,11 +137,12 @@ impl<'a> Router for TestRouter<'a> { } } -#[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; + #[cfg(feature = "std")] { + if std::thread::panicking() { + return; + } } assert!(self.next_routes.lock().unwrap().is_empty()); } @@ -423,10 +424,10 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler { fn handle_channel_reestablish(&self, _their_node_id: &PublicKey, msg: &msgs::ChannelReestablish) { self.received_msg(wire::Message::ChannelReestablish(msg.clone())); } - fn peer_disconnected(&self, their_node_id: &PublicKey, _no_connection_possible: bool) { + fn peer_disconnected(&self, their_node_id: &PublicKey) { assert!(self.connected_peers.lock().unwrap().remove(their_node_id)); } - fn peer_connected(&self, their_node_id: &PublicKey, _msg: &msgs::Init) -> Result<(), ()> { + fn peer_connected(&self, their_node_id: &PublicKey, _msg: &msgs::Init, _inbound: bool) -> Result<(), ()> { assert!(self.connected_peers.lock().unwrap().insert(their_node_id.clone())); // Don't bother with `received_msg` for Init as its auto-generated and we don't want to // bother re-generating the expected Init message in all tests. @@ -543,7 +544,7 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { None } - fn peer_connected(&self, their_node_id: &PublicKey, init_msg: &msgs::Init) -> Result<(), ()> { + fn peer_connected(&self, their_node_id: &PublicKey, init_msg: &msgs::Init, _inbound: bool) -> Result<(), ()> { if !init_msg.features.supports_gossip_queries() { return Ok(()); } @@ -641,10 +642,10 @@ impl TestLogger { /// 1. belongs to the specified module and /// 2. contains `line` in it. /// And asserts if the number of occurrences is the same with the given `count` - pub fn assert_log_contains(&self, module: String, line: String, count: usize) { + pub fn assert_log_contains(&self, module: &str, line: &str, count: usize) { let log_entries = self.lines.lock().unwrap(); let l: usize = log_entries.iter().filter(|&(&(ref m, ref l), _c)| { - m == &module && l.contains(line.as_str()) + m == module && l.contains(line) }).map(|(_, c) | { c }).sum(); assert_eq!(l, count) } @@ -653,10 +654,10 @@ impl TestLogger { /// 1. belong to the specified module and /// 2. match the given regex pattern. /// Assert that the number of occurrences equals the given `count` - pub fn assert_log_regex(&self, module: String, pattern: regex::Regex, count: usize) { + pub fn assert_log_regex(&self, module: &str, pattern: regex::Regex, count: usize) { let log_entries = self.lines.lock().unwrap(); let l: usize = log_entries.iter().filter(|&(&(ref m, ref l), _c)| { - m == &module && pattern.is_match(&l) + m == module && pattern.is_match(&l) }).map(|(_, c) | { c }).sum(); assert_eq!(l, count) }