]> Untitled Git - bdk/commitdiff
test: fix populate_test_db conf calculation
authorDaniela Brozzoni <danielabrozzoni@protonmail.com>
Fri, 1 Jul 2022 08:56:48 +0000 (10:56 +0200)
committerDaniela Brozzoni <danielabrozzoni@protonmail.com>
Wed, 6 Jul 2022 10:48:18 +0000 (12:48 +0200)
populate_test_db would previously give back a transaction with N + 1
confirmations when you asked for N.

This commit also fixes test_spend_coinbase, which would improperly
ask for a transaction with 0 confirmations instead of 1.

src/database/memory.rs
src/wallet/mod.rs

index cc56c94db92ec65e5793fcb22e01ddb08e91382d..7d806eb4af24455b43810912998d1595c39d2a02 100644 (file)
@@ -512,10 +512,13 @@ macro_rules! populate_test_db {
         };
 
         let txid = tx.txid();
-        let confirmation_time = tx_meta.min_confirmations.map(|conf| $crate::BlockTime {
-            height: current_height.unwrap().checked_sub(conf as u32).unwrap(),
-            timestamp: 0,
-        });
+        let confirmation_time = tx_meta
+            .min_confirmations
+            .and_then(|v| if v == 0 { None } else { Some(v) })
+            .map(|conf| $crate::BlockTime {
+                height: current_height.unwrap().checked_sub(conf as u32).unwrap() + 1,
+                timestamp: 0,
+            });
 
         let tx_details = $crate::TransactionDetails {
             transaction: Some(tx.clone()),
index 213cc60d15b45fb93e7797976a9de03d18f9a491..36cc162282aad7d8e6de1ab019b198911ec0309b 100644 (file)
@@ -4723,7 +4723,7 @@ pub(crate) mod test {
 
         crate::populate_test_db!(
             wallet.database.borrow_mut(),
-            testutils! (@tx ( (@external descriptors, 0) => 25_000 ) (@confirmations 0)),
+            testutils! (@tx ( (@external descriptors, 0) => 25_000 ) (@confirmations 1)),
             Some(confirmation_time),
             (@coinbase true)
         );