Skip to content

Commit dfbcacf

Browse files
committed
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.
1 parent dae97a4 commit dfbcacf

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/ln/channelmanager.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5369,8 +5369,7 @@ mod tests {
53695369
}}
53705370
}
53715371

5372-
#[test]
5373-
fn channel_reserve_test() {
5372+
fn do_channel_reserve_test(test_recv: bool) {
53745373
use util::rng;
53755374
use std::sync::atomic::Ordering;
53765375
use ln::msgs::HandleError;
@@ -5527,9 +5526,23 @@ mod tests {
55275526
onion_routing_packet: onion_packet,
55285527
};
55295528

5530-
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg).err().unwrap();
5531-
match err {
5532-
HandleError{err, .. } => assert_eq!(err, "Remote HTLC add would put them over their reserve value"),
5529+
if test_recv {
5530+
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg).err().unwrap();
5531+
match err {
5532+
HandleError{err, .. } => assert_eq!(err, "Remote HTLC add would put them over their reserve value"),
5533+
}
5534+
// If we send a garbage message, the channel should get closed, making the rest of this test case fail.
5535+
/*assert_eq!(nodes[1].node.list_channels().len(), 1);
5536+
assert_eq!(nodes[1].node.list_channels().len(), 1);
5537+
let channel_close_broadcast = nodes[1].node.get_and_clear_pending_msg_events();
5538+
assert_eq!(channel_close_broadcast.len(), 1);
5539+
match channel_close_broadcast[0] {
5540+
MessageSendEvent::BroadcastChannelUpdate { ref msg } => {
5541+
assert_eq!(msg.contents.flags & 2, 2);
5542+
},
5543+
_ => panic!("Unexpected event"),
5544+
}*/
5545+
return;
55335546
}
55345547
}
55355548

@@ -5637,6 +5650,12 @@ mod tests {
56375650
assert_eq!(stat2.value_to_self_msat, stat22.value_to_self_msat + recv_value_1 + recv_value_21 + recv_value_22);
56385651
}
56395652

5653+
#[test]
5654+
fn channel_reserve_test() {
5655+
do_channel_reserve_test(false);
5656+
do_channel_reserve_test(true);
5657+
}
5658+
56405659
#[test]
56415660
fn channel_monitor_network_test() {
56425661
// Simple test which builds a network of ChannelManagers, connects them to each other, and

0 commit comments

Comments
 (0)