Skip to content

Commit 0d1705d

Browse files
committed
f Use other match pattern here already
.. to keep changes in the following commits minimal.
1 parent 4c35c4a commit 0d1705d

File tree

1 file changed

+34
-49
lines changed

1 file changed

+34
-49
lines changed

lightning/src/ln/payment_tests.rs

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -637,29 +637,22 @@ fn test_reject_mpp_keysend_htlc_mismatching_secret() {
637637

638638
assert!(nodes[3].node.get_and_clear_pending_msg_events().is_empty());
639639
assert_eq!(nodes[3].node.forward_htlcs.lock().unwrap().len(), 1);
640-
if let Some((_, pending_forwards)) =
641-
nodes[3].node.forward_htlcs.lock().unwrap().iter_mut().next()
642-
{
643-
assert_eq!(pending_forwards.len(), 1);
644-
match pending_forwards.get_mut(0).unwrap() {
645-
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) => {
646-
match forward_info.routing {
647-
PendingHTLCRouting::ReceiveKeysend { ref mut payment_data, .. } => {
648-
*payment_data = Some(msgs::FinalOnionHopData {
649-
payment_secret: PaymentSecret([42; 32]),
650-
total_msat: amount * 2,
651-
});
652-
},
653-
_ => panic!("Expected PendingHTLCRouting::ReceiveKeysend"),
654-
}
655-
},
656-
_ => {
657-
panic!("Unexpected HTLCForwardInfo");
658-
},
659-
}
660-
} else {
661-
panic!("Expected pending receive");
662-
};
640+
match nodes[3].node.forward_htlcs.lock().unwrap().get_mut(&0).unwrap().get_mut(0).unwrap() {
641+
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) => {
642+
match forward_info.routing {
643+
PendingHTLCRouting::ReceiveKeysend { ref mut payment_data, .. } => {
644+
*payment_data = Some(msgs::FinalOnionHopData {
645+
payment_secret: PaymentSecret([42; 32]),
646+
total_msat: amount * 2,
647+
});
648+
},
649+
_ => panic!("Expected PendingHTLCRouting::ReceiveKeysend"),
650+
}
651+
},
652+
_ => {
653+
panic!("Unexpected HTLCForwardInfo");
654+
},
655+
}
663656
nodes[3].node.process_pending_htlc_forwards();
664657

665658
// Pay along nodes[2]
@@ -687,34 +680,26 @@ fn test_reject_mpp_keysend_htlc_mismatching_secret() {
687680
let update_add_3 = update_3.update_add_htlcs[0].clone();
688681
nodes[3].node.handle_update_add_htlc(node_c_id, &update_add_3);
689682
commitment_signed_dance!(nodes[3], nodes[2], update_3.commitment_signed, false, true);
690-
expect_htlc_failure_conditions(nodes[3].node.get_and_clear_pending_events(), &[]);
691-
nodes[3].node.process_pending_update_add_htlcs();
692-
683+
assert!(nodes[3].node.get_and_clear_pending_events().is_empty());
693684
assert!(nodes[3].node.get_and_clear_pending_msg_events().is_empty());
685+
nodes[3].node.process_pending_update_add_htlcs();
694686
assert_eq!(nodes[3].node.forward_htlcs.lock().unwrap().len(), 1);
695-
if let Some((_, pending_forwards)) =
696-
nodes[3].node.forward_htlcs.lock().unwrap().iter_mut().next()
697-
{
698-
assert_eq!(pending_forwards.len(), 1);
699-
match pending_forwards.get_mut(0).unwrap() {
700-
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) => {
701-
match forward_info.routing {
702-
PendingHTLCRouting::ReceiveKeysend { ref mut payment_data, .. } => {
703-
*payment_data = Some(msgs::FinalOnionHopData {
704-
payment_secret: PaymentSecret([43; 32]), // Doesn't match the secret used above
705-
total_msat: amount * 2,
706-
});
707-
},
708-
_ => panic!("Expected PendingHTLCRouting::ReceiveKeysend"),
709-
}
710-
},
711-
_ => {
712-
panic!("Unexpected HTLCForwardInfo");
713-
},
714-
}
715-
} else {
716-
panic!("Expected pending receive");
717-
};
687+
match nodes[3].node.forward_htlcs.lock().unwrap().get_mut(&0).unwrap().get_mut(0).unwrap() {
688+
&mut HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo { ref mut forward_info, .. }) => {
689+
match forward_info.routing {
690+
PendingHTLCRouting::ReceiveKeysend { ref mut payment_data, .. } => {
691+
*payment_data = Some(msgs::FinalOnionHopData {
692+
payment_secret: PaymentSecret([43; 32]), // Doesn't match the secret used above
693+
total_msat: amount * 2,
694+
});
695+
},
696+
_ => panic!("Expected PendingHTLCRouting::ReceiveKeysend"),
697+
}
698+
},
699+
_ => {
700+
panic!("Unexpected HTLCForwardInfo");
701+
},
702+
}
718703
nodes[3].node.process_pending_htlc_forwards();
719704
let fail_type = HTLCHandlingFailureType::Receive { payment_hash };
720705
expect_and_process_pending_htlcs_and_htlc_handling_failed(&nodes[3], &[fail_type]);

0 commit comments

Comments
 (0)