Skip to content

Commit 613622a

Browse files
committed
f DRY
1 parent 61aef9b commit 613622a

File tree

1 file changed

+17
-39
lines changed

1 file changed

+17
-39
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
10771077
} }
10781078
}
10791079

1080+
let complete_first = |v: &mut Vec<_>| if !v.is_empty() { Some(v.remove(0)) } else { None };
1081+
let complete_second = |v: &mut Vec<_>| if v.len() > 1 { Some(v.remove(1)) } else { None };
10801082
let complete_monitor_update = |
10811083
monitor: &Arc<TestChainMonitor>, chan_funding,
10821084
compl_selector: &dyn Fn(&mut Vec<(u64, Vec<u8>)>) -> Option<(u64, Vec<u8>)>,
@@ -1337,45 +1339,21 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
13371339
},
13381340
0x89 => { fee_est_c.ret_val.store(253, atomic::Ordering::Release); nodes[2].maybe_update_chan_fees(); },
13391341

1340-
0xf0 =>
1341-
complete_monitor_update(&monitor_a, &chan_1_funding,
1342-
&|v: &mut Vec<_>| if !v.is_empty() { Some(v.remove(0)) } else { None }),
1343-
0xf1 =>
1344-
complete_monitor_update(&monitor_a, &chan_1_funding,
1345-
&|v: &mut Vec<_>| if v.len() > 1 { Some(v.remove(1)) } else { None }),
1346-
0xf2 =>
1347-
complete_monitor_update(&monitor_a, &chan_1_funding,
1348-
&|v: &mut Vec<_>| v.pop()),
1349-
1350-
0xf4 =>
1351-
complete_monitor_update(&monitor_b, &chan_1_funding,
1352-
&|v: &mut Vec<_>| if !v.is_empty() { Some(v.remove(0)) } else { None }),
1353-
0xf5 =>
1354-
complete_monitor_update(&monitor_b, &chan_1_funding,
1355-
&|v: &mut Vec<_>| if v.len() > 1 { Some(v.remove(1)) } else { None }),
1356-
0xf6 =>
1357-
complete_monitor_update(&monitor_b, &chan_1_funding,
1358-
&|v: &mut Vec<_>| v.pop()),
1359-
1360-
0xf8 =>
1361-
complete_monitor_update(&monitor_b, &chan_2_funding,
1362-
&|v: &mut Vec<_>| if !v.is_empty() { Some(v.remove(0)) } else { None }),
1363-
0xf9 =>
1364-
complete_monitor_update(&monitor_b, &chan_2_funding,
1365-
&|v: &mut Vec<_>| if v.len() > 1 { Some(v.remove(1)) } else { None }),
1366-
0xfa =>
1367-
complete_monitor_update(&monitor_b, &chan_2_funding,
1368-
&|v: &mut Vec<_>| v.pop()),
1369-
1370-
0xfc =>
1371-
complete_monitor_update(&monitor_c, &chan_2_funding,
1372-
&|v: &mut Vec<_>| if !v.is_empty() { Some(v.remove(0)) } else { None }),
1373-
0xfd =>
1374-
complete_monitor_update(&monitor_c, &chan_2_funding,
1375-
&|v: &mut Vec<_>| if v.len() > 1 { Some(v.remove(1)) } else { None }),
1376-
0xfe =>
1377-
complete_monitor_update(&monitor_c, &chan_2_funding,
1378-
&|v: &mut Vec<_>| v.pop()),
1342+
0xf0 => complete_monitor_update(&monitor_a, &chan_1_funding, &complete_first),
1343+
0xf1 => complete_monitor_update(&monitor_a, &chan_1_funding, &complete_second),
1344+
0xf2 => complete_monitor_update(&monitor_a, &chan_1_funding, &Vec::pop),
1345+
1346+
0xf4 => complete_monitor_update(&monitor_b, &chan_1_funding, &complete_first),
1347+
0xf5 => complete_monitor_update(&monitor_b, &chan_1_funding, &complete_second),
1348+
0xf6 => complete_monitor_update(&monitor_b, &chan_1_funding, &Vec::pop),
1349+
1350+
0xf8 => complete_monitor_update(&monitor_b, &chan_2_funding, &complete_first),
1351+
0xf9 => complete_monitor_update(&monitor_b, &chan_2_funding, &complete_second),
1352+
0xfa => complete_monitor_update(&monitor_b, &chan_2_funding, &Vec::pop),
1353+
1354+
0xfc => complete_monitor_update(&monitor_c, &chan_2_funding, &complete_first),
1355+
0xfd => complete_monitor_update(&monitor_c, &chan_2_funding, &complete_second),
1356+
0xfe => complete_monitor_update(&monitor_c, &chan_2_funding, &Vec::pop),
13791357

13801358
0xff => {
13811359
// Test that no channel is in a stuck state where neither party can send funds even

0 commit comments

Comments
 (0)