use ln::channelmonitor;
use ln::msgs;
use ln::msgs::{HandleError};
+use ln::channelmonitor::HTLCUpdate;
use util::events;
use util::logger::{Logger, Level, Record};
-use util::ser::{Readable, Writer};
+use util::ser::{ReadableArgs, Writer};
use bitcoin::blockdata::transaction::Transaction;
+use bitcoin::util::hash::Sha256dHash;
use secp256k1::PublicKey;
pub update_ret: Mutex<Result<(), channelmonitor::ChannelMonitorUpdateErr>>,
}
impl TestChannelMonitor {
- pub fn new(chain_monitor: Arc<chaininterface::ChainWatchInterface>, broadcaster: Arc<chaininterface::BroadcasterInterface>) -> Self {
+ pub fn new(chain_monitor: Arc<chaininterface::ChainWatchInterface>, broadcaster: Arc<chaininterface::BroadcasterInterface>, logger: Arc<Logger>) -> Self {
Self {
added_monitors: Mutex::new(Vec::new()),
- simple_monitor: channelmonitor::SimpleManyChannelMonitor::new(chain_monitor, broadcaster),
+ simple_monitor: channelmonitor::SimpleManyChannelMonitor::new(chain_monitor, broadcaster, logger),
update_ret: Mutex::new(Ok(())),
}
}
// to a watchtower and disk...
let mut w = VecWriter(Vec::new());
monitor.write_for_disk(&mut w).unwrap();
- assert!(channelmonitor::ChannelMonitor::read(&mut ::std::io::Cursor::new(&w.0)).unwrap() == monitor);
+ assert!(<(Sha256dHash, channelmonitor::ChannelMonitor)>::read(
+ &mut ::std::io::Cursor::new(&w.0), Arc::new(TestLogger::new())).unwrap().1 == monitor);
w.0.clear();
monitor.write_for_watchtower(&mut w).unwrap(); // This at least shouldn't crash...
self.added_monitors.lock().unwrap().push((funding_txo, monitor.clone()));
assert!(self.simple_monitor.add_update_monitor(funding_txo, monitor).is_ok());
self.update_ret.lock().unwrap().clone()
}
+
+ fn fetch_pending_htlc_updated(&self) -> Vec<HTLCUpdate> {
+ return self.simple_monitor.fetch_pending_htlc_updated();
+ }
}
pub struct TestBroadcaster {
TestRoutingMessageHandler {}
}
}
-
impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result<bool, HandleError> {
Err(HandleError { err: "", action: None })
Err(HandleError { err: "", action: None })
}
fn handle_htlc_fail_channel_update(&self, _update: &msgs::HTLCFailChannelUpdate) {}
+ fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, msgs::ChannelUpdate,msgs::ChannelUpdate)> {
+ Vec::new()
+ }
+ fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec<msgs::NodeAnnouncement> {
+ Vec::new()
+ }
}
pub struct TestLogger {
level: Level,
+ id: String,
}
impl TestLogger {
pub fn new() -> TestLogger {
+ Self::with_id("".to_owned())
+ }
+ pub fn with_id(id: String) -> TestLogger {
TestLogger {
level: Level::Trace,
+ id,
}
}
pub fn enable(&mut self, level: Level) {
impl Logger for TestLogger {
fn log(&self, record: &Record) {
if self.level >= record.level {
- println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args);
+ println!("{:<5} {} [{} : {}, {}] {}", record.level.to_string(), self.id, record.module_path, record.file, record.line, record.args);
}
}
}