@@ -74,6 +74,10 @@ static bool equal_sets(CoinSet a, CoinSet b)
74
74
return ret.first == a.end () && ret.second == b.end ();
75
75
}
76
76
77
+ CoinEligibilityFilter filter_standard (1 , 6 , 0 );
78
+ CoinEligibilityFilter filter_confirmed (1 , 1 , 0 );
79
+ CoinEligibilityFilter filter_standard_extra (6 , 6 , 0 );
80
+
77
81
BOOST_AUTO_TEST_CASE (coin_selection_tests)
78
82
{
79
83
CoinSet setCoinsRet, setCoinsRet2;
@@ -87,24 +91,24 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
87
91
empty_wallet ();
88
92
89
93
// with an empty wallet we can't even pay one cent
90
- BOOST_CHECK (!testWallet.SelectCoinsMinConf ( 1 * CENT, 1 , 6 , 0 , vCoins, setCoinsRet, nValueRet));
94
+ BOOST_CHECK (!testWallet.SelectCoinsMinConf ( 1 * CENT, filter_standard , vCoins, setCoinsRet, nValueRet));
91
95
92
96
add_coin (1 *CENT, 4 ); // add a new 1 cent coin
93
97
94
98
// with a new 1 cent coin, we still can't find a mature 1 cent
95
- BOOST_CHECK (!testWallet.SelectCoinsMinConf ( 1 * CENT, 1 , 6 , 0 , vCoins, setCoinsRet, nValueRet));
99
+ BOOST_CHECK (!testWallet.SelectCoinsMinConf ( 1 * CENT, filter_standard , vCoins, setCoinsRet, nValueRet));
96
100
97
101
// but we can find a new 1 cent
98
- BOOST_CHECK ( testWallet.SelectCoinsMinConf ( 1 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
102
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf ( 1 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
99
103
BOOST_CHECK_EQUAL (nValueRet, 1 * CENT);
100
104
101
105
add_coin (2 *CENT); // add a mature 2 cent coin
102
106
103
107
// we can't make 3 cents of mature coins
104
- BOOST_CHECK (!testWallet.SelectCoinsMinConf ( 3 * CENT, 1 , 6 , 0 , vCoins, setCoinsRet, nValueRet));
108
+ BOOST_CHECK (!testWallet.SelectCoinsMinConf ( 3 * CENT, filter_standard , vCoins, setCoinsRet, nValueRet));
105
109
106
110
// we can make 3 cents of new coins
107
- BOOST_CHECK ( testWallet.SelectCoinsMinConf ( 3 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
111
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf ( 3 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
108
112
BOOST_CHECK_EQUAL (nValueRet, 3 * CENT);
109
113
110
114
add_coin (5 *CENT); // add a mature 5 cent coin,
@@ -114,33 +118,33 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
114
118
// now we have new: 1+10=11 (of which 10 was self-sent), and mature: 2+5+20=27. total = 38
115
119
116
120
// we can't make 38 cents only if we disallow new coins:
117
- BOOST_CHECK (!testWallet.SelectCoinsMinConf (38 * CENT, 1 , 6 , 0 , vCoins, setCoinsRet, nValueRet));
121
+ BOOST_CHECK (!testWallet.SelectCoinsMinConf (38 * CENT, filter_standard , vCoins, setCoinsRet, nValueRet));
118
122
// we can't even make 37 cents if we don't allow new coins even if they're from us
119
- BOOST_CHECK (!testWallet.SelectCoinsMinConf (38 * CENT, 6 , 6 , 0 , vCoins, setCoinsRet, nValueRet));
123
+ BOOST_CHECK (!testWallet.SelectCoinsMinConf (38 * CENT, filter_standard_extra , vCoins, setCoinsRet, nValueRet));
120
124
// but we can make 37 cents if we accept new coins from ourself
121
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (37 * CENT, 1 , 6 , 0 , vCoins, setCoinsRet, nValueRet));
125
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (37 * CENT, filter_standard , vCoins, setCoinsRet, nValueRet));
122
126
BOOST_CHECK_EQUAL (nValueRet, 37 * CENT);
123
127
// and we can make 38 cents if we accept all new coins
124
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (38 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
128
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (38 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
125
129
BOOST_CHECK_EQUAL (nValueRet, 38 * CENT);
126
130
127
131
// try making 34 cents from 1,2,5,10,20 - we can't do it exactly
128
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (34 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
132
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (34 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
129
133
BOOST_CHECK_EQUAL (nValueRet, 35 * CENT); // but 35 cents is closest
130
134
BOOST_CHECK_EQUAL (setCoinsRet.size (), 3U ); // the best should be 20+10+5. it's incredibly unlikely the 1 or 2 got included (but possible)
131
135
132
136
// when we try making 7 cents, the smaller coins (1,2,5) are enough. We should see just 2+5
133
- BOOST_CHECK ( testWallet.SelectCoinsMinConf ( 7 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
137
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf ( 7 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
134
138
BOOST_CHECK_EQUAL (nValueRet, 7 * CENT);
135
139
BOOST_CHECK_EQUAL (setCoinsRet.size (), 2U );
136
140
137
141
// when we try making 8 cents, the smaller coins (1,2,5) are exactly enough.
138
- BOOST_CHECK ( testWallet.SelectCoinsMinConf ( 8 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
142
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf ( 8 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
139
143
BOOST_CHECK (nValueRet == 8 * CENT);
140
144
BOOST_CHECK_EQUAL (setCoinsRet.size (), 3U );
141
145
142
146
// when we try making 9 cents, no subset of smaller coins is enough, and we get the next bigger coin (10)
143
- BOOST_CHECK ( testWallet.SelectCoinsMinConf ( 9 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
147
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf ( 9 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
144
148
BOOST_CHECK_EQUAL (nValueRet, 10 * CENT);
145
149
BOOST_CHECK_EQUAL (setCoinsRet.size (), 1U );
146
150
@@ -154,30 +158,30 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
154
158
add_coin (30 *CENT); // now we have 6+7+8+20+30 = 71 cents total
155
159
156
160
// check that we have 71 and not 72
157
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (71 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
158
- BOOST_CHECK (!testWallet.SelectCoinsMinConf (72 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
161
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (71 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
162
+ BOOST_CHECK (!testWallet.SelectCoinsMinConf (72 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
159
163
160
164
// now try making 16 cents. the best smaller coins can do is 6+7+8 = 21; not as good at the next biggest coin, 20
161
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (16 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
165
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (16 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
162
166
BOOST_CHECK_EQUAL (nValueRet, 20 * CENT); // we should get 20 in one coin
163
167
BOOST_CHECK_EQUAL (setCoinsRet.size (), 1U );
164
168
165
169
add_coin ( 5 *CENT); // now we have 5+6+7+8+20+30 = 75 cents total
166
170
167
171
// now if we try making 16 cents again, the smaller coins can make 5+6+7 = 18 cents, better than the next biggest coin, 20
168
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (16 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
172
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (16 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
169
173
BOOST_CHECK_EQUAL (nValueRet, 18 * CENT); // we should get 18 in 3 coins
170
174
BOOST_CHECK_EQUAL (setCoinsRet.size (), 3U );
171
175
172
176
add_coin ( 18 *CENT); // now we have 5+6+7+8+18+20+30
173
177
174
178
// and now if we try making 16 cents again, the smaller coins can make 5+6+7 = 18 cents, the same as the next biggest coin, 18
175
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (16 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
179
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (16 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
176
180
BOOST_CHECK_EQUAL (nValueRet, 18 * CENT); // we should get 18 in 1 coin
177
181
BOOST_CHECK_EQUAL (setCoinsRet.size (), 1U ); // because in the event of a tie, the biggest coin wins
178
182
179
183
// now try making 11 cents. we should get 5+6
180
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (11 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
184
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (11 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
181
185
BOOST_CHECK_EQUAL (nValueRet, 11 * CENT);
182
186
BOOST_CHECK_EQUAL (setCoinsRet.size (), 2U );
183
187
@@ -186,11 +190,11 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
186
190
add_coin ( 2 *COIN);
187
191
add_coin ( 3 *COIN);
188
192
add_coin ( 4 *COIN); // now we have 5+6+7+8+18+20+30+100+200+300+400 = 1094 cents
189
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (95 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
193
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (95 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
190
194
BOOST_CHECK_EQUAL (nValueRet, 1 * COIN); // we should get 1 BTC in 1 coin
191
195
BOOST_CHECK_EQUAL (setCoinsRet.size (), 1U );
192
196
193
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (195 * CENT, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
197
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (195 * CENT, filter_confirmed , vCoins, setCoinsRet, nValueRet));
194
198
BOOST_CHECK_EQUAL (nValueRet, 2 * COIN); // we should get 2 BTC in 1 coin
195
199
BOOST_CHECK_EQUAL (setCoinsRet.size (), 1U );
196
200
@@ -205,22 +209,22 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
205
209
206
210
// try making 1 * MIN_CHANGE from the 1.5 * MIN_CHANGE
207
211
// we'll get change smaller than MIN_CHANGE whatever happens, so can expect MIN_CHANGE exactly
208
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (MIN_CHANGE, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
212
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (MIN_CHANGE, filter_confirmed , vCoins, setCoinsRet, nValueRet));
209
213
BOOST_CHECK_EQUAL (nValueRet, MIN_CHANGE);
210
214
211
215
// but if we add a bigger coin, small change is avoided
212
216
add_coin (1111 *MIN_CHANGE);
213
217
214
218
// try making 1 from 0.1 + 0.2 + 0.3 + 0.4 + 0.5 + 1111 = 1112.5
215
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (1 * MIN_CHANGE, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
219
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (1 * MIN_CHANGE, filter_confirmed , vCoins, setCoinsRet, nValueRet));
216
220
BOOST_CHECK_EQUAL (nValueRet, 1 * MIN_CHANGE); // we should get the exact amount
217
221
218
222
// if we add more small coins:
219
223
add_coin (MIN_CHANGE * 6 / 10 );
220
224
add_coin (MIN_CHANGE * 7 / 10 );
221
225
222
226
// and try again to make 1.0 * MIN_CHANGE
223
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (1 * MIN_CHANGE, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
227
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (1 * MIN_CHANGE, filter_confirmed , vCoins, setCoinsRet, nValueRet));
224
228
BOOST_CHECK_EQUAL (nValueRet, 1 * MIN_CHANGE); // we should get the exact amount
225
229
226
230
// run the 'mtgox' test (see http://blockexplorer.com/tx/29a3efd3ef04f9153d47a990bd7b048a4b2d213daaa5fb8ed670fb85f13bdbcf)
@@ -229,7 +233,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
229
233
for (int j = 0 ; j < 20 ; j++)
230
234
add_coin (50000 * COIN);
231
235
232
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (500000 * COIN, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
236
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (500000 * COIN, filter_confirmed , vCoins, setCoinsRet, nValueRet));
233
237
BOOST_CHECK_EQUAL (nValueRet, 500000 * COIN); // we should get the exact amount
234
238
BOOST_CHECK_EQUAL (setCoinsRet.size (), 10U ); // in ten coins
235
239
@@ -242,7 +246,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
242
246
add_coin (MIN_CHANGE * 6 / 10 );
243
247
add_coin (MIN_CHANGE * 7 / 10 );
244
248
add_coin (1111 * MIN_CHANGE);
245
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (1 * MIN_CHANGE, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
249
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (1 * MIN_CHANGE, filter_confirmed , vCoins, setCoinsRet, nValueRet));
246
250
BOOST_CHECK_EQUAL (nValueRet, 1111 * MIN_CHANGE); // we get the bigger coin
247
251
BOOST_CHECK_EQUAL (setCoinsRet.size (), 1U );
248
252
@@ -252,7 +256,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
252
256
add_coin (MIN_CHANGE * 6 / 10 );
253
257
add_coin (MIN_CHANGE * 8 / 10 );
254
258
add_coin (1111 * MIN_CHANGE);
255
- BOOST_CHECK ( testWallet.SelectCoinsMinConf (MIN_CHANGE, 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
259
+ BOOST_CHECK ( testWallet.SelectCoinsMinConf (MIN_CHANGE, filter_confirmed , vCoins, setCoinsRet, nValueRet));
256
260
BOOST_CHECK_EQUAL (nValueRet, MIN_CHANGE); // we should get the exact amount
257
261
BOOST_CHECK_EQUAL (setCoinsRet.size (), 2U ); // in two coins 0.4+0.6
258
262
@@ -263,12 +267,12 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
263
267
add_coin (MIN_CHANGE * 100 );
264
268
265
269
// trying to make 100.01 from these three coins
266
- BOOST_CHECK (testWallet.SelectCoinsMinConf (MIN_CHANGE * 10001 / 100 , 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
270
+ BOOST_CHECK (testWallet.SelectCoinsMinConf (MIN_CHANGE * 10001 / 100 , filter_confirmed , vCoins, setCoinsRet, nValueRet));
267
271
BOOST_CHECK_EQUAL (nValueRet, MIN_CHANGE * 10105 / 100 ); // we should get all coins
268
272
BOOST_CHECK_EQUAL (setCoinsRet.size (), 3U );
269
273
270
274
// but if we try to make 99.9, we should take the bigger of the two small coins to avoid small change
271
- BOOST_CHECK (testWallet.SelectCoinsMinConf (MIN_CHANGE * 9990 / 100 , 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
275
+ BOOST_CHECK (testWallet.SelectCoinsMinConf (MIN_CHANGE * 9990 / 100 , filter_confirmed , vCoins, setCoinsRet, nValueRet));
272
276
BOOST_CHECK_EQUAL (nValueRet, 101 * MIN_CHANGE);
273
277
BOOST_CHECK_EQUAL (setCoinsRet.size (), 2U );
274
278
@@ -278,7 +282,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
278
282
// Create 676 inputs (= (old MAX_STANDARD_TX_SIZE == 100000) / 148 bytes per input)
279
283
for (uint16_t j = 0 ; j < 676 ; j++)
280
284
add_coin (amt);
281
- BOOST_CHECK (testWallet.SelectCoinsMinConf (2000 , 1 , 1 , 0 , vCoins, setCoinsRet, nValueRet));
285
+ BOOST_CHECK (testWallet.SelectCoinsMinConf (2000 , filter_confirmed , vCoins, setCoinsRet, nValueRet));
282
286
if (amt - 2000 < MIN_CHANGE) {
283
287
// needs more than one input:
284
288
uint16_t returnSize = std::ceil ((2000.0 + MIN_CHANGE)/amt);
@@ -300,17 +304,17 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
300
304
301
305
// picking 50 from 100 coins doesn't depend on the shuffle,
302
306
// but does depend on randomness in the stochastic approximation code
303
- BOOST_CHECK (testWallet.SelectCoinsMinConf (50 * COIN, 1 , 6 , 0 , vCoins, setCoinsRet , nValueRet));
304
- BOOST_CHECK (testWallet.SelectCoinsMinConf (50 * COIN, 1 , 6 , 0 , vCoins, setCoinsRet2, nValueRet));
307
+ BOOST_CHECK (testWallet.SelectCoinsMinConf (50 * COIN, filter_standard , vCoins, setCoinsRet , nValueRet));
308
+ BOOST_CHECK (testWallet.SelectCoinsMinConf (50 * COIN, filter_standard , vCoins, setCoinsRet2, nValueRet));
305
309
BOOST_CHECK (!equal_sets (setCoinsRet, setCoinsRet2));
306
310
307
311
int fails = 0 ;
308
312
for (int j = 0 ; j < RANDOM_REPEATS; j++)
309
313
{
310
314
// selecting 1 from 100 identical coins depends on the shuffle; this test will fail 1% of the time
311
315
// run the test RANDOM_REPEATS times and only complain if all of them fail
312
- BOOST_CHECK (testWallet.SelectCoinsMinConf (COIN, 1 , 6 , 0 , vCoins, setCoinsRet , nValueRet));
313
- BOOST_CHECK (testWallet.SelectCoinsMinConf (COIN, 1 , 6 , 0 , vCoins, setCoinsRet2, nValueRet));
316
+ BOOST_CHECK (testWallet.SelectCoinsMinConf (COIN, filter_standard , vCoins, setCoinsRet , nValueRet));
317
+ BOOST_CHECK (testWallet.SelectCoinsMinConf (COIN, filter_standard , vCoins, setCoinsRet2, nValueRet));
314
318
if (equal_sets (setCoinsRet, setCoinsRet2))
315
319
fails++;
316
320
}
@@ -330,8 +334,8 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
330
334
{
331
335
// selecting 1 from 100 identical coins depends on the shuffle; this test will fail 1% of the time
332
336
// run the test RANDOM_REPEATS times and only complain if all of them fail
333
- BOOST_CHECK (testWallet.SelectCoinsMinConf (90 *CENT, 1 , 6 , 0 , vCoins, setCoinsRet , nValueRet));
334
- BOOST_CHECK (testWallet.SelectCoinsMinConf (90 *CENT, 1 , 6 , 0 , vCoins, setCoinsRet2, nValueRet));
337
+ BOOST_CHECK (testWallet.SelectCoinsMinConf (90 *CENT, filter_standard , vCoins, setCoinsRet , nValueRet));
338
+ BOOST_CHECK (testWallet.SelectCoinsMinConf (90 *CENT, filter_standard , vCoins, setCoinsRet2, nValueRet));
335
339
if (equal_sets (setCoinsRet, setCoinsRet2))
336
340
fails++;
337
341
}
@@ -355,7 +359,7 @@ BOOST_AUTO_TEST_CASE(ApproximateBestSubset)
355
359
add_coin (1000 * COIN);
356
360
add_coin (3 * COIN);
357
361
358
- BOOST_CHECK (testWallet.SelectCoinsMinConf (1003 * COIN, 1 , 6 , 0 , vCoins, setCoinsRet, nValueRet));
362
+ BOOST_CHECK (testWallet.SelectCoinsMinConf (1003 * COIN, filter_standard , vCoins, setCoinsRet, nValueRet));
359
363
BOOST_CHECK_EQUAL (nValueRet, 1003 * COIN);
360
364
BOOST_CHECK_EQUAL (setCoinsRet.size (), 2U );
361
365
0 commit comments