Split channel_reserve_test so we don't rely on unfilled Err actions
authorMatt Corallo <git@bluematt.me>
Fri, 23 Nov 2018 04:44:42 +0000 (23:44 -0500)
committerMatt Corallo <git@bluematt.me>
Fri, 23 Nov 2018 04:57:54 +0000 (23:57 -0500)
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.

src/ln/channelmanager.rs

index c87e5a6ef15c6572f75e8035d6c01649b72ba616..ddd6b2f214afbf54910e7a6ba38a2de383484e17 100644 (file)
@@ -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