Branch and bound coin selection tests
| 184 | |
| 185 | // Branch and bound coin selection tests |
| 186 | BOOST_AUTO_TEST_CASE(bnb_search_test) |
| 187 | { |
| 188 | // Setup |
| 189 | std::vector<CInputCoin> utxo_pool; |
| 190 | SelectionResult expected_result(CAmountMap{{::policyAsset, 0}}); |
| 191 | |
| 192 | ///////////////////////// |
| 193 | // Known Outcome tests // |
| 194 | ///////////////////////// |
| 195 | |
| 196 | // Empty utxo pool |
| 197 | BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 1 * CENT, 0.5 * CENT)); |
| 198 | |
| 199 | // Add utxos |
| 200 | add_coin(1 * CENT, 1, utxo_pool); |
| 201 | add_coin(2 * CENT, 2, utxo_pool); |
| 202 | add_coin(3 * CENT, 3, utxo_pool); |
| 203 | add_coin(4 * CENT, 4, utxo_pool); |
| 204 | |
| 205 | // Select 1 Cent |
| 206 | add_coin(1 * CENT, 1, expected_result); |
| 207 | const auto result1 = SelectCoinsBnB(GroupCoins(utxo_pool), 1 * CENT, 0.5 * CENT); |
| 208 | BOOST_CHECK(result1); |
| 209 | BOOST_CHECK(EquivalentResult(expected_result, *result1)); |
| 210 | BOOST_CHECK_EQUAL(result1->GetSelectedValue()[::policyAsset], 1 * CENT); |
| 211 | expected_result.Clear(); |
| 212 | |
| 213 | // Select 2 Cent |
| 214 | add_coin(2 * CENT, 2, expected_result); |
| 215 | const auto result2 = SelectCoinsBnB(GroupCoins(utxo_pool), 2 * CENT, 0.5 * CENT); |
| 216 | BOOST_CHECK(result2); |
| 217 | BOOST_CHECK(EquivalentResult(expected_result, *result2)); |
| 218 | BOOST_CHECK_EQUAL(result2->GetSelectedValue()[::policyAsset], 2 * CENT); |
| 219 | expected_result.Clear(); |
| 220 | |
| 221 | // Select 5 Cent |
| 222 | add_coin(4 * CENT, 4, expected_result); |
| 223 | add_coin(1 * CENT, 1, expected_result); |
| 224 | const auto result3 = SelectCoinsBnB(GroupCoins(utxo_pool), 5 * CENT, 0.5 * CENT); |
| 225 | BOOST_CHECK(result3); |
| 226 | BOOST_CHECK(EquivalentResult(expected_result, *result3)); |
| 227 | BOOST_CHECK_EQUAL(result3->GetSelectedValue()[::policyAsset], 5 * CENT); |
| 228 | expected_result.Clear(); |
| 229 | |
| 230 | // Select 11 Cent, not possible |
| 231 | BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 11 * CENT, 0.5 * CENT)); |
| 232 | expected_result.Clear(); |
| 233 | |
| 234 | // Cost of change is greater than the difference between target value and utxo sum |
| 235 | add_coin(1 * CENT, 1, expected_result); |
| 236 | const auto result4 = SelectCoinsBnB(GroupCoins(utxo_pool), 0.9 * CENT, 0.5 * CENT); |
| 237 | BOOST_CHECK(result4); |
| 238 | BOOST_CHECK_EQUAL(result4->GetSelectedValue()[::policyAsset], 1 * CENT); |
| 239 | BOOST_CHECK(EquivalentResult(expected_result, *result4)); |
| 240 | expected_result.Clear(); |
| 241 | |
| 242 | // Cost of change is less than the difference between target value and utxo sum |
| 243 | BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 0.9 * CENT, 0)); |
nothing calls this directly
no test coverage detected