Skip to content

Commit ab5185c

Browse files
committed
Clean up exceedingly vertical code in chainmonitor.rs tests
In c356070 we ran `rustfmt` on all of `chainmonitor.rs`, but left a few expressions in `test_async_ooo_offchain_updates` exceedingly vertical (with redundant code across both `c_bindings` compile modes). Here we reduce redundant code to simplify the expressions, reducing verticality as a side effect.
1 parent f22ffbb commit ab5185c

File tree

1 file changed

+19
-42
lines changed

1 file changed

+19
-42
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,57 +1305,34 @@ mod tests {
13051305
// fail either way but if it fails intermittently it's depending on the ordering of updates.
13061306
let mut update_iter = updates.iter();
13071307
let next_update = update_iter.next().unwrap().clone();
1308+
let node_b_mon = &nodes[1].chain_monitor.chain_monitor;
1309+
13081310
// Should contain next_update when pending updates listed.
1311+
let pending_updates = node_b_mon.list_pending_monitor_updates();
13091312
#[cfg(not(c_bindings))]
1310-
assert!(nodes[1]
1311-
.chain_monitor
1312-
.chain_monitor
1313-
.list_pending_monitor_updates()
1314-
.get(&channel_id)
1315-
.unwrap()
1316-
.contains(&next_update));
1313+
let pending_chan_updates = pending_updates.get(&channel_id).unwrap();
13171314
#[cfg(c_bindings)]
1318-
assert!(nodes[1]
1319-
.chain_monitor
1320-
.chain_monitor
1321-
.list_pending_monitor_updates()
1322-
.iter()
1323-
.find(|(chan_id, _)| *chan_id == channel_id)
1324-
.unwrap()
1325-
.1
1326-
.contains(&next_update));
1327-
nodes[1]
1328-
.chain_monitor
1329-
.chain_monitor
1330-
.channel_monitor_updated(channel_id, next_update.clone())
1331-
.unwrap();
1315+
let pending_chan_updates =
1316+
&pending_updates.iter().find(|(chan_id, _)| *chan_id == channel_id).unwrap().1;
1317+
assert!(pending_chan_updates.contains(&next_update));
1318+
1319+
node_b_mon.channel_monitor_updated(channel_id, next_update.clone()).unwrap();
1320+
13321321
// Should not contain the previously pending next_update when pending updates listed.
1322+
let pending_updates = node_b_mon.list_pending_monitor_updates();
13331323
#[cfg(not(c_bindings))]
1334-
assert!(!nodes[1]
1335-
.chain_monitor
1336-
.chain_monitor
1337-
.list_pending_monitor_updates()
1338-
.get(&channel_id)
1339-
.unwrap()
1340-
.contains(&next_update));
1324+
let pending_chan_updates = pending_updates.get(&channel_id).unwrap();
13411325
#[cfg(c_bindings)]
1342-
assert!(!nodes[1]
1343-
.chain_monitor
1344-
.chain_monitor
1345-
.list_pending_monitor_updates()
1346-
.iter()
1347-
.find(|(chan_id, _)| *chan_id == channel_id)
1348-
.unwrap()
1349-
.1
1350-
.contains(&next_update));
1326+
let pending_chan_updates =
1327+
&pending_updates.iter().find(|(chan_id, _)| *chan_id == channel_id).unwrap().1;
1328+
assert!(!pending_chan_updates.contains(&next_update));
1329+
13511330
assert!(nodes[1].chain_monitor.release_pending_monitor_events().is_empty());
13521331
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
13531332
assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
1354-
nodes[1]
1355-
.chain_monitor
1356-
.chain_monitor
1357-
.channel_monitor_updated(channel_id, update_iter.next().unwrap().clone())
1358-
.unwrap();
1333+
1334+
let next_update = update_iter.next().unwrap().clone();
1335+
node_b_mon.channel_monitor_updated(channel_id, next_update).unwrap();
13591336

13601337
let claim_events = nodes[1].node.get_and_clear_pending_events();
13611338
assert_eq!(claim_events.len(), 2);

0 commit comments

Comments
 (0)