Skip to content

Commit 4ce23bc

Browse files
committed
Clean up misc rustfmt verticality in tests
`rustfmt` loves to make expressions vertical by putting each method parameter or `.` subexpression on its own line. In cases where each method parameter or `.` subexpression is actually doing something, this can be fine, but in some cases we have a few method parameters that are straightforward and shouldn't be the readers focus, mixed with one or two parameters which are key or a few subexpressions which simply do rote variable indexing or locking. Here we clean up various `rustfmt` verticality that exposes unimportant details of tests and test utils, making it easier for the reader to skim past them by introducing additional variables.
1 parent 7882d04 commit 4ce23bc

File tree

4 files changed

+37
-84
lines changed

4 files changed

+37
-84
lines changed

lightning/src/ln/async_signer_tests.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,20 +1299,10 @@ fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) {
12991299

13001300
assert!(nodes[0].node.list_channels().is_empty());
13011301
assert!(nodes[1].node.list_channels().is_empty());
1302-
check_closed_event!(
1303-
nodes[0],
1304-
1,
1305-
ClosureReason::LocallyInitiatedCooperativeClosure,
1306-
[node_b_id],
1307-
100000
1308-
);
1309-
check_closed_event!(
1310-
nodes[1],
1311-
1,
1312-
ClosureReason::CounterpartyInitiatedCooperativeClosure,
1313-
[node_a_id],
1314-
100000
1315-
);
1302+
let reason_a = ClosureReason::LocallyInitiatedCooperativeClosure;
1303+
check_closed_event!(nodes[0], 1, reason_a, [node_b_id], 100000);
1304+
let reason_b = ClosureReason::CounterpartyInitiatedCooperativeClosure;
1305+
check_closed_event!(nodes[1], 1, reason_b, [node_a_id], 100000);
13161306
}
13171307

13181308
#[test]

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -799,12 +799,8 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
799799
{
800800
for channel_id in self.chain_monitor.chain_monitor.list_monitors() {
801801
let mut w = test_utils::TestVecWriter(Vec::new());
802-
self.chain_monitor
803-
.chain_monitor
804-
.get_monitor(channel_id)
805-
.unwrap()
806-
.write(&mut w)
807-
.unwrap();
802+
let mon = self.chain_monitor.chain_monitor.get_monitor(channel_id).unwrap();
803+
mon.write(&mut w).unwrap();
808804
let (_, deserialized_monitor) =
809805
<(BlockHash, ChannelMonitor<TestChannelSigner>)>::read(
810806
&mut io::Cursor::new(&w.0),

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,9 @@ fn test_priv_forwarding_rejection() {
105105

106106
nodes[0].node.handle_update_fail_htlc(node_b_id, &htlc_fail_updates.update_fail_htlcs[0]);
107107
commitment_signed_dance!(nodes[0], nodes[1], htlc_fail_updates.commitment_signed, true, true);
108-
expect_payment_failed_with_update!(
109-
nodes[0],
110-
our_payment_hash,
111-
false,
112-
nodes[2].node.list_channels()[0].short_channel_id.unwrap(),
113-
true
114-
);
108+
109+
let chan_2_scid = nodes[2].node.list_channels()[0].short_channel_id.unwrap();
110+
expect_payment_failed_with_update!(nodes[0], our_payment_hash, false, chan_2_scid, true);
115111

116112
// Now disconnect nodes[1] from its peers and restart with accept_forwards_to_priv_channels set
117113
// to true. Sadly there is currently no way to change it at runtime.
@@ -967,14 +963,11 @@ fn test_0conf_channel_with_async_monitor() {
967963
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
968964

969965
chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
970-
let (_, latest_update) = nodes[1]
971-
.chain_monitor
972-
.latest_monitor_update_id
973-
.lock()
974-
.unwrap()
975-
.get(&bs_raa.channel_id)
976-
.unwrap()
977-
.clone();
966+
let (_, latest_update) = {
967+
let latest_monitor_update_id =
968+
nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap();
969+
latest_monitor_update_id.get(&bs_raa.channel_id).unwrap().clone()
970+
};
978971
nodes[1]
979972
.chain_monitor
980973
.chain_monitor
@@ -1020,13 +1013,8 @@ fn test_0conf_close_no_early_chan_update() {
10201013

10211014
nodes[0].node.force_close_all_channels_broadcasting_latest_txn(error_message.to_string());
10221015
check_added_monitors!(nodes[0], 1);
1023-
check_closed_event!(
1024-
&nodes[0],
1025-
1,
1026-
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true) },
1027-
[node_b_id],
1028-
100000
1029-
);
1016+
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true) };
1017+
check_closed_event!(&nodes[0], 1, reason, [node_b_id], 100000);
10301018
let _ = get_err_msg(&nodes[0], &node_b_id);
10311019
}
10321020

@@ -1138,28 +1126,18 @@ fn test_0conf_channel_reorg() {
11381126
// At this point the channel no longer has an SCID again. In the future we should likely
11391127
// support simply un-setting the SCID and waiting until the channel gets re-confirmed, but for
11401128
// now we force-close the channel here.
1141-
check_closed_event!(
1142-
&nodes[0],
1143-
1,
1144-
ClosureReason::ProcessingError {
1145-
err: "Funding transaction was un-confirmed. Locked at 0 confs, now have 0 confs."
1146-
.to_owned()
1147-
},
1148-
[node_b_id],
1149-
100000
1150-
);
1129+
let reason = ClosureReason::ProcessingError {
1130+
err: "Funding transaction was un-confirmed. Locked at 0 confs, now have 0 confs."
1131+
.to_owned()
1132+
};
1133+
check_closed_event!(&nodes[0], 1, reason, [node_b_id], 100000);
11511134
check_closed_broadcast!(nodes[0], true);
11521135
check_added_monitors(&nodes[0], 1);
1153-
check_closed_event!(
1154-
&nodes[1],
1155-
1,
1156-
ClosureReason::ProcessingError {
1157-
err: "Funding transaction was un-confirmed. Locked at 0 confs, now have 0 confs."
1158-
.to_owned()
1159-
},
1160-
[node_a_id],
1161-
100000
1162-
);
1136+
let reason = ClosureReason::ProcessingError {
1137+
err: "Funding transaction was un-confirmed. Locked at 0 confs, now have 0 confs."
1138+
.to_owned()
1139+
};
1140+
check_closed_event!(&nodes[1], 1, reason, [node_a_id], 100000);
11631141
check_closed_broadcast!(nodes[1], true);
11641142
check_added_monitors(&nodes[1], 1);
11651143
}

lightning/src/ln/shutdown_tests.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,20 +1346,12 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) {
13461346
// nodes[1] should happily accept and respond to.
13471347
node_0_closing_signed.fee_range.as_mut().unwrap().max_fee_satoshis *= 10;
13481348
{
1349-
let mut node_0_per_peer_lock;
1350-
let mut node_0_peer_state_lock;
1351-
get_channel_ref!(
1352-
nodes[0],
1353-
nodes[1],
1354-
node_0_per_peer_lock,
1355-
node_0_peer_state_lock,
1356-
chan_id
1357-
)
1358-
.context_mut()
1359-
.closing_fee_limits
1360-
.as_mut()
1361-
.unwrap()
1362-
.1 *= 10;
1349+
let mut per_peer_lock;
1350+
let mut peer_state_lock;
1351+
let chan =
1352+
get_channel_ref!(nodes[0], nodes[1], per_peer_lock, peer_state_lock, chan_id);
1353+
1354+
chan.context_mut().closing_fee_limits.as_mut().unwrap().1 *= 10;
13631355
}
13641356
nodes[1].node.handle_closing_signed(node_a_id, &node_0_closing_signed);
13651357
let node_1_closing_signed =
@@ -1609,14 +1601,11 @@ fn do_outbound_update_no_early_closing_signed(use_htlc: bool) {
16091601

16101602
expect_channel_shutdown_state!(nodes[0], chan_id, ChannelShutdownState::ResolvingHTLCs);
16111603
assert_eq!(nodes[0].node.get_and_clear_pending_msg_events(), Vec::new());
1612-
let (latest_update, _) = nodes[0]
1613-
.chain_monitor
1614-
.latest_monitor_update_id
1615-
.lock()
1616-
.unwrap()
1617-
.get(&chan_id)
1618-
.unwrap()
1619-
.clone();
1604+
let (latest_update, _) = {
1605+
let latest_monitor_update_id =
1606+
nodes[0].chain_monitor.latest_monitor_update_id.lock().unwrap();
1607+
latest_monitor_update_id.get(&chan_id).unwrap().clone()
1608+
};
16201609
nodes[0].chain_monitor.chain_monitor.force_channel_monitor_updated(chan_id, latest_update);
16211610

16221611
let as_raa_closing_signed = nodes[0].node.get_and_clear_pending_msg_events();

0 commit comments

Comments
 (0)