use lightning::ln::msgs::DecodeError;
use lightning::routing::gossip::{NetworkGraph, NodeId};
- use lightning::util::logger::Level;
use lightning::util::test_utils::TestLogger;
use crate::processing::STALE_RGS_UPDATE_AGE_LIMIT_SECS;
#[test]
fn node_data_update_succeeds_with_v2() {
- let mut logger = TestLogger::new();
- logger.enable(Level::Gossip);
+ let logger = TestLogger::new();
let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
let example_input = vec![
#[test]
fn node_date_update_succeeds_without_channels() {
- let mut logger = TestLogger::new();
- logger.enable(Level::Gossip);
+ let logger = TestLogger::new();
let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
#[test]
fn update_ignores_v2_additional_data() {
- let mut logger = TestLogger::new();
- logger.enable(Level::Gossip);
+ let logger = TestLogger::new();
let network_graph = NetworkGraph::new(Network::Bitcoin, &logger);
let rapid_sync = RapidGossipSync::new(&network_graph, &logger);
use crate::sync::RwLock;
use crate::util::config::UserConfig;
use crate::util::test_channel_signer::{TestChannelSigner, EnforcementState};
-use crate::util::logger::{Logger, Level, Record};
+use crate::util::logger::{Logger, Record};
use crate::util::ser::{Readable, ReadableArgs, Writer, Writeable};
use crate::util::persist::KVStore;
}
pub struct TestLogger {
- level: Level,
pub(crate) id: String,
pub lines: Mutex<HashMap<(&'static str, String), usize>>,
pub context: Mutex<HashMap<(&'static str, Option<PublicKey>, Option<ChannelId>), usize>>,
}
pub fn with_id(id: String) -> TestLogger {
TestLogger {
- level: Level::Trace,
id,
lines: Mutex::new(new_hash_map()),
context: Mutex::new(new_hash_map()),
}
}
- pub fn enable(&mut self, level: Level) {
- self.level = level;
- }
pub fn assert_log(&self, module: &str, line: String, count: usize) {
let log_entries = self.lines.lock().unwrap();
assert_eq!(log_entries.get(&(module, line)), Some(&count));
fn log(&self, record: Record) {
*self.lines.lock().unwrap().entry((record.module_path, format!("{}", record.args))).or_insert(0) += 1;
*self.context.lock().unwrap().entry((record.module_path, record.peer_id, record.channel_id)).or_insert(0) += 1;
- if record.level >= self.level {
- let pfx = format!("{} {} [{}:{}]", self.id, record.level.to_string(), record.module_path, record.line);
- println!("{:<55}{}", pfx, record.args);
- }
+ let pfx = format!("{} {} [{}:{}]", self.id, record.level.to_string(), record.module_path, record.line);
+ println!("{:<55}{}", pfx, record.args);
}
}