@@ -31,12 +31,14 @@ typedef std::set<CInputCoin> CoinSet;
31
31
static const CoinEligibilityFilter filter_standard (1 , 6 , 0 );
32
32
static const CoinEligibilityFilter filter_confirmed (1 , 1 , 0 );
33
33
static const CoinEligibilityFilter filter_standard_extra (6 , 6 , 0 );
34
+ static int nextLockTime = 0 ;
34
35
35
36
static void add_coin (const CAmount& nValue, int nInput, std::vector<CInputCoin>& set)
36
37
{
37
38
CMutableTransaction tx;
38
39
tx.vout .resize (nInput + 1 );
39
40
tx.vout [nInput].nValue = nValue;
41
+ tx.nLockTime = nextLockTime++; // so all transactions get different hashes
40
42
set.emplace_back (MakeTransactionRef (tx), nInput);
41
43
}
42
44
@@ -45,6 +47,7 @@ static void add_coin(const CAmount& nValue, int nInput, CoinSet& set, CAmount fe
45
47
CMutableTransaction tx;
46
48
tx.vout .resize (nInput + 1 );
47
49
tx.vout [nInput].nValue = nValue;
50
+ tx.nLockTime = nextLockTime++; // so all transactions get different hashes
48
51
CInputCoin coin (MakeTransactionRef (tx), nInput);
49
52
coin.effective_value = nValue - fee;
50
53
coin.m_fee = fee;
@@ -54,7 +57,6 @@ static void add_coin(const CAmount& nValue, int nInput, CoinSet& set, CAmount fe
54
57
55
58
static void add_coin (std::vector<COutput>& coins, CWallet& wallet, const CAmount& nValue, int nAge = 6 *24 , bool fIsFromMe = false , int nInput=0 , bool spendable = false )
56
59
{
57
- static int nextLockTime = 0 ;
58
60
CMutableTransaction tx;
59
61
tx.nLockTime = nextLockTime++; // so all transactions get different hashes
60
62
tx.vout .resize (nInput + 1 );
@@ -81,6 +83,23 @@ static void add_coin(std::vector<COutput>& coins, CWallet& wallet, const CAmount
81
83
coins.push_back (output);
82
84
}
83
85
86
+ static bool equivalent_sets (CoinSet a, CoinSet b)
87
+ {
88
+ std::vector<CAmount> a_amts;
89
+ std::vector<CAmount> b_amts;
90
+ for (const auto & coin : a) {
91
+ a_amts.push_back (coin.txout .nValue );
92
+ }
93
+ for (const auto & coin : b) {
94
+ b_amts.push_back (coin.txout .nValue );
95
+ }
96
+ std::sort (a_amts.begin (), a_amts.end ());
97
+ std::sort (b_amts.begin (), b_amts.end ());
98
+
99
+ std::pair<std::vector<CAmount>::iterator, std::vector<CAmount>::iterator> ret = mismatch (a_amts.begin (), a_amts.end (), b_amts.begin ());
100
+ return ret.first == a_amts.end () && ret.second == b_amts.end ();
101
+ }
102
+
84
103
static bool equal_sets (CoinSet a, CoinSet b)
85
104
{
86
105
std::pair<CoinSet::iterator, CoinSet::iterator> ret = mismatch (a.begin (), a.end (), b.begin ());
@@ -158,15 +177,15 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
158
177
// Select 1 Cent
159
178
add_coin (1 * CENT, 1 , actual_selection);
160
179
BOOST_CHECK (SelectCoinsBnB (GroupCoins (utxo_pool), 1 * CENT, 0.5 * CENT, selection, value_ret));
161
- BOOST_CHECK (equal_sets (selection, actual_selection));
180
+ BOOST_CHECK (equivalent_sets (selection, actual_selection));
162
181
BOOST_CHECK_EQUAL (value_ret, 1 * CENT);
163
182
actual_selection.clear ();
164
183
selection.clear ();
165
184
166
185
// Select 2 Cent
167
186
add_coin (2 * CENT, 2 , actual_selection);
168
187
BOOST_CHECK (SelectCoinsBnB (GroupCoins (utxo_pool), 2 * CENT, 0.5 * CENT, selection, value_ret));
169
- BOOST_CHECK (equal_sets (selection, actual_selection));
188
+ BOOST_CHECK (equivalent_sets (selection, actual_selection));
170
189
BOOST_CHECK_EQUAL (value_ret, 2 * CENT);
171
190
actual_selection.clear ();
172
191
selection.clear ();
@@ -175,7 +194,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
175
194
add_coin (4 * CENT, 4 , actual_selection);
176
195
add_coin (1 * CENT, 1 , actual_selection);
177
196
BOOST_CHECK (SelectCoinsBnB (GroupCoins (utxo_pool), 5 * CENT, 0.5 * CENT, selection, value_ret));
178
- BOOST_CHECK (equal_sets (selection, actual_selection));
197
+ BOOST_CHECK (equivalent_sets (selection, actual_selection));
179
198
BOOST_CHECK_EQUAL (value_ret, 5 * CENT);
180
199
actual_selection.clear ();
181
200
selection.clear ();
@@ -189,7 +208,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
189
208
add_coin (1 * CENT, 1 , actual_selection);
190
209
BOOST_CHECK (SelectCoinsBnB (GroupCoins (utxo_pool), 0.9 * CENT, 0.5 * CENT, selection, value_ret));
191
210
BOOST_CHECK_EQUAL (value_ret, 1 * CENT);
192
- BOOST_CHECK (equal_sets (selection, actual_selection));
211
+ BOOST_CHECK (equivalent_sets (selection, actual_selection));
193
212
actual_selection.clear ();
194
213
selection.clear ();
195
214
@@ -204,7 +223,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
204
223
add_coin (4 * CENT, 4 , actual_selection);
205
224
add_coin (1 * CENT, 1 , actual_selection);
206
225
BOOST_CHECK (SelectCoinsBnB (GroupCoins (utxo_pool), 10 * CENT, 0.5 * CENT, selection, value_ret));
207
- BOOST_CHECK (equal_sets (selection, actual_selection));
226
+ BOOST_CHECK (equivalent_sets (selection, actual_selection));
208
227
BOOST_CHECK_EQUAL (value_ret, 10 * CENT);
209
228
actual_selection.clear ();
210
229
selection.clear ();
@@ -217,7 +236,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
217
236
BOOST_CHECK (SelectCoinsBnB (GroupCoins (utxo_pool), 10 * CENT, 5000 , selection, value_ret));
218
237
BOOST_CHECK_EQUAL (value_ret, 10 * CENT);
219
238
// FIXME: this test is redundant with the above, because 1 Cent is selected, not "too small"
220
- // BOOST_CHECK(equal_sets (selection, actual_selection));
239
+ // BOOST_CHECK(equivalent_sets (selection, actual_selection));
221
240
222
241
// Select 0.25 Cent, not possible
223
242
BOOST_CHECK (!SelectCoinsBnB (GroupCoins (utxo_pool), 0.25 * CENT, 0.5 * CENT, selection, value_ret));
@@ -247,7 +266,7 @@ BOOST_AUTO_TEST_CASE(bnb_search_test)
247
266
}
248
267
BOOST_CHECK (SelectCoinsBnB (GroupCoins (utxo_pool), 30 * CENT, 5000 , selection, value_ret));
249
268
BOOST_CHECK_EQUAL (value_ret, 30 * CENT);
250
- BOOST_CHECK (equal_sets (selection, actual_selection));
269
+ BOOST_CHECK (equivalent_sets (selection, actual_selection));
251
270
252
271
// //////////////////
253
272
// Behavior tests //
0 commit comments