Merge pull request #1250 from vss96/sanity_check
[rust-lightning] / lightning / src / ln / functional_test_utils.rs
index 8ff793ed08b723280c3f089eb2ce74cb7bd2ad53..2e8994b5880284337e19f62dcdc18cd0ab03c726 100644 (file)
@@ -22,7 +22,7 @@ use ln::msgs;
 use ln::msgs::{ChannelMessageHandler,RoutingMessageHandler};
 use util::enforcing_trait_impls::EnforcingSigner;
 use util::test_utils;
-use util::test_utils::TestChainMonitor;
+use util::test_utils::{panicking, TestChainMonitor};
 use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose};
 use util::errors::APIError;
 use util::config::UserConfig;
@@ -40,7 +40,7 @@ use bitcoin::secp256k1::key::PublicKey;
 use io;
 use prelude::*;
 use core::cell::RefCell;
-use std::rc::Rc;
+use alloc::rc::Rc;
 use sync::{Arc, Mutex};
 use core::mem;
 
@@ -231,7 +231,7 @@ impl<'a, 'b, 'c> Node<'a, 'b, 'c> {
 
 impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
        fn drop(&mut self) {
-               if !::std::thread::panicking() {
+               if !panicking() {
                        // Check that we processed all pending events
                        assert!(self.node.get_and_clear_pending_msg_events().is_empty());
                        assert!(self.node.get_and_clear_pending_events().is_empty());
@@ -440,6 +440,17 @@ macro_rules! get_feerate {
        }
 }
 
+#[cfg(test)]
+macro_rules! get_opt_anchors {
+       ($node: expr, $channel_id: expr) => {
+               {
+                       let mut lock;
+                       let chan = get_channel_ref!($node, lock, $channel_id);
+                       chan.opt_anchors()
+               }
+       }
+}
+
 /// Returns a channel monitor given a channel id, making some naive assumptions
 #[macro_export]
 macro_rules! get_monitor {
@@ -780,6 +791,22 @@ macro_rules! get_closing_signed_broadcast {
        }
 }
 
+#[cfg(test)]
+macro_rules! check_warn_msg {
+       ($node: expr, $recipient_node_id: expr, $chan_id: expr) => {{
+               let msg_events = $node.node.get_and_clear_pending_msg_events();
+               assert_eq!(msg_events.len(), 1);
+               match msg_events[0] {
+                       MessageSendEvent::HandleError { action: ErrorAction::SendWarningMessage { ref msg, log_level: _ }, node_id } => {
+                               assert_eq!(node_id, $recipient_node_id);
+                               assert_eq!(msg.channel_id, $chan_id);
+                               msg.data.clone()
+                       },
+                       _ => panic!("Unexpected event"),
+               }
+       }}
+}
+
 /// Check that a channel's closing channel update has been broadcasted, and optionally
 /// check whether an error message event has occurred.
 #[macro_export]