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,
logger: Arc<Logger>,
}
+// 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) {
#[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;
#[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;
#[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);
#[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;