Refactor `mpp_retry[_overpay]` tests to use `SendEvent::from_event`
authorElias Rohrer <dev@tnull.de>
Wed, 27 Sep 2023 07:57:20 +0000 (09:57 +0200)
committerElias Rohrer <dev@tnull.de>
Thu, 28 Sep 2023 17:45:30 +0000 (19:45 +0200)
.. as a follow-up from #2417.

lightning/src/ln/payment_tests.rs

index 22d85ecc76c3af0a5bbb8d5df0a74fb30db6fe0e..0af1d69f2aa7671178d5bfecf1b0980b4cdb0728 100644 (file)
@@ -114,19 +114,9 @@ fn mpp_retry() {
 
        // Add the HTLC along the first hop.
        let fail_path_msgs_1 = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events);
-       let (update_add, commitment_signed) = match fail_path_msgs_1 {
-               MessageSendEvent::UpdateHTLCs { node_id: _, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed } } => {
-                       assert_eq!(update_add_htlcs.len(), 1);
-                       assert!(update_fail_htlcs.is_empty());
-                       assert!(update_fulfill_htlcs.is_empty());
-                       assert!(update_fail_malformed_htlcs.is_empty());
-                       assert!(update_fee.is_none());
-                       (update_add_htlcs[0].clone(), commitment_signed.clone())
-               },
-               _ => panic!("Unexpected event"),
-       };
-       nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add);
-       commitment_signed_dance!(nodes[2], nodes[0], commitment_signed, false);
+       let send_event = SendEvent::from_event(fail_path_msgs_1);
+       nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]);
+       commitment_signed_dance!(nodes[2], nodes[0], &send_event.commitment_msg, false);
 
        // Attempt to forward the payment and complete the 2nd path's failure.
        expect_pending_htlcs_forwardable!(&nodes[2]);
@@ -225,25 +215,9 @@ fn mpp_retry_overpay() {
 
        // Add the HTLC along the first hop.
        let fail_path_msgs_1 = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events);
-       let (update_add, commitment_signed) = match fail_path_msgs_1 {
-               MessageSendEvent::UpdateHTLCs {
-                       node_id: _,
-                       updates: msgs::CommitmentUpdate {
-                                       ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs,
-                                       ref update_fail_malformed_htlcs, ref update_fee, ref commitment_signed
-                       }
-               } => {
-                       assert_eq!(update_add_htlcs.len(), 1);
-                       assert!(update_fail_htlcs.is_empty());
-                       assert!(update_fulfill_htlcs.is_empty());
-                       assert!(update_fail_malformed_htlcs.is_empty());
-                       assert!(update_fee.is_none());
-                       (update_add_htlcs[0].clone(), commitment_signed.clone())
-               },
-               _ => panic!("Unexpected event"),
-       };
-       nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add);
-       commitment_signed_dance!(nodes[2], nodes[0], commitment_signed, false);
+       let send_event = SendEvent::from_event(fail_path_msgs_1);
+       nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]);
+       commitment_signed_dance!(nodes[2], nodes[0], &send_event.commitment_msg, false);
 
        // Attempt to forward the payment and complete the 2nd path's failure.
        expect_pending_htlcs_forwardable!(&nodes[2]);