Merge pull request #1972 from jkczyz/2023-01-bolt12-spec-updates
[rust-lightning] / lightning / src / ln / functional_test_utils.rs
index 3fbf1bb5f86d1cd8a2852c13936e57c9333031f2..868b38e3fdaf30d44b766286ca280208a4d36d9d 100644 (file)
@@ -61,17 +61,22 @@ pub fn confirm_transaction<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Tran
        connect_blocks(node, CHAN_CONFIRM_DEPTH - 1);
        scid
 }
-/// Mine a signle block containing the given transaction
+/// Mine a single block containing the given transaction
 pub fn mine_transaction<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction) {
        let height = node.best_block_info().1 + 1;
        confirm_transaction_at(node, tx, height);
 }
+/// Mine a single block containing the given transactions
+pub fn mine_transactions<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, txn: &[&Transaction]) {
+       let height = node.best_block_info().1 + 1;
+       confirm_transactions_at(node, txn, height);
+}
 /// Mine the given transaction at the given height, mining blocks as required to build to that
 /// height
 ///
 /// Returns the SCID a channel confirmed in the given transaction will have, assuming the funding
 /// output is the 1st output in the transaction.
-pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction, conf_height: u32) -> u64 {
+pub fn confirm_transactions_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, txn: &[&Transaction], conf_height: u32) -> u64 {
        let first_connect_height = node.best_block_info().1 + 1;
        assert!(first_connect_height <= conf_height);
        if conf_height > first_connect_height {
@@ -84,10 +89,15 @@ pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &T
        for _ in 0..*node.network_chan_count.borrow() { // Make sure we don't end up with channels at the same short id by offsetting by chan_count
                block.txdata.push(Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() });
        }
-       block.txdata.push(tx.clone());
+       for tx in txn {
+               block.txdata.push((*tx).clone());
+       }
        connect_block(node, &block);
        scid_utils::scid_from_parts(conf_height as u64, block.txdata.len() as u64 - 1, 0).unwrap()
 }
+pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &Transaction, conf_height: u32) -> u64 {
+       confirm_transactions_at(node, &[tx], conf_height)
+}
 
 /// The possible ways we may notify a ChannelManager of a new block
 #[derive(Clone, Copy, Debug, PartialEq)]
@@ -1437,6 +1447,11 @@ macro_rules! get_payment_preimage_hash {
                }
        };
        ($dest_node: expr, $min_value_msat: expr) => {
+               {
+                       crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
+               }
+       };
+       ($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
                {
                        use bitcoin::hashes::Hash as _;
                        let mut payment_count = $dest_node.network_payment_count.borrow_mut();
@@ -1444,10 +1459,10 @@ macro_rules! get_payment_preimage_hash {
                        *payment_count += 1;
                        let payment_hash = $crate::ln::PaymentHash(
                                bitcoin::hashes::sha256::Hash::hash(&payment_preimage.0[..]).into_inner());
-                       let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, $min_value_msat, 7200).unwrap();
+                       let payment_secret = $dest_node.node.create_inbound_payment_for_hash(payment_hash, $min_value_msat, 7200, $min_final_cltv_expiry_delta).unwrap();
                        (payment_preimage, payment_hash, payment_secret)
                }
-       }
+       };
 }
 
 #[macro_export]