]> Untitled Git - bdk/commitdiff
populate_test_db accepts a `coinbase` param
authorDaniela Brozzoni <danielabrozzoni@protonmail.com>
Wed, 25 May 2022 17:54:40 +0000 (18:54 +0100)
committerDaniela Brozzoni <danielabrozzoni@protonmail.com>
Thu, 30 Jun 2022 09:50:15 +0000 (11:50 +0200)
Allows user to ask for a test db populated with clean coins
from coinbases. This is useful for testing the wallet behaviour
when some inputs are coinbases.

src/database/memory.rs

index 1c8d1ccace532e4822a01f7dda2ef1e04f793912..8aa8506b62f1022113bcb6fbd5b6f6e9003f0cf9 100644 (file)
@@ -486,15 +486,23 @@ impl ConfigurableDatabase for MemoryDatabase {
 /// don't have `test` set.
 macro_rules! populate_test_db {
     ($db:expr, $tx_meta:expr, $current_height:expr$(,)?) => {{
+        $crate::populate_test_db!($db, $tx_meta, $current_height, (@coinbase false))
+    }};
+    ($db:expr, $tx_meta:expr, $current_height:expr, (@coinbase $is_coinbase:expr)$(,)?) => {{
         use std::str::FromStr;
         use $crate::database::BatchOperations;
         let mut db = $db;
         let tx_meta = $tx_meta;
         let current_height: Option<u32> = $current_height;
+        let input = if $is_coinbase {
+            vec![$crate::bitcoin::TxIn::default()]
+        } else {
+            vec![]
+        };
         let tx = $crate::bitcoin::Transaction {
             version: 1,
             lock_time: 0,
-            input: vec![],
+            input,
             output: tx_meta
                 .output
                 .iter()