Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
yancyribbens committed Mar 20, 2024
1 parent 76954ba commit 6ee8dfe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
47 changes: 19 additions & 28 deletions src/branch_and_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,10 @@ mod tests {
let output =
TxOut { value: Amount::from_str("1 cBTC").unwrap(), script_pubkey: ScriptBuf::new() };

eff_values.iter().map(|e|
Coin {
utxo: output.clone(),
effective_value: *e,
waste: SignedAmount::ZERO
}
).collect()
eff_values
.iter()
.map(|e| Coin { utxo: output.clone(), effective_value: *e, waste: SignedAmount::ZERO })
.collect()
}

fn create_coin_with_waste(waste: SignedAmount) -> Vec<Coin> {
Expand All @@ -330,25 +327,25 @@ mod tests {
let coin_one = Coin {
utxo: output.clone(),
effective_value: Amount::from_str("1 cBTC").unwrap(),
waste
waste,
};

let coin_two = Coin {
utxo: output.clone(),
effective_value: Amount::from_str("2 cBTC").unwrap(),
waste
waste,
};

let coin_three = Coin {
utxo: output.clone(),
effective_value: Amount::from_str("3 cBTC").unwrap(),
waste
waste,
};

let coin_four = Coin {
utxo: output.clone(),
effective_value: Amount::from_str("4 cBTC").unwrap(),
waste
waste,
};

vec![coin_one, coin_two, coin_three, coin_four]
Expand Down Expand Up @@ -376,7 +373,7 @@ mod tests {
}

#[test]
fn select_coins_bnb_one() {
fn select_coins_bnb_one() {
let target = Amount::from_str("1 cBTC").unwrap();
let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO);

Expand Down Expand Up @@ -556,8 +553,7 @@ mod tests {
let target = Amount::from_str("11 cBTC").unwrap();
let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO);

let list =
select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, FeeRate::ZERO, &coin);
let list = select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, FeeRate::ZERO, &coin);
assert!(list.is_none());
}

Expand All @@ -574,9 +570,7 @@ mod tests {
// the possible combinations are 2,4 or 1,2,3
// fees are cheap, so use 1,2,3
let list: Vec<_> =
select_coins_bnb(target, Amount::ZERO, fee_rate, lt_fee_rate, &coin)
.unwrap()
.collect();
select_coins_bnb(target, Amount::ZERO, fee_rate, lt_fee_rate, &coin).unwrap().collect();

assert_eq!(list.len(), 3);
assert_eq!(list[0].effective_value, Amount::from_str("3 cBTC").unwrap());
Expand All @@ -597,9 +591,7 @@ mod tests {
// the possible combinations are 2,4 or 1,2,3
// fees are expensive, so use 2,4
let list: Vec<_> =
select_coins_bnb(target, Amount::ZERO, fee_rate, lt_fee_rate, &coin)
.unwrap()
.collect();
select_coins_bnb(target, Amount::ZERO, fee_rate, lt_fee_rate, &coin).unwrap().collect();

assert_eq!(list.len(), 2);
assert_eq!(list[0].effective_value, Amount::from_str("4 cBTC").unwrap());
Expand All @@ -612,15 +604,15 @@ mod tests {
let satisfaction_weight = Weight::from_wu(204);
let value = SignedAmount::MAX.to_unsigned().unwrap();

let tx_out =
TxOut { value, script_pubkey: ScriptBuf::new() };
let coin_one = Coin::new(tx_out.clone(), FeeRate::ZERO, FeeRate::ZERO, Weight::ZERO).unwrap();
let coin_two = Coin::new(tx_out.clone(), FeeRate::ZERO, FeeRate::ZERO, Weight::ZERO).unwrap();
let tx_out = TxOut { value, script_pubkey: ScriptBuf::new() };
let coin_one =
Coin::new(tx_out.clone(), FeeRate::ZERO, FeeRate::ZERO, Weight::ZERO).unwrap();
let coin_two =
Coin::new(tx_out.clone(), FeeRate::ZERO, FeeRate::ZERO, Weight::ZERO).unwrap();

let coins = &[coin_one, coin_two];

let list =
select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, FeeRate::ZERO, coins);
let list = select_coins_bnb(target, Amount::ZERO, FeeRate::ZERO, FeeRate::ZERO, coins);
assert!(list.is_none());
}

Expand All @@ -632,8 +624,7 @@ mod tests {
let cost_of_change = Amount::MAX;
let coin = create_coin(FeeRate::ZERO, FeeRate::ZERO);

let list =
select_coins_bnb(target, cost_of_change, FeeRate::ZERO, FeeRate::ZERO, &coin);
let list = select_coins_bnb(target, cost_of_change, FeeRate::ZERO, FeeRate::ZERO, &coin);
assert!(list.is_none());
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ mod tests {

// effective_vale = value - fee
// fee = satisfaction_weight + base_weight * fee_rate
//
// effective_value = 46 sats - (204 wu + 160 wu) * 10 sat/kwu = 42 sats
//
// effective_value = 46 sats - (204 wu + 160 wu) * 10 sat/kwu = 42 sats
assert_eq!(coin.effective_value, Amount::from_str("42 sats").unwrap());

// waste = fee - long term fee
// waste = (fee_rate * weight) - (lt_fee_fee_rate * weight)
// = (10 sat/kwu * (204 wu + 160 wu)) - (15 sat/kwu * (204 wu + 160 wu))
// = (10 sat/kwu * (204 wu + 160 wu)) - (15 sat/kwu * (204 wu + 160 wu))
// waste = -2 sats
assert_eq!(coin.waste, SignedAmount::from_str("-2 sats").unwrap());

assert_eq!(coin.utxo, tx_out);
}

Expand Down

0 comments on commit 6ee8dfe

Please sign in to comment.