X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmonitor_tests.rs;h=ece24794f63f593ecba133660fa73a466fc547a7;hb=26b515c13cccd1d027e67d0c65d69321d235ce40;hp=506af02c0b006c97947a451bcf7ad747a511b3cd;hpb=0b196ebae6b9b1f861c2fc2ceddcc128b9f46f18;p=rust-lightning diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 506af02c..ece24794 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -16,7 +16,7 @@ use crate::chain::chaininterface::{LowerBoundedFeeEstimator, compute_feerate_sat use crate::events::bump_transaction::{BumpTransactionEvent, WalletSource}; use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, ClosureReason, HTLCDestination}; use crate::ln::channel; -use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChannelManager, PaymentId, RecipientOnionFields}; +use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, PaymentId, RecipientOnionFields}; use crate::ln::msgs::ChannelMessageHandler; use crate::util::config::UserConfig; use crate::util::crypto::sign; @@ -95,7 +95,7 @@ fn chanmon_fail_from_stale_commitment() { fn test_spendable_output<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, spendable_tx: &Transaction) { let mut spendable = node.chain_monitor.chain_monitor.get_and_clear_pending_events(); assert_eq!(spendable.len(), 1); - if let Event::SpendableOutputs { outputs } = spendable.pop().unwrap() { + if let Event::SpendableOutputs { outputs, .. } = spendable.pop().unwrap() { assert_eq!(outputs.len(), 1); let spend_tx = node.keys_manager.backing.spend_spendable_outputs(&[&outputs[0]], Vec::new(), Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script(), 253, None, &Secp256k1::new()).unwrap(); @@ -269,12 +269,12 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { assert_eq!(funding_outpoint.to_channel_id(), chan_id); // This HTLC is immediately claimed, giving node B the preimage - let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1]], 3_000_000); + let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 3_000_000); // This HTLC is allowed to time out, letting A claim it. However, in order to test claimable // balances more fully we also give B the preimage for this HTLC. - let (timeout_payment_preimage, timeout_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1]], 4_000_000); + let (timeout_payment_preimage, timeout_payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 4_000_000); // This HTLC will be dust, and not be claimable at all: - let (dust_payment_preimage, dust_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1]], 3_000); + let (dust_payment_preimage, dust_payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 3_000); let htlc_cltv_timeout = nodes[0].best_block_info().1 + TEST_FINAL_CLTV + 1; // Note ChannelManager adds one to CLTV timeouts for safety @@ -1871,7 +1871,7 @@ fn test_yield_anchors_events() { &nodes, 0, 1, 1_000_000, 500_000_000 ).2; route_payment(&nodes[0], &[&nodes[1]], 1_000_000); - let (payment_preimage, payment_hash, _) = route_payment(&nodes[1], &[&nodes[0]], 1_000_000); + let (payment_preimage, payment_hash, ..) = route_payment(&nodes[1], &[&nodes[0]], 1_000_000); assert!(nodes[0].node.get_and_clear_pending_events().is_empty()); @@ -2191,7 +2191,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { // Alice should see that Bob is trying to claim to HTLCs, so she should now try to claim them at // the second level instead. - let revoked_claims = { + let revoked_claim_transactions = { let txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); assert_eq!(txn.len(), 2); @@ -2205,10 +2205,14 @@ fn test_anchors_aggregated_revoked_htlc_tx() { check_spends!(revoked_htlc_claim, htlc_tx); } - txn + let mut revoked_claim_transaction_map = HashMap::new(); + for current_tx in txn.into_iter() { + revoked_claim_transaction_map.insert(current_tx.txid(), current_tx); + } + revoked_claim_transaction_map }; for node in &nodes { - mine_transactions(node, &revoked_claims.iter().collect::>()); + mine_transactions(node, &revoked_claim_transactions.values().collect::>()); } @@ -2227,13 +2231,15 @@ fn test_anchors_aggregated_revoked_htlc_tx() { assert!(nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty()); let spendable_output_events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events(); assert_eq!(spendable_output_events.len(), 2); - for (idx, event) in spendable_output_events.iter().enumerate() { - if let Event::SpendableOutputs { outputs } = event { + for event in spendable_output_events.iter() { + if let Event::SpendableOutputs { outputs, channel_id } = event { assert_eq!(outputs.len(), 1); + assert!(vec![chan_b.2, chan_a.2].contains(&channel_id.unwrap())); let spend_tx = nodes[0].keys_manager.backing.spend_spendable_outputs( &[&outputs[0]], Vec::new(), Script::new_op_return(&[]), 253, None, &Secp256k1::new(), ).unwrap(); - check_spends!(spend_tx, revoked_claims[idx]); + + check_spends!(spend_tx, revoked_claim_transactions.get(&spend_tx.input[0].previous_output.txid).unwrap()); } else { panic!("unexpected event"); }