Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yancyribbens committed Feb 23, 2024
1 parent 35ee647 commit b46e8bd
Showing 1 changed file with 78 additions and 1 deletion.
79 changes: 78 additions & 1 deletion src/branch_and_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ pub fn select_coins_bnb(
}

// Anchor the new subtree at the next available index.
//
// [4,3,2,1]

// if our index selection is: [0,1,2,3]
// then copy the head 0 into index.
// At the end of this loop, index is incremented to 1.
Expand Down Expand Up @@ -547,6 +548,82 @@ mod tests {
assert_eq!(list[3].utxo.value, Amount::from_str("1 cBTC").unwrap());
}

#[test]
fn select_coins_extended_test() {
let target = Amount::from_str("18 BTC").unwrap();

let weighted_utxos = vec![
WeightedUtxo {
satisfaction_weight: Weight::ZERO,
utxo: TxOut {
value: Amount::from_str("10 BTC").unwrap(),
script_pubkey: ScriptBuf::new(),
},
},
WeightedUtxo {
satisfaction_weight: Weight::ZERO,
utxo: TxOut {
value: Amount::from_str("7 BTC").unwrap() + Amount::from_str("5 sats").unwrap(),
script_pubkey: ScriptBuf::new(),
},
},
WeightedUtxo {
satisfaction_weight: Weight::ZERO,
utxo: TxOut {
value: Amount::from_str("6 BTC").unwrap() + Amount::from_str("5 sats").unwrap(),
script_pubkey: ScriptBuf::new(),
},
},
WeightedUtxo {
satisfaction_weight: Weight::ZERO,
utxo: TxOut {
value: Amount::from_str("6 BTC").unwrap(),
script_pubkey: ScriptBuf::new(),
},
},
WeightedUtxo {
satisfaction_weight: Weight::ZERO,
utxo: TxOut {
value: Amount::from_str("3 BTC").unwrap(),
script_pubkey: ScriptBuf::new(),
},
},
WeightedUtxo {
satisfaction_weight: Weight::ZERO,
utxo: TxOut {
value: Amount::from_str("2 BTC").unwrap(),
script_pubkey: ScriptBuf::new(),
},
},
WeightedUtxo {
satisfaction_weight: Weight::ZERO,
utxo: TxOut {
value: Amount::from_str("1 BTC").unwrap() + Amount::from_str("5 sats").unwrap(),
script_pubkey: ScriptBuf::new(),
},
}
];

let wu = weighted_utxos.clone();

let list: Vec<_> = select_coins_bnb(
target,
Amount::from_str("50 sats").unwrap(),
FeeRate::ZERO,
FeeRate::ZERO,
&wu,
)
.unwrap()
.collect();

// 6.00000005, 6, 3, 2, 1.00000005
assert_eq!(list[0].utxo.value, Amount::from_str("6 BTC").unwrap() + Amount::from_str("5 sats").unwrap());
assert_eq!(list[1].utxo.value, Amount::from_str("6 BTC").unwrap());
assert_eq!(list[2].utxo.value, Amount::from_str("3 BTC").unwrap());
assert_eq!(list[3].utxo.value, Amount::from_str("2 BTC").unwrap());
assert_eq!(list[4].utxo.value, Amount::from_str("1 BTC").unwrap() + Amount::from_str("5 sats").unwrap());
}

#[test]
fn select_coins_bnb_cost_of_change() {
let target = Amount::from_str("1 cBTC").unwrap();
Expand Down

0 comments on commit b46e8bd

Please sign in to comment.