Skip to content

Commit a339add

Browse files
committed
Make member variables of SelectionResult private
1 parent cbf0b9f commit a339add

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

src/wallet/coinselection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ struct OutputGroup
199199

200200
struct SelectionResult
201201
{
202+
private:
202203
/** Set of inputs selected by the algorithm to use in the transaction */
203204
std::set<CInputCoin> m_selected_inputs;
204205
/** The target the algorithm selected for. Note that this may not be equal to the recipient amount as it can include non-input fees */
@@ -208,6 +209,7 @@ struct SelectionResult
208209
/** The computed waste */
209210
std::optional<CAmount> m_waste;
210211

212+
public:
211213
explicit SelectionResult(const CAmount target)
212214
: m_target(target) {}
213215

src/wallet/test/coinselector_tests.cpp

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ static void add_coin(const CAmount& nValue, int nInput, std::vector<CInputCoin>&
4242
set.emplace_back(MakeTransactionRef(tx), nInput);
4343
}
4444

45+
static void add_coin(const CAmount& nValue, int nInput, SelectionResult& result)
46+
{
47+
CMutableTransaction tx;
48+
tx.vout.resize(nInput + 1);
49+
tx.vout[nInput].nValue = nValue;
50+
tx.nLockTime = nextLockTime++; // so all transactions get different hashes
51+
CInputCoin coin(MakeTransactionRef(tx), nInput);
52+
OutputGroup group;
53+
group.Insert(coin, 1, false, 0, 0, true);
54+
result.AddInput(group);
55+
}
56+
4557
static void add_coin(const CAmount& nValue, int nInput, CoinSet& set, CAmount fee = 0, CAmount long_term_fee = 0)
4658
{
4759
CMutableTransaction tx;
@@ -175,26 +187,26 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
175187
add_coin(4 * CENT, 4, utxo_pool);
176188

177189
// Select 1 Cent
178-
add_coin(1 * CENT, 1, expected_result.m_selected_inputs);
190+
add_coin(1 * CENT, 1, expected_result);
179191
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 1 * CENT, 0.5 * CENT, selection, value_ret));
180-
BOOST_CHECK(equivalent_sets(selection, expected_result.m_selected_inputs));
192+
BOOST_CHECK(equivalent_sets(selection, expected_result.GetInputSet()));
181193
BOOST_CHECK_EQUAL(value_ret, 1 * CENT);
182194
expected_result.Clear();
183195
selection.clear();
184196

185197
// Select 2 Cent
186-
add_coin(2 * CENT, 2, expected_result.m_selected_inputs);
198+
add_coin(2 * CENT, 2, expected_result);
187199
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 2 * CENT, 0.5 * CENT, selection, value_ret));
188-
BOOST_CHECK(equivalent_sets(selection, expected_result.m_selected_inputs));
200+
BOOST_CHECK(equivalent_sets(selection, expected_result.GetInputSet()));
189201
BOOST_CHECK_EQUAL(value_ret, 2 * CENT);
190202
expected_result.Clear();
191203
selection.clear();
192204

193205
// Select 5 Cent
194-
add_coin(4 * CENT, 4, expected_result.m_selected_inputs);
195-
add_coin(1 * CENT, 1, expected_result.m_selected_inputs);
206+
add_coin(4 * CENT, 4, expected_result);
207+
add_coin(1 * CENT, 1, expected_result);
196208
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 5 * CENT, 0.5 * CENT, selection, value_ret));
197-
BOOST_CHECK(equivalent_sets(selection, expected_result.m_selected_inputs));
209+
BOOST_CHECK(equivalent_sets(selection, expected_result.GetInputSet()));
198210
BOOST_CHECK_EQUAL(value_ret, 5 * CENT);
199211
expected_result.Clear();
200212
selection.clear();
@@ -205,10 +217,10 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
205217
selection.clear();
206218

207219
// Cost of change is greater than the difference between target value and utxo sum
208-
add_coin(1 * CENT, 1, expected_result.m_selected_inputs);
220+
add_coin(1 * CENT, 1, expected_result);
209221
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 0.9 * CENT, 0.5 * CENT, selection, value_ret));
210222
BOOST_CHECK_EQUAL(value_ret, 1 * CENT);
211-
BOOST_CHECK(equivalent_sets(selection, expected_result.m_selected_inputs));
223+
BOOST_CHECK(equivalent_sets(selection, expected_result.GetInputSet()));
212224
expected_result.Clear();
213225
selection.clear();
214226

@@ -219,24 +231,24 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
219231

220232
// Select 10 Cent
221233
add_coin(5 * CENT, 5, utxo_pool);
222-
add_coin(5 * CENT, 5, expected_result.m_selected_inputs);
223-
add_coin(4 * CENT, 4, expected_result.m_selected_inputs);
224-
add_coin(1 * CENT, 1, expected_result.m_selected_inputs);
234+
add_coin(5 * CENT, 5, expected_result);
235+
add_coin(4 * CENT, 4, expected_result);
236+
add_coin(1 * CENT, 1, expected_result);
225237
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 10 * CENT, 0.5 * CENT, selection, value_ret));
226-
BOOST_CHECK(equivalent_sets(selection, expected_result.m_selected_inputs));
238+
BOOST_CHECK(equivalent_sets(selection, expected_result.GetInputSet()));
227239
BOOST_CHECK_EQUAL(value_ret, 10 * CENT);
228240
expected_result.Clear();
229241
selection.clear();
230242

231243
// Negative effective value
232244
// Select 10 Cent but have 1 Cent not be possible because too small
233-
add_coin(5 * CENT, 5, expected_result.m_selected_inputs);
234-
add_coin(3 * CENT, 3, expected_result.m_selected_inputs);
235-
add_coin(2 * CENT, 2, expected_result.m_selected_inputs);
245+
add_coin(5 * CENT, 5, expected_result);
246+
add_coin(3 * CENT, 3, expected_result);
247+
add_coin(2 * CENT, 2, expected_result);
236248
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 10 * CENT, 5000, selection, value_ret));
237249
BOOST_CHECK_EQUAL(value_ret, 10 * CENT);
238250
// FIXME: this test is redundant with the above, because 1 Cent is selected, not "too small"
239-
// BOOST_CHECK(equivalent_sets(selection, expected_result.m_selected_inputs));
251+
// BOOST_CHECK(equivalent_sets(selection, expected_result.GetInputSet()));
240252

241253
// Select 0.25 Cent, not possible
242254
BOOST_CHECK(!SelectCoinsBnB(GroupCoins(utxo_pool), 0.25 * CENT, 0.5 * CENT, selection, value_ret));
@@ -251,11 +263,11 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
251263

252264
// Test same value early bailout optimization
253265
utxo_pool.clear();
254-
add_coin(7 * CENT, 7, expected_result.m_selected_inputs);
255-
add_coin(7 * CENT, 7, expected_result.m_selected_inputs);
256-
add_coin(7 * CENT, 7, expected_result.m_selected_inputs);
257-
add_coin(7 * CENT, 7, expected_result.m_selected_inputs);
258-
add_coin(2 * CENT, 7, expected_result.m_selected_inputs);
266+
add_coin(7 * CENT, 7, expected_result);
267+
add_coin(7 * CENT, 7, expected_result);
268+
add_coin(7 * CENT, 7, expected_result);
269+
add_coin(7 * CENT, 7, expected_result);
270+
add_coin(2 * CENT, 7, expected_result);
259271
add_coin(7 * CENT, 7, utxo_pool);
260272
add_coin(7 * CENT, 7, utxo_pool);
261273
add_coin(7 * CENT, 7, utxo_pool);
@@ -266,7 +278,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
266278
}
267279
BOOST_CHECK(SelectCoinsBnB(GroupCoins(utxo_pool), 30 * CENT, 5000, selection, value_ret));
268280
BOOST_CHECK_EQUAL(value_ret, 30 * CENT);
269-
BOOST_CHECK(equivalent_sets(selection, expected_result.m_selected_inputs));
281+
BOOST_CHECK(equivalent_sets(selection, expected_result.GetInputSet()));
270282

271283
////////////////////
272284
// Behavior tests //

0 commit comments

Comments
 (0)