p2pderivatives / rust-bitcoin-coin-selection

10 stars 5 forks source link

BNB/SRD consolidate common tests with a helper function #41

Open yancyribbens opened 7 months ago

yancyribbens commented 7 months ago

Comment from https://github.com/p2pderivatives/rust-bitcoin-coin-selection/pull/30

   fn select_coins_bnb_given_target(target_str, expected_inputs) {
        let target = Amount::from_str(target_str).unwrap();
        let mut weighted_utxos = create_weighted_utxos(Amount::ZERO);

        let inputs: Vec<_> = select_coins_bnb(
            target,
            Amount::ZERO,
            FeeRate::ZERO,
            FeeRate::ZERO,
            &mut weighted_utxos,
        )
        .unwrap()
        .collect();

        assert_eq!(inputs.len(), expected_inputs.len());
        inputs.sort();
        expected_inputs.sort()
        for i in 0..inputs.len() -1 {
            assert_eq!(inputs[i].utxo.value, Amount::from_str(expected_inputs[i]).unwrap());
        }
    }

# one
select_coins_bnb_given_target("1 cBTC", ["1 cBTC"]);
# two
…
# five
select_coins_bnb_given_target("5 cBTC", ["3 cBTC", "2 cBTC"]);
# six
select_coins_bnb_given_target("6 cBTC", ["3 cBTC", "2 cBTC", "1 cBTC"]);
# seven
…
select_coins_bnb_given_target("10 cBTC", ["4 cBTC", "3 cBTC", "2 cBTC", "1 cBTC"]);