Merge pull request #970 from TheBlueMatt/2021-06-no-confirmed-csv-delay
[rust-lightning] / lightning / src / ln / functional_test_utils.rs
index 166e943e66ddb1007dafbab2f49c843e6db63467..00bde294cefa7eda24590a03596615a680872a14 100644 (file)
@@ -221,6 +221,9 @@ impl<'a, 'b, 'c> Node<'a, 'b, 'c> {
        pub fn best_block_info(&self) -> (BlockHash, u32) {
                self.blocks.lock().unwrap().last().map(|(a, b)| (a.block_hash(), *b)).unwrap()
        }
+       pub fn get_block_header(&self, height: u32) -> BlockHeader {
+               self.blocks.lock().unwrap()[height as usize].0
+       }
 }
 
 impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
@@ -997,6 +1000,30 @@ macro_rules! expect_payment_sent {
        }
 }
 
+#[cfg(test)]
+macro_rules! expect_payment_failure_chan_update {
+       ($node: expr, $scid: expr, $chan_closed: expr) => {
+               let events = $node.node.get_and_clear_pending_msg_events();
+               assert_eq!(events.len(), 1);
+               match events[0] {
+                       MessageSendEvent::PaymentFailureNetworkUpdate { ref update } => {
+                               match update {
+                                       &HTLCFailChannelUpdate::ChannelUpdateMessage { ref msg } if !$chan_closed => {
+                                               assert_eq!(msg.contents.short_channel_id, $scid);
+                                               assert_eq!(msg.contents.flags & 2, 0);
+                                       },
+                                       &HTLCFailChannelUpdate::ChannelClosed { short_channel_id, is_permanent } if $chan_closed => {
+                                               assert_eq!(short_channel_id, $scid);
+                                               assert!(is_permanent);
+                                       },
+                                       _ => panic!("Unexpected update type"),
+                               }
+                       },
+                       _ => panic!("Unexpected event"),
+               }
+       }
+}
+
 #[cfg(test)]
 macro_rules! expect_payment_failed {
        ($node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr $(, $expected_error_code: expr, $expected_error_data: expr)*) => {