Skip to content

Commit 9c558b2

Browse files
committed
Simplify channelmonitor tests which use chain::Watch and Persister
test_simple_monitor_permanent_update_fail and test_simple_monitor_temporary_update_fail both have a mode where they use either chain::Watch or persister to return errors. As we won't be doing any returns directly from the chain::Watch wrapper in a coming commit, the chain::Watch-return form of the test will no longer make sense.
1 parent 65dc6b3 commit 9c558b2

File tree

1 file changed

+9
-36
lines changed

1 file changed

+9
-36
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ use io;
4343
use prelude::*;
4444
use sync::{Arc, Mutex};
4545

46-
// If persister_fail is true, we have the persister return a PermanentFailure
47-
// instead of the higher-level ChainMonitor.
48-
fn do_test_simple_monitor_permanent_update_fail(persister_fail: bool) {
46+
#[test]
47+
fn test_simple_monitor_permanent_update_fail() {
4948
// Test that we handle a simple permanent monitor update failure
5049
let mut chanmon_cfgs = create_chanmon_cfgs(2);
5150
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
@@ -56,10 +55,7 @@ fn do_test_simple_monitor_permanent_update_fail(persister_fail: bool) {
5655

5756
let (_, payment_hash_1, payment_secret_1) = get_payment_preimage_hash!(&nodes[1]);
5857

59-
match persister_fail {
60-
true => chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::PermanentFailure)),
61-
false => *nodes[0].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::PermanentFailure))
62-
}
58+
*nodes[0].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::PermanentFailure));
6359
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
6460
let route = get_route(&nodes[0].node.get_our_node_id(), &net_graph_msg_handler.network_graph, &nodes[1].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 1000000, TEST_FINAL_CLTV, &logger).unwrap();
6561
unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)), true, APIError::ChannelUnavailable {..}, {});
@@ -156,17 +152,7 @@ fn test_monitor_and_persister_update_fail() {
156152
assert_eq!(events.len(), 1);
157153
}
158154

159-
#[test]
160-
fn test_simple_monitor_permanent_update_fail() {
161-
do_test_simple_monitor_permanent_update_fail(false);
162-
163-
// Test behavior when the persister returns a PermanentFailure.
164-
do_test_simple_monitor_permanent_update_fail(true);
165-
}
166-
167-
// If persister_fail is true, we have the persister return a TemporaryFailure instead of the
168-
// higher-level ChainMonitor.
169-
fn do_test_simple_monitor_temporary_update_fail(disconnect: bool, persister_fail: bool) {
155+
fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
170156
// Test that we can recover from a simple temporary monitor update failure optionally with
171157
// a disconnect in between
172158
let mut chanmon_cfgs = create_chanmon_cfgs(2);
@@ -178,10 +164,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool, persister_fail
178164

179165
let (payment_preimage_1, payment_hash_1, payment_secret_1) = get_payment_preimage_hash!(&nodes[1]);
180166

181-
match persister_fail {
182-
true => chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure)),
183-
false => *nodes[0].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure))
184-
}
167+
chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
185168

186169
{
187170
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
@@ -200,10 +183,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool, persister_fail
200183
reconnect_nodes(&nodes[0], &nodes[1], (true, true), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
201184
}
202185

203-
match persister_fail {
204-
true => chanmon_cfgs[0].persister.set_update_ret(Ok(())),
205-
false => *nodes[0].chain_monitor.update_ret.lock().unwrap() = Some(Ok(()))
206-
}
186+
chanmon_cfgs[0].persister.set_update_ret(Ok(()));
207187
let (outpoint, latest_update) = nodes[0].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone();
208188
nodes[0].node.channel_monitor_updated(&outpoint, latest_update);
209189
check_added_monitors!(nodes[0], 0);
@@ -239,10 +219,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool, persister_fail
239219
// Now set it to failed again...
240220
let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(&nodes[1]);
241221
{
242-
match persister_fail {
243-
true => chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure)),
244-
false => *nodes[0].chain_monitor.update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure))
245-
}
222+
chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
246223
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
247224
let route = get_route(&nodes[0].node.get_our_node_id(), &net_graph_msg_handler.network_graph, &nodes[1].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 1000000, TEST_FINAL_CLTV, &logger).unwrap();
248225
unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)), false, APIError::MonitorUpdateFailed, {});
@@ -273,12 +250,8 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool, persister_fail
273250

274251
#[test]
275252
fn test_simple_monitor_temporary_update_fail() {
276-
do_test_simple_monitor_temporary_update_fail(false, false);
277-
do_test_simple_monitor_temporary_update_fail(true, false);
278-
279-
// Test behavior when the persister returns a TemporaryFailure.
280-
do_test_simple_monitor_temporary_update_fail(false, true);
281-
do_test_simple_monitor_temporary_update_fail(true, true);
253+
do_test_simple_monitor_temporary_update_fail(false);
254+
do_test_simple_monitor_temporary_update_fail(true);
282255
}
283256

284257
fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {

0 commit comments

Comments
 (0)