]> Untitled Git - bdk/commitdiff
[wallet] Add tests for BranchAndBoundCoinSelection::single_random_draw
authorDaniela Brozzoni <danielabrozzoni@protonmail.com>
Sat, 31 Oct 2020 15:28:21 +0000 (16:28 +0100)
committerDaniela Brozzoni <danielabrozzoni@protonmail.com>
Fri, 13 Nov 2020 11:42:06 +0000 (12:42 +0100)
src/wallet/coin_selection.rs

index 45bbe300db1f88eb7e10503e156d396a2be71029..54fe6875a6be1b86c9f1ec3c1e3a267d650af509 100644 (file)
@@ -987,4 +987,29 @@ mod test {
             assert_eq!(result.selected_amount, target_amount);
         }
     }
+
+    #[test]
+    fn test_single_random_draw_function_success() {
+        let seed = [0; 32];
+        let mut rng: StdRng = SeedableRng::from_seed(seed);
+        let mut utxos = generate_random_utxos(&mut rng, 300);
+        let target_amount = sum_random_utxos(&mut rng, &mut utxos);
+
+        let fee_rate = FeeRate::from_sat_per_vb(1.0);
+        let utxos: Vec<OutputGroup> = utxos
+            .into_iter()
+            .map(|u| OutputGroup::new(u.0, u.1, fee_rate))
+            .collect();
+
+        let result = BranchAndBoundCoinSelection::default().single_random_draw(
+            vec![],
+            utxos,
+            0,
+            target_amount,
+            50.0,
+        );
+
+        assert!(result.selected_amount > target_amount);
+        assert_eq!(result.fee_amount, 50.0 + result.txin.len() as f32 * 68.0);
+    }
 }