]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Test that txn pay at least a minimum relay fee in functional tests 2020-03-fee-missing
authorMatt Corallo <git@bluematt.me>
Mon, 2 Mar 2020 16:44:11 +0000 (11:44 -0500)
committerMatt Corallo <git@bluematt.me>
Thu, 5 Mar 2020 16:25:07 +0000 (11:25 -0500)
lightning/src/ln/functional_test_utils.rs

index 489647dcfa094764883d9ee2adfb106226afbf4c..99f56b14352b6609aee54adaa1252031686e91b8 100644 (file)
@@ -405,14 +405,25 @@ pub fn create_announced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &'a
 macro_rules! check_spends {
        ($tx: expr, $($spends_txn: expr),*) => {
                {
-                       $tx.verify(|out_point| {
+                       let get_output = |out_point: &bitcoin::blockdata::transaction::OutPoint| {
                                $(
                                        if out_point.txid == $spends_txn.txid() {
                                                return $spends_txn.output.get(out_point.vout as usize).cloned()
                                        }
                                )*
                                None
-                       }).unwrap();
+                       };
+                       let mut total_value_in = 0;
+                       for input in $tx.input.iter() {
+                               total_value_in += get_output(&input.previous_output).unwrap().value;
+                       }
+                       let mut total_value_out = 0;
+                       for output in $tx.output.iter() {
+                               total_value_out += output.value;
+                       }
+                       let min_fee = $tx.get_weight() as u64 / 4; // One sat per vbyte
+                       assert!(total_value_out + min_fee <= total_value_in); // Must not be equal as there must be a fee!
+                       $tx.verify(get_output).unwrap();
                }
        }
 }