Skip to content

Commit bc7631f

Browse files
committed
Clean up some spurious test_utils/transaction_utils variables
PR #3323 introduced some extra variables to avoid `rustfmt` making a total mess of our code, but introduced a few that don't make `rustfmt` do dumb things, which we remove here.
1 parent 8e9ad55 commit bc7631f

File tree

2 files changed

+22
-43
lines changed

2 files changed

+22
-43
lines changed

lightning/src/util/test_utils.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -414,15 +414,10 @@ impl<'a> TestChainMonitor<'a> {
414414
fee_estimator: &'a TestFeeEstimator, persister: &'a dyn Persist<TestChannelSigner>,
415415
keys_manager: &'a TestKeysInterface,
416416
) -> Self {
417-
let added_monitors = Mutex::new(Vec::new());
418-
let monitor_updates = Mutex::new(new_hash_map());
419-
let latest_monitor_update_id = Mutex::new(new_hash_map());
420-
let expect_channel_force_closed = Mutex::new(None);
421-
let expect_monitor_round_trip_fail = Mutex::new(None);
422417
Self {
423-
added_monitors,
424-
monitor_updates,
425-
latest_monitor_update_id,
418+
added_monitors: Mutex::new(Vec::new()),
419+
monitor_updates: Mutex::new(new_hash_map()),
420+
latest_monitor_update_id: Mutex::new(new_hash_map()),
426421
chain_monitor: ChainMonitor::new(
427422
chain_source,
428423
broadcaster,
@@ -431,8 +426,8 @@ impl<'a> TestChainMonitor<'a> {
431426
persister,
432427
),
433428
keys_manager,
434-
expect_channel_force_closed,
435-
expect_monitor_round_trip_fail,
429+
expect_channel_force_closed: Mutex::new(None),
430+
expect_monitor_round_trip_fail: Mutex::new(None),
436431
}
437432
}
438433

@@ -909,13 +904,10 @@ impl TestChannelMessageHandler {
909904

910905
impl TestChannelMessageHandler {
911906
pub fn new(chain_hash: ChainHash) -> Self {
912-
let pending_events = Mutex::new(Vec::new());
913-
let expected_recv_msgs = Mutex::new(None);
914-
let connected_peers = Mutex::new(new_hash_set());
915907
TestChannelMessageHandler {
916-
pending_events,
917-
expected_recv_msgs,
918-
connected_peers,
908+
pending_events: Mutex::new(Vec::new()),
909+
expected_recv_msgs: Mutex::new(None),
910+
connected_peers: Mutex::new(new_hash_set()),
919911
chain_hash,
920912
}
921913
}
@@ -1567,19 +1559,14 @@ impl SignerProvider for TestKeysInterface {
15671559
impl TestKeysInterface {
15681560
pub fn new(seed: &[u8; 32], network: Network) -> Self {
15691561
let now = Duration::from_secs(genesis_block(network).header.time as u64);
1570-
let override_random_bytes = Mutex::new(None);
1571-
let enforcement_states = Mutex::new(new_hash_map());
1572-
let expectations = Mutex::new(None);
1573-
let unavailable_signers_ops = Mutex::new(new_hash_map());
1574-
let next_signer_disabled_ops = Mutex::new(new_hash_set());
15751562
Self {
15761563
backing: sign::PhantomKeysManager::new(seed, now.as_secs(), now.subsec_nanos(), seed),
1577-
override_random_bytes,
1564+
override_random_bytes: Mutex::new(None),
15781565
disable_revocation_policy_check: false,
1579-
enforcement_states,
1580-
expectations,
1581-
unavailable_signers_ops,
1582-
next_signer_disabled_ops,
1566+
enforcement_states: Mutex::new(new_hash_map()),
1567+
expectations: Mutex::new(None),
1568+
unavailable_signers_ops: Mutex::new(new_hash_map()),
1569+
next_signer_disabled_ops: Mutex::new(new_hash_set()),
15831570
}
15841571
}
15851572

@@ -1653,14 +1640,12 @@ impl TestChainSource {
16531640
let script_pubkey = Builder::new().push_opcode(opcodes::OP_TRUE).into_script();
16541641
let utxo_ret =
16551642
Mutex::new(UtxoResult::Sync(Ok(TxOut { value: Amount::MAX, script_pubkey })));
1656-
let watched_txn = Mutex::new(new_hash_set());
1657-
let watched_outputs = Mutex::new(new_hash_set());
16581643
Self {
16591644
chain_hash: ChainHash::using_genesis_block(network),
16601645
utxo_ret,
16611646
get_utxo_call_count: AtomicUsize::new(0),
1662-
watched_txn,
1663-
watched_outputs,
1647+
watched_txn: Mutex::new(new_hash_set()),
1648+
watched_outputs: Mutex::new(new_hash_set()),
16641649
}
16651650
}
16661651
pub fn remove_watched_txn_and_outputs(&self, outpoint: OutPoint, script_pubkey: ScriptBuf) {

lightning/src/util/transaction_utils.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,8 @@ mod tests {
219219
// If we have a bogus input amount or outputs valued more than inputs, we should fail
220220
let version = Version::TWO;
221221
let lock_time = LockTime::ZERO;
222-
let input = Vec::new();
223222
let tx_out = TxOut { script_pubkey: ScriptBuf::new(), value: Amount::from_sat(1000) };
224-
let output = vec![tx_out];
225-
let mut tx = Transaction { version, lock_time, input, output };
223+
let mut tx = Transaction { version, lock_time, input: Vec::new(), output: vec![tx_out] };
226224
let amount = Amount::from_sat(21_000_000_0000_0001);
227225
assert!(maybe_add_change_output(&mut tx, amount, 0, 253, ScriptBuf::new()).is_err());
228226
let amount = Amount::from_sat(400);
@@ -294,36 +292,32 @@ mod tests {
294292
let tx_in = TxIn { previous_output, script_sig, witness, sequence };
295293
let version = Version::TWO;
296294
let lock_time = LockTime::ZERO;
297-
let input = vec![tx_in];
298-
let output = vec![tx_out];
299-
let mut tx = Transaction { version, lock_time, input, output };
295+
let mut tx = Transaction { version, lock_time, input: vec![tx_in], output: vec![tx_out] };
300296
let orig_wtxid = tx.compute_wtxid();
301297
let orig_weight = tx.weight().to_wu();
302298
assert_eq!(orig_weight / 4, 61);
303299

304300
assert_eq!(Builder::new().push_int(2).into_script().minimal_non_dust().to_sat(), 474);
305301

302+
let script = Builder::new().push_int(2).into_script();
303+
306304
// Input value of the output value + fee - 1 should fail:
307305
let amount = Amount::from_sat(1000 + 61 + 100 - 1);
308-
let script = Builder::new().push_int(2).into_script();
309-
assert!(maybe_add_change_output(&mut tx, amount, 400, 250, script).is_err());
306+
assert!(maybe_add_change_output(&mut tx, amount, 400, 250, script.clone()).is_err());
310307
// Failure doesn't change the transaction
311308
assert_eq!(tx.compute_wtxid(), orig_wtxid);
312309
// but one more input sat should succeed, without changing the transaction
313310
let amount = Amount::from_sat(1000 + 61 + 100);
314-
let script = Builder::new().push_int(2).into_script();
315-
assert!(maybe_add_change_output(&mut tx, amount, 400, 250, script).is_ok());
311+
assert!(maybe_add_change_output(&mut tx, amount, 400, 250, script.clone()).is_ok());
316312
// If we don't add an output, we don't change the transaction
317313
assert_eq!(tx.compute_wtxid(), orig_wtxid);
318314
// In order to get a change output, we need to add 474 plus the output's weight / 4 (10)...
319315
let amount = Amount::from_sat(1000 + 61 + 100 + 474 + 9);
320-
let script = Builder::new().push_int(2).into_script();
321-
assert!(maybe_add_change_output(&mut tx, amount, 400, 250, script).is_ok());
316+
assert!(maybe_add_change_output(&mut tx, amount, 400, 250, script.clone()).is_ok());
322317
// If we don't add an output, we don't change the transaction
323318
assert_eq!(tx.compute_wtxid(), orig_wtxid);
324319

325320
let amount = Amount::from_sat(1000 + 61 + 100 + 474 + 10);
326-
let script = Builder::new().push_int(2).into_script();
327321
assert!(maybe_add_change_output(&mut tx, amount, 400, 250, script).is_ok());
328322
assert_eq!(tx.output.len(), 2);
329323
assert_eq!(tx.output[1].value.to_sat(), 474);

0 commit comments

Comments
 (0)