X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fchaininterface.rs;h=b30ebc1ee1629441ca7ed95e4e27a2518279ad35;hb=79c8491120ecc2bc305766a8249d9b004e642135;hp=ad08c817dcea362187fb223629b989810b5309fd;hpb=7d6234662cb49d38dcd792ef8034e5111401e75e;p=rust-lightning diff --git a/lightning/src/chain/chaininterface.rs b/lightning/src/chain/chaininterface.rs index ad08c817..b30ebc1e 100644 --- a/lightning/src/chain/chaininterface.rs +++ b/lightning/src/chain/chaininterface.rs @@ -22,6 +22,7 @@ use std::marker::PhantomData; use std::ptr; /// Used to give chain error details upstream +#[derive(Clone)] pub enum ChainError { /// Client doesn't support UTXO lookup (but the chain hash matches our genesis block hash) NotSupported, @@ -127,6 +128,7 @@ pub trait FeeEstimator: Sync + Send { pub const MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = 4000; /// Utility for tracking registered txn/outpoints and checking for matches +#[cfg_attr(test, derive(PartialEq))] pub struct ChainWatchedUtil { watch_all: bool, @@ -317,6 +319,17 @@ pub struct ChainWatchInterfaceUtil { logger: Arc, } +// We only expose PartialEq in test since its somewhat unclear exactly what it should do and we're +// only comparing a subset of fields (essentially just checking that the set of things we're +// watching is the same). +#[cfg(test)] +impl PartialEq for ChainWatchInterfaceUtil { + fn eq(&self, o: &Self) -> bool { + self.network == o.network && + *self.watched.lock().unwrap() == *o.watched.lock().unwrap() + } +} + /// Register listener impl ChainWatchInterface for ChainWatchInterfaceUtil { fn install_watch_tx(&self, txid: &Sha256dHash, script_pub_key: &Script) { @@ -391,13 +404,14 @@ impl ChainWatchInterfaceUtil { #[cfg(test)] mod tests { - use ln::functional_test_utils::{create_node_cfgs}; + use ln::functional_test_utils::{create_chanmon_cfgs, create_node_cfgs}; use super::{BlockNotifier, ChainListener}; use std::ptr; #[test] fn register_listener_test() { - let node_cfgs = create_node_cfgs(1); + let chanmon_cfgs = create_chanmon_cfgs(1); + let node_cfgs = create_node_cfgs(1, &chanmon_cfgs); let block_notifier = BlockNotifier::new(node_cfgs[0].chain_monitor.clone()); assert_eq!(block_notifier.listeners.lock().unwrap().len(), 0); let listener = &node_cfgs[0].chan_monitor.simple_monitor as &ChainListener; @@ -410,7 +424,8 @@ mod tests { #[test] fn unregister_single_listener_test() { - let node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let block_notifier = BlockNotifier::new(node_cfgs[0].chain_monitor.clone()); let listener1 = &node_cfgs[0].chan_monitor.simple_monitor as &ChainListener; let listener2 = &node_cfgs[1].chan_monitor.simple_monitor as &ChainListener; @@ -428,7 +443,8 @@ mod tests { #[test] fn unregister_single_listener_ref_test() { - let node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let block_notifier = BlockNotifier::new(node_cfgs[0].chain_monitor.clone()); block_notifier.register_listener(&node_cfgs[0].chan_monitor.simple_monitor as &ChainListener); block_notifier.register_listener(&node_cfgs[1].chan_monitor.simple_monitor as &ChainListener); @@ -444,7 +460,8 @@ mod tests { #[test] fn unregister_multiple_of_the_same_listeners_test() { - let node_cfgs = create_node_cfgs(2); + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let block_notifier = BlockNotifier::new(node_cfgs[0].chain_monitor.clone()); let listener1 = &node_cfgs[0].chan_monitor.simple_monitor as &ChainListener; let listener2 = &node_cfgs[1].chan_monitor.simple_monitor as &ChainListener;