From: Matt Corallo Date: Fri, 23 Nov 2018 04:44:42 +0000 (-0500) Subject: Split channel_reserve_test so we don't rely on unfilled Err actions X-Git-Tag: v0.0.12~264^2~7 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=dfbcacfe0ef446234d0d40400fc818908311da7b;p=rust-lightning Split channel_reserve_test so we don't rely on unfilled Err actions Currently channel_reserve_test sends a garbage update_add_htlc message and then relies on it being silently ignored to continue using the channel. This shouldn't be the case, so take the easy way out and split the test in two, at first not delivering the bogus update_add_htlc and then delivering it, but not running the rest of the test. --- diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index c87e5a6ef..ddd6b2f21 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -5369,8 +5369,7 @@ mod tests { }} } - #[test] - fn channel_reserve_test() { + fn do_channel_reserve_test(test_recv: bool) { use util::rng; use std::sync::atomic::Ordering; use ln::msgs::HandleError; @@ -5527,9 +5526,23 @@ mod tests { onion_routing_packet: onion_packet, }; - let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg).err().unwrap(); - match err { - HandleError{err, .. } => assert_eq!(err, "Remote HTLC add would put them over their reserve value"), + if test_recv { + let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg).err().unwrap(); + match err { + HandleError{err, .. } => assert_eq!(err, "Remote HTLC add would put them over their reserve value"), + } + // If we send a garbage message, the channel should get closed, making the rest of this test case fail. + /*assert_eq!(nodes[1].node.list_channels().len(), 1); + assert_eq!(nodes[1].node.list_channels().len(), 1); + let channel_close_broadcast = nodes[1].node.get_and_clear_pending_msg_events(); + assert_eq!(channel_close_broadcast.len(), 1); + match channel_close_broadcast[0] { + MessageSendEvent::BroadcastChannelUpdate { ref msg } => { + assert_eq!(msg.contents.flags & 2, 2); + }, + _ => panic!("Unexpected event"), + }*/ + return; } } @@ -5637,6 +5650,12 @@ mod tests { assert_eq!(stat2.value_to_self_msat, stat22.value_to_self_msat + recv_value_1 + recv_value_21 + recv_value_22); } + #[test] + fn channel_reserve_test() { + do_channel_reserve_test(false); + do_channel_reserve_test(true); + } + #[test] fn channel_monitor_network_test() { // Simple test which builds a network of ChannelManagers, connects them to each other, and