use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
use lightning::routing::router::{Route, RouteHop};
-
-use utils::test_logger;
+use utils::test_logger::{self, Output};
use utils::test_persister::TestPersister;
use bitcoin::secp256k1::key::{PublicKey,SecretKey};
}
#[inline]
-pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
+pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
+ let out = SearchingOutput::new(underlying_out);
let broadcast = Arc::new(TestBroadcaster{});
macro_rules! make_node {
// force-close which we should detect as an error).
assert_eq!(msg.contents.flags & 2, 0);
},
- _ => if out.locked_contains(&"Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") {
+ _ => if out.may_fail.load(atomic::Ordering::Acquire) {
+ return;
} else {
panic!("Unhandled message event {:?}", event)
},
events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.flags & 2, 0); // The disable bit must never be set!
},
- _ => if out.locked_contains(&"Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") {
+ _ => if out.may_fail.load(atomic::Ordering::Acquire) {
+ return;
} else {
panic!("Unhandled message event")
},
events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
assert_eq!(msg.contents.flags & 2, 0); // The disable bit must never be set!
},
- _ => if out.locked_contains(&"Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") {
+ _ => if out.may_fail.load(atomic::Ordering::Acquire) {
+ return;
} else {
panic!("Unhandled message event")
},
events::Event::PendingHTLCsForwardable { .. } => {
nodes[$node].process_pending_htlc_forwards();
},
- _ => if out.locked_contains(&"Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") {
+ _ => if out.may_fail.load(atomic::Ordering::Acquire) {
+ return;
} else {
panic!("Unhandled event")
},
// Finally, make sure that at least one end of each channel can make a substantial payment.
// Unless we expected to hit a limitation of LN state machine (see comment in `send_update_fee_and_commit`)
- if out.locked_contains(&"Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") {
+ if out.may_fail.load(atomic::Ordering::Acquire) {
+ return;
} else {
assert!(
send_payment(&nodes[0], &nodes[1], chan_a, 10_000_000, &mut payment_id) ||
}
}
-pub fn chanmon_consistency_test<Out: test_logger::Output>(data: &[u8], out: Out) {
+/// We actually have different behavior based on if a certain log string has been seen, so we have
+/// to do a bit more tracking.
+#[derive(Clone)]
+struct SearchingOutput<O: Output> {
+ output: O,
+ may_fail: Arc<atomic::AtomicBool>,
+}
+impl<O: Output> Output for SearchingOutput<O> {
+ fn locked_write(&self, data: &[u8]) {
+ if std::str::from_utf8(data).unwrap().contains("Outbound update_fee HTLC buffer overflow - counterparty should force-close this channel") {
+ self.may_fail.store(true, atomic::Ordering::Release);
+ }
+ self.output.locked_write(data)
+ }
+}
+impl<O: Output> SearchingOutput<O> {
+ pub fn new(output: O) -> Self {
+ Self { output, may_fail: Arc::new(atomic::AtomicBool::new(false)) }
+ }
+}
+
+pub fn chanmon_consistency_test<Out: Output>(data: &[u8], out: Out) {
do_test(data, out);
}
pub trait Output : Clone + 'static {
fn locked_write(&self, data: &[u8]);
- fn locked_contains(&self, pattern: &str) -> bool;
}
#[derive(Clone)]
pub struct DevNull {}
impl Output for DevNull {
fn locked_write(&self, _data: &[u8]) {}
- fn locked_contains(&self, _pattern: &str) -> bool {
- false
- }
}
#[derive(Clone)]
pub struct StringBuffer(Arc<Mutex<String>>);
fn locked_write(&self, data: &[u8]) {
self.0.lock().unwrap().push_str(&String::from_utf8(data.to_vec()).unwrap());
}
- fn locked_contains(&self, pattern: &str) -> bool {
- self.0.lock().unwrap().contains(pattern)
- }
}
impl StringBuffer {
pub fn new() -> Self {