Skip to content

Commit 9cd7729

Browse files
committed
test: add tests with high iteration counts
A test with iteration count nearly the limit is added which returns a result named `coin_grinder_finds_eight_of_seventeen`. Another test is added that is the same as `..finds_eight_of_seventeen`, except this one exceeds the iteration count returning `ITERATION_LIMIT` error. Both tests crate a selection pattern that causes coin_grinder to perform a large number of combinations. To do so, an input set is created such that the lowest effective_values are greedily selected. However, all `UTXOs` with the lowest effective_value have the highest weight. The only combination of `UTXOs` that satisfy the target and have a weight less than `max_weight` are those with the highest `effective_value`. The branch and bound selection will not at last try the combination _all_ highest effective_value `UTXOs` until the end.
1 parent acb5a40 commit 9cd7729

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

src/coin_grinder.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,84 @@ mod tests {
664664
.assert();
665665
}
666666

667+
#[test]
668+
fn coin_grinder_finds_eight_of_seventeen() {
669+
TestCoinGrinder {
670+
target: "8 BTC",
671+
change_target: "0",
672+
max_weight: "3200",
673+
fee_rate: "0",
674+
weighted_utxos: &[
675+
"100000000 sats/384 wu",
676+
"100000001 sats/388 wu",
677+
"100000002 sats/392 wu",
678+
"100000003 sats/396 wu",
679+
"100000004 sats/400 wu",
680+
"100000005 sats/404 wu",
681+
"100000006 sats/408 wu",
682+
"100000007 sats/412 wu",
683+
"100000008 sats/416 wu",
684+
"100000009 sats/420 wu",
685+
"100000010 sats/424 wu",
686+
"100000011 sats/428 wu",
687+
"100000012 sats/432 wu",
688+
"100000013 sats/436 wu",
689+
"100000014 sats/440 wu",
690+
"100000015 sats/444 wu",
691+
"100000016 sats/448 wu",
692+
"100000017 sats/452 wu",
693+
],
694+
expected_utxos: &[
695+
"100000007 sats/412 wu",
696+
"100000006 sats/408 wu",
697+
"100000005 sats/404 wu",
698+
"100000004 sats/400 wu",
699+
"100000003 sats/396 wu",
700+
"100000002 sats/392 wu",
701+
"100000001 sats/388 wu",
702+
"100000000 sats/384 wu",
703+
],
704+
expected_error: None,
705+
expected_iterations: 87_525,
706+
}
707+
.assert();
708+
}
709+
710+
#[test]
711+
fn coin_grinder_exhaust_iteration_limit() {
712+
TestCoinGrinder {
713+
target: "8 BTC",
714+
change_target: "0",
715+
max_weight: "3200",
716+
fee_rate: "0",
717+
weighted_utxos: &[
718+
"100000000 sats/384 wu",
719+
"100000001 sats/388 wu",
720+
"100000002 sats/392 wu",
721+
"100000003 sats/396 wu",
722+
"100000004 sats/400 wu",
723+
"100000005 sats/404 wu",
724+
"100000006 sats/408 wu",
725+
"100000007 sats/412 wu",
726+
"100000008 sats/416 wu",
727+
"100000009 sats/420 wu",
728+
"100000010 sats/424 wu",
729+
"100000011 sats/428 wu",
730+
"100000012 sats/432 wu",
731+
"100000013 sats/436 wu",
732+
"100000014 sats/440 wu",
733+
"100000015 sats/444 wu",
734+
"100000016 sats/448 wu",
735+
"100000017 sats/452 wu",
736+
"100000018 sats/456 wu",
737+
],
738+
expected_utxos: &[],
739+
expected_error: Some(IterationLimitReached),
740+
expected_iterations: 0,
741+
}
742+
.assert();
743+
}
744+
667745
#[test]
668746
fn coin_grinder_proptest_lowest_weight_solution() {
669747
// This tests that coin-grinder will find the lowest weight solution. To do so, create two

0 commit comments

Comments
 (0)