]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Use `check_added_monitors` test utility in invoice utils tests
authorMatt Corallo <git@bluematt.me>
Fri, 9 Aug 2024 13:20:35 +0000 (13:20 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 13 Aug 2024 12:54:59 +0000 (12:54 +0000)
In a coming commit, the `lightning-invoice::utils` module will move
to the `lightning` crate, causing its tests to be included in the
global lockorder tests done in that crate. This should be fine,
except that the `lightning-invoice::utils` module currently holds
the `added_monitors` lock too long causing lockorder violations.

Instead, this commit replaces the legacy monitors-added test with
the `check_added_monitors` test utility.

lightning-invoice/src/utils.rs

index 669e6f50f1ac93f72e3707770a645f95f3755c18..5b94c3adac3eefee97774506319d1f705baefe72 100644 (file)
@@ -905,20 +905,15 @@ mod test {
                        nodes[0].node.send_payment(payment_hash,
                                RecipientOnionFields::secret_only(*invoice.payment_secret()),
                                PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
-                       let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
-                       assert_eq!(added_monitors.len(), 1);
-                       added_monitors.clear();
+                       check_added_monitors(&nodes[0], 1);
 
                        let mut events = nodes[0].node.get_and_clear_pending_msg_events();
                        assert_eq!(events.len(), 1);
                        SendEvent::from_event(events.remove(0))
-
                };
                nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
                nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg);
-               let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
-               assert_eq!(added_monitors.len(), 1);
-               added_monitors.clear();
+               check_added_monitors(&nodes[1], 1);
                let events = nodes[1].node.get_and_clear_pending_msg_events();
                assert_eq!(events.len(), 2);
        }
@@ -1362,9 +1357,7 @@ mod test {
                        nodes[0].node.send_payment(payment_hash,
                                RecipientOnionFields::secret_only(*invoice.payment_secret()),
                                PaymentId(payment_hash.0), params, Retry::Attempts(0)).unwrap();
-                       let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
-                       assert_eq!(added_monitors.len(), 1);
-                       added_monitors.clear();
+                       check_added_monitors(&nodes[0], 1);
 
                        let mut events = nodes[0].node.get_and_clear_pending_msg_events();
                        assert_eq!(events.len(), 1);