@@ -27,7 +27,7 @@ typedef set<pair<const CWalletTx*,unsigned int> > CoinSet;
27
27
28
28
BOOST_FIXTURE_TEST_SUITE (wallet_tests, WalletTestingSetup)
29
29
30
- static CWallet wallet;
30
+ static const CWallet wallet;
31
31
static vector<COutput> vCoins;
32
32
33
33
static void add_coin (const CAmount& nValue, int nAge = 6 *24 , bool fIsFromMe = false , int nInput=0 )
@@ -188,11 +188,11 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
188
188
// empty the wallet and start again, now with fractions of a cent, to test small change avoidance
189
189
190
190
empty_wallet ();
191
- add_coin (0.1 * MIN_CHANGE);
192
- add_coin (0.2 * MIN_CHANGE);
193
- add_coin (0.3 * MIN_CHANGE);
194
- add_coin (0.4 * MIN_CHANGE);
195
- add_coin (0.5 * MIN_CHANGE);
191
+ add_coin (MIN_CHANGE * 1 / 10 );
192
+ add_coin (MIN_CHANGE * 2 / 10 );
193
+ add_coin (MIN_CHANGE * 3 / 10 );
194
+ add_coin (MIN_CHANGE * 4 / 10 );
195
+ add_coin (MIN_CHANGE * 5 / 10 );
196
196
197
197
// try making 1 * MIN_CHANGE from the 1.5 * MIN_CHANGE
198
198
// we'll get change smaller than MIN_CHANGE whatever happens, so can expect MIN_CHANGE exactly
@@ -207,8 +207,8 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
207
207
BOOST_CHECK_EQUAL (nValueRet, 1 * MIN_CHANGE); // we should get the exact amount
208
208
209
209
// if we add more small coins:
210
- add_coin (0.6 * MIN_CHANGE);
211
- add_coin (0.7 * MIN_CHANGE);
210
+ add_coin (MIN_CHANGE * 6 / 10 );
211
+ add_coin (MIN_CHANGE * 7 / 10 );
212
212
213
213
// and try again to make 1.0 * MIN_CHANGE
214
214
BOOST_CHECK ( wallet.SelectCoinsMinConf (1 * MIN_CHANGE, 1 , 1 , vCoins, setCoinsRet, nValueRet));
@@ -229,37 +229,37 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
229
229
230
230
// sometimes it will fail, and so we use the next biggest coin:
231
231
empty_wallet ();
232
- add_coin (0.5 * MIN_CHANGE );
233
- add_coin (0.6 * MIN_CHANGE );
234
- add_coin (0.7 * MIN_CHANGE );
232
+ add_coin (MIN_CHANGE * 5 / 10 );
233
+ add_coin (MIN_CHANGE * 6 / 10 );
234
+ add_coin (MIN_CHANGE * 7 / 10 );
235
235
add_coin (1111 * MIN_CHANGE);
236
236
BOOST_CHECK ( wallet.SelectCoinsMinConf (1 * MIN_CHANGE, 1 , 1 , vCoins, setCoinsRet, nValueRet));
237
237
BOOST_CHECK_EQUAL (nValueRet, 1111 * MIN_CHANGE); // we get the bigger coin
238
238
BOOST_CHECK_EQUAL (setCoinsRet.size (), 1U );
239
239
240
240
// but sometimes it's possible, and we use an exact subset (0.4 + 0.6 = 1.0)
241
241
empty_wallet ();
242
- add_coin (0.4 * MIN_CHANGE );
243
- add_coin (0.6 * MIN_CHANGE );
244
- add_coin (0.8 * MIN_CHANGE );
242
+ add_coin (MIN_CHANGE * 4 / 10 );
243
+ add_coin (MIN_CHANGE * 6 / 10 );
244
+ add_coin (MIN_CHANGE * 8 / 10 );
245
245
add_coin (1111 * MIN_CHANGE);
246
246
BOOST_CHECK ( wallet.SelectCoinsMinConf (MIN_CHANGE, 1 , 1 , vCoins, setCoinsRet, nValueRet));
247
247
BOOST_CHECK_EQUAL (nValueRet, MIN_CHANGE); // we should get the exact amount
248
248
BOOST_CHECK_EQUAL (setCoinsRet.size (), 2U ); // in two coins 0.4+0.6
249
249
250
250
// test avoiding small change
251
251
empty_wallet ();
252
- add_coin (0.05 * MIN_CHANGE );
253
- add_coin (1 * MIN_CHANGE );
254
- add_coin (100 * MIN_CHANGE );
252
+ add_coin (MIN_CHANGE * 5 / 100 );
253
+ add_coin (MIN_CHANGE * 1 );
254
+ add_coin (MIN_CHANGE * 100 );
255
255
256
256
// trying to make 100.01 from these three coins
257
- BOOST_CHECK ( wallet.SelectCoinsMinConf (100.01 * MIN_CHANGE , 1 , 1 , vCoins, setCoinsRet, nValueRet));
258
- BOOST_CHECK_EQUAL (nValueRet, 101.05 * MIN_CHANGE); // we should get all coins
257
+ BOOST_CHECK (wallet.SelectCoinsMinConf (MIN_CHANGE * 10001 / 100 , 1 , 1 , vCoins, setCoinsRet, nValueRet));
258
+ BOOST_CHECK_EQUAL (nValueRet, MIN_CHANGE * 10105 / 100 ); // we should get all coins
259
259
BOOST_CHECK_EQUAL (setCoinsRet.size (), 3U );
260
260
261
261
// but if we try to make 99.9, we should take the bigger of the two small coins to avoid small change
262
- BOOST_CHECK ( wallet.SelectCoinsMinConf (99.9 * MIN_CHANGE , 1 , 1 , vCoins, setCoinsRet, nValueRet));
262
+ BOOST_CHECK (wallet.SelectCoinsMinConf (MIN_CHANGE * 9990 / 100 , 1 , 1 , vCoins, setCoinsRet, nValueRet));
263
263
BOOST_CHECK_EQUAL (nValueRet, 101 * MIN_CHANGE);
264
264
BOOST_CHECK_EQUAL (setCoinsRet.size (), 2U );
265
265
@@ -310,7 +310,11 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
310
310
// add 75 cents in small change. not enough to make 90 cents,
311
311
// then try making 90 cents. there are multiple competing "smallest bigger" coins,
312
312
// one of which should be picked at random
313
- add_coin ( 5 *CENT); add_coin (10 *CENT); add_coin (15 *CENT); add_coin (20 *CENT); add_coin (25 *CENT);
313
+ add_coin (5 * CENT);
314
+ add_coin (10 * CENT);
315
+ add_coin (15 * CENT);
316
+ add_coin (20 * CENT);
317
+ add_coin (25 * CENT);
314
318
315
319
fails = 0 ;
316
320
for (int i = 0 ; i < RANDOM_REPEATS; i++)
0 commit comments