aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax K <[email protected]>2020-07-22 21:16:28 +0200
committerGitHub <[email protected]>2020-07-22 21:16:28 +0200
commitb0d25579cbde6920d570d4b89c7a2bd844d76fd8 (patch)
tree35d9ad526638ee84e1b6bf4019d23aaed8c4f819 /src
parentMerge pull request #1631 from m-primo/patch-1 (diff)
parentfix cents->coins in comment in wallet_tests.cpp (diff)
downloaddiscoin-b0d25579cbde6920d570d4b89c7a2bd844d76fd8.tar.xz
discoin-b0d25579cbde6920d570d4b89c7a2bd844d76fd8.zip
Merge pull request #1636 from patricklodder/1.14-fix-tests
QA: Fix all the tests
Diffstat (limited to 'src')
-rw-r--r--src/qt/test/paymentservertests.cpp3
-rw-r--r--src/qt/test/rpcnestedtests.cpp2
-rw-r--r--src/test/data/bitcoin-util-test.json42
-rw-r--r--src/test/transaction_tests.cpp2
-rw-r--r--src/test/txvalidationcache_tests.cpp2
-rw-r--r--src/wallet/test/wallet_tests.cpp196
6 files changed, 126 insertions, 121 deletions
diff --git a/src/qt/test/paymentservertests.cpp b/src/qt/test/paymentservertests.cpp
index 7aeafce79..5a397f199 100644
--- a/src/qt/test/paymentservertests.cpp
+++ b/src/qt/test/paymentservertests.cpp
@@ -191,6 +191,8 @@ void PaymentServerTests::paymentServerTests()
QCOMPARE(PaymentServer::verifySize(tempFile.size()), false);
// Payment request with amount overflow (amount is set to 21000001 BTC):
+ /* PL: This doesn't work for Dogecoin (as there is no actual maximum coins)
+ * I'm disabling this test for now.
data = DecodeBase64(paymentrequest5_cert2_BASE64);
byteArray = QByteArray((const char*)&data[0], data.size());
r.paymentRequest.parse(byteArray);
@@ -203,6 +205,7 @@ void PaymentServerTests::paymentServerTests()
if (ExtractDestination(sendingTo.first, dest))
QCOMPARE(PaymentServer::verifyAmount(sendingTo.second), false);
}
+ */
delete server;
}
diff --git a/src/qt/test/rpcnestedtests.cpp b/src/qt/test/rpcnestedtests.cpp
index bd496f149..e6acd4523 100644
--- a/src/qt/test/rpcnestedtests.cpp
+++ b/src/qt/test/rpcnestedtests.cpp
@@ -90,7 +90,7 @@ void RPCNestedTests::rpcNestedTests()
QVERIFY(result == result2);
RPCConsole::RPCExecuteCommandLine(result, "getblock(getbestblockhash())[tx][0]", &filtered);
- QVERIFY(result == "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
+ QVERIFY(result == "5b2a3f53f605d62c53e62932dac6925e3d74afa5a4b459745c36d42d0ed26a69");
QVERIFY(filtered == "getblock(getbestblockhash())[tx][0]");
RPCConsole::RPCParseCommandLine(result, "importprivkey", false, &filtered);
diff --git a/src/test/data/bitcoin-util-test.json b/src/test/data/bitcoin-util-test.json
index 901a6a1b9..99bfda37c 100644
--- a/src/test/data/bitcoin-util-test.json
+++ b/src/test/data/bitcoin-util-test.json
@@ -5,7 +5,7 @@
"description": "Creates a blank v1 transaction"
},
{ "exec": "./dogecoin-tx",
- "args": ["-json","-create", "nversion=1"],
+ "args": ["-json", "-create", "nversion=1"],
"output_cmp": "blanktxv1.json",
"description": "Creates a blank v1 transaction (output in json)"
},
@@ -13,15 +13,15 @@
"args": ["-"],
"input": "blanktxv2.hex",
"output_cmp": "blanktxv2.hex",
- "description": "Creates a blank transaction when nothing is piped into dogecoin-tx"
+ "description": "Creates a blank v2 transaction when nothing is piped into dogecoin-tx"
},
{ "exec": "./dogecoin-tx",
- "args": ["-json","-create"],
+ "args": ["-json","-create", "nversion=2"],
"output_cmp": "blanktxv2.json",
- "description": "Creates a blank transaction (output in json)"
+ "description": "Creates a blank v2 transaction (output in json)"
},
{ "exec": "./dogecoin-tx",
- "args": ["-json","-"],
+ "args": ["-json", "-"],
"input": "blanktxv2.hex",
"output_cmp": "blanktxv2.json",
"description": "Creates a blank transaction when nothing is piped into dogecoin-tx (output in json)"
@@ -84,15 +84,15 @@
"error_txt": "error: TX output missing or too many separators",
"description": "Malformed outaddr argument (no address specified). Expected to fail."
},
- { "exec": "./bitcoin-tx",
+ { "exec": "./dogecoin-tx",
"args":
["-create",
- "outaddr=1:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o:garbage"],
+ "outaddr=1:DTH54BW9S9Q1EPCCiseQCzEBgf6pTRZv3U:garbage"],
"return_code": 1,
"error_txt": "error: TX output missing or too many separators",
"description": "Malformed outaddr argument (too many separators). Expected to fail."
},
- { "exec": "./bitcoin-tx",
+ { "exec": "./dogecoin-tx",
"args":
["-create",
"outpubkey=0"],
@@ -100,7 +100,7 @@
"error_txt": "error: TX output missing or too many separators",
"description": "Malformed outpubkey argument (no pubkey specified). Expected to fail."
},
- { "exec": "./bitcoin-tx",
+ { "exec": "./dogecoin-tx",
"args":
["-create",
"outpubkey=0:02a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397:W:non53nse"],
@@ -108,14 +108,15 @@
"error_txt": "error: TX output missing or too many separators",
"description": "Malformed outpubkey argument (too many separators). Expected to fail."
},
- { "exec": "./bitcoin-tx",
+ { "exec": "./dogecoin-tx",
"args":
["-create",
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
"in=bf829c6bcf84579331337659d31f89dfd138f7f7785802d5501c92333145ca7c:18",
"in=22a6f904655d53ae2ff70e701a0bbd90aa3975c0f40bfc6cc996a9049e31cdfc:1",
"outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd",
- "outaddr=4:DTH54BW9S9Q1EPCCiseQCzEBgf6pTRZv3U"],
+ "outaddr=4:DTH54BW9S9Q1EPCCiseQCzEBgf6pTRZv3U",
+ "nversion=2"],
"output_cmp": "txcreate1.hex",
"description": "Creates a new transaction with three inputs and two outputs"
},
@@ -127,17 +128,18 @@
"in=bf829c6bcf84579331337659d31f89dfd138f7f7785802d5501c92333145ca7c:18",
"in=22a6f904655d53ae2ff70e701a0bbd90aa3975c0f40bfc6cc996a9049e31cdfc:1",
"outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd",
- "outaddr=4:DTH54BW9S9Q1EPCCiseQCzEBgf6pTRZv3U"],
+ "outaddr=4:DTH54BW9S9Q1EPCCiseQCzEBgf6pTRZv3U",
+ "nversion=2"],
"output_cmp": "txcreate1.json",
"description": "Creates a new transaction with three inputs and two outputs (output in json)"
},
{ "exec": "./dogecoin-tx",
- "args": ["-create", "outscript=0:"],
+ "args": ["-create", "outscript=0:", "nversion=2"],
"output_cmp": "txcreate2.hex",
"description": "Creates a new transaction with a single empty output script"
},
{ "exec": "./dogecoin-tx",
- "args": ["-json", "-create", "outscript=0:"],
+ "args": ["-json", "-create", "outscript=0:", "nversion=2"],
"output_cmp": "txcreate2.json",
"description": "Creates a new transaction with a single empty output script (output in json)"
},
@@ -216,7 +218,7 @@
},
{ "exec": "./dogecoin-tx",
"args":
- ["-create",
+ ["-create", "nversion=2",
"in=4d49a71ec9da436f71ec4ee231d04f292a29cd316f598bb7068feccabdc59485:0",
"set=privatekeys:[\"6J8csdv3eDrnJcpSEb4shfjMh2JTiG9MKzC1Yfge4Y4GyUsjdM6\"]",
"set=prevtxs:[{\"txid\":\"4d49a71ec9da436f71ec4ee231d04f292a29cd316f598bb7068feccabdc59485\",\"vout\":0,\"scriptPubKey\":\"76a91491b24bf9f5288532960ac687abb035127b1d28a588ac\"}]",
@@ -281,7 +283,7 @@
},
{ "exec": "./dogecoin-tx",
"args":
- ["-create",
+ ["-create", "nversion=2",
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
"outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd",
"outdata=4:54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e"],
@@ -300,7 +302,7 @@
},
{ "exec": "./dogecoin-tx",
"args":
- ["-create",
+ ["-create", "nversion=2",
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
"outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd",
"outdata=54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e"],
@@ -310,7 +312,7 @@
{ "exec": "./dogecoin-tx",
"args":
["-json",
- "-create",
+ "-create", "nversion=2",
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0",
"outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd",
"outdata=54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e"],
@@ -319,7 +321,7 @@
},
{ "exec": "./dogecoin-tx",
"args":
- ["-create",
+ ["-create", "nversion=2",
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0:4294967293",
"outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd"],
"output_cmp": "txcreatedata_seq0.hex",
@@ -328,7 +330,7 @@
{ "exec": "./dogecoin-tx",
"args":
["-json",
- "-create",
+ "-create", "nversion=2",
"in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0:4294967293",
"outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd"],
"output_cmp": "txcreatedata_seq0.json",
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
index e4fa56100..9124c2ff3 100644
--- a/src/test/transaction_tests.cpp
+++ b/src/test/transaction_tests.cpp
@@ -681,7 +681,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
t.vin[0].prevout.n = 1;
t.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
t.vout.resize(1);
- t.vout[0].nValue = 90*CENT;
+ t.vout[0].nValue = COIN;
CKey key;
key.MakeNewKey(true);
t.vout[0].scriptPubKey = GetScriptForDestination(key.GetPubKey().GetID());
diff --git a/src/test/txvalidationcache_tests.cpp b/src/test/txvalidationcache_tests.cpp
index a4d1c8f73..64f2782ad 100644
--- a/src/test/txvalidationcache_tests.cpp
+++ b/src/test/txvalidationcache_tests.cpp
@@ -44,7 +44,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain240Setup)
spends[i].vin[0].prevout.hash = coinbaseTxns[0].GetHash();
spends[i].vin[0].prevout.n = 0;
spends[i].vout.resize(1);
- spends[i].vout[0].nValue = 11*CENT;
+ spends[i].vout[0].nValue = COIN;
spends[i].vout[0].scriptPubKey = scriptPubKey;
// Sign:
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index 03838926a..4e84bb688 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -88,115 +88,115 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
{
empty_wallet();
- // with an empty wallet we can't even pay one cent
- BOOST_CHECK(!wallet.SelectCoinsMinConf( 1 * CENT, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
+ // with an empty wallet we can't even pay one coin
+ BOOST_CHECK(!wallet.SelectCoinsMinConf( 1 * COIN, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
- add_coin(1*CENT, 4); // add a new 1 cent coin
+ add_coin(1*COIN, 4); // add a new 1 coin output
- // with a new 1 cent coin, we still can't find a mature 1 cent
- BOOST_CHECK(!wallet.SelectCoinsMinConf( 1 * CENT, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
+ // with only a new 1 coin output, we still can't find a mature 1 coin output
+ BOOST_CHECK(!wallet.SelectCoinsMinConf( 1 * COIN, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
- // but we can find a new 1 cent
- BOOST_CHECK( wallet.SelectCoinsMinConf( 1 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 1 * CENT);
+ // but we can find a new 1 coin output
+ BOOST_CHECK( wallet.SelectCoinsMinConf( 1 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 1 * COIN);
- add_coin(2*CENT); // add a mature 2 cent coin
+ add_coin(2*COIN); // add a mature 2 coin output
- // we can't make 3 cents of mature coins
- BOOST_CHECK(!wallet.SelectCoinsMinConf( 3 * CENT, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
+ // we can't make 3 coins of mature outputs
+ BOOST_CHECK(!wallet.SelectCoinsMinConf( 3 * COIN, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
- // we can make 3 cents of new coins
- BOOST_CHECK( wallet.SelectCoinsMinConf( 3 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 3 * CENT);
+ // we can make 3 coin of new outputs
+ BOOST_CHECK( wallet.SelectCoinsMinConf( 3 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 3 * COIN);
- add_coin(5*CENT); // add a mature 5 cent coin,
- add_coin(10*CENT, 3, true); // a new 10 cent coin sent from one of our own addresses
- add_coin(20*CENT); // and a mature 20 cent coin
+ add_coin(5*COIN); // add a mature 5 coin output,
+ add_coin(10*COIN, 3, true); // a new 10 coin output sent from one of our own addresses
+ add_coin(20*COIN); // and a mature 20 coin output
// now we have new: 1+10=11 (of which 10 was self-sent), and mature: 2+5+20=27. total = 38
- // we can't make 38 cents only if we disallow new coins:
- BOOST_CHECK(!wallet.SelectCoinsMinConf(38 * CENT, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
- // we can't even make 37 cents if we don't allow new coins even if they're from us
- BOOST_CHECK(!wallet.SelectCoinsMinConf(38 * CENT, 6, 6, 0, vCoins, setCoinsRet, nValueRet));
- // but we can make 37 cents if we accept new coins from ourself
- BOOST_CHECK( wallet.SelectCoinsMinConf(37 * CENT, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 37 * CENT);
- // and we can make 38 cents if we accept all new coins
- BOOST_CHECK( wallet.SelectCoinsMinConf(38 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 38 * CENT);
-
- // try making 34 cents from 1,2,5,10,20 - we can't do it exactly
- BOOST_CHECK( wallet.SelectCoinsMinConf(34 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 35 * CENT); // but 35 cents is closest
+ // we can't make 38 coins only if we disallow new output:
+ BOOST_CHECK(!wallet.SelectCoinsMinConf(38 * COIN, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
+ // we can't even make 37 coins if we don't allow new output even if they're from us
+ BOOST_CHECK(!wallet.SelectCoinsMinConf(38 * COIN, 6, 6, 0, vCoins, setCoinsRet, nValueRet));
+ // but we can make 37 coins if we accept new output from ourself
+ BOOST_CHECK( wallet.SelectCoinsMinConf(37 * COIN, 1, 6, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 37 * COIN);
+ // and we can make 38 coins if we accept all new output
+ BOOST_CHECK( wallet.SelectCoinsMinConf(38 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 38 * COIN);
+
+ // try making 34 coins from 1,2,5,10,20 - we can't do it exactly
+ BOOST_CHECK( wallet.SelectCoinsMinConf(34 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 35 * COIN); // but 35 coins is closest
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)
- // when we try making 7 cents, the smaller coins (1,2,5) are enough. We should see just 2+5
- BOOST_CHECK( wallet.SelectCoinsMinConf( 7 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 7 * CENT);
+ // when we try making 7 coins, the smaller outputs (1,2,5) are enough. We should see just 2+5
+ BOOST_CHECK( wallet.SelectCoinsMinConf( 7 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 7 * COIN);
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U);
- // when we try making 8 cents, the smaller coins (1,2,5) are exactly enough.
- BOOST_CHECK( wallet.SelectCoinsMinConf( 8 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK(nValueRet == 8 * CENT);
+ // when we try making 8 coins, the smaller outputs (1,2,5) are exactly enough.
+ BOOST_CHECK( wallet.SelectCoinsMinConf( 8 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK(nValueRet == 8 * COIN);
BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U);
- // when we try making 9 cents, no subset of smaller coins is enough, and we get the next bigger coin (10)
- BOOST_CHECK( wallet.SelectCoinsMinConf( 9 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 10 * CENT);
+ // when we try making 9 coins, no subset of smaller outputs is enough, and we get the next bigger output (10)
+ BOOST_CHECK( wallet.SelectCoinsMinConf( 9 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 10 * COIN);
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
// now clear out the wallet and start again to test choosing between subsets of smaller coins and the next biggest coin
empty_wallet();
- add_coin( 6*CENT);
- add_coin( 7*CENT);
- add_coin( 8*CENT);
- add_coin(20*CENT);
- add_coin(30*CENT); // now we have 6+7+8+20+30 = 71 cents total
+ add_coin( 6*COIN);
+ add_coin( 7*COIN);
+ add_coin( 8*COIN);
+ add_coin(20*COIN);
+ add_coin(30*COIN); // now we have 6+7+8+20+30 = 71 coins total
// check that we have 71 and not 72
- BOOST_CHECK( wallet.SelectCoinsMinConf(71 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK(!wallet.SelectCoinsMinConf(72 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK( wallet.SelectCoinsMinConf(71 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK(!wallet.SelectCoinsMinConf(72 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- // 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
- BOOST_CHECK( wallet.SelectCoinsMinConf(16 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 20 * CENT); // we should get 20 in one coin
+ // now try making 16 coins. the best smaller outputs can do is 6+7+8 = 21; not as good at the next biggest output, 20
+ BOOST_CHECK( wallet.SelectCoinsMinConf(16 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 20 * COIN); // we should get 20 in one output
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
- add_coin( 5*CENT); // now we have 5+6+7+8+20+30 = 75 cents total
+ add_coin( 5*COIN); // now we have 5+6+7+8+20+30 = 75 coins total
- // 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
- BOOST_CHECK( wallet.SelectCoinsMinConf(16 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 18 * CENT); // we should get 18 in 3 coins
+ // now if we try making 16 coins again, the smaller outputs can make 5+6+7 = 18 coins, better than the next biggest output, 20
+ BOOST_CHECK( wallet.SelectCoinsMinConf(16 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 18 * COIN); // we should get 18 in 3 outputs
BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U);
- add_coin( 18*CENT); // now we have 5+6+7+8+18+20+30
+ add_coin( 18*COIN); // now we have 5+6+7+8+18+20+30
- // 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
- BOOST_CHECK( wallet.SelectCoinsMinConf(16 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 18 * CENT); // we should get 18 in 1 coin
- BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U); // because in the event of a tie, the biggest coin wins
+ // and now if we try making 16 coins again, the smaller outputs can make 5+6+7 = 18 coins, the same as the next biggest output, 18
+ BOOST_CHECK( wallet.SelectCoinsMinConf(16 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 18 * COIN); // we should get 18 in 1 output
+ BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U); // because in the event of a tie, the biggest output wins
- // now try making 11 cents. we should get 5+6
- BOOST_CHECK( wallet.SelectCoinsMinConf(11 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 11 * CENT);
+ // now try making 11 coins. we should get 5+6
+ BOOST_CHECK( wallet.SelectCoinsMinConf(11 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 11 * COIN);
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U);
- // check that the smallest bigger coin is used
- add_coin( 1*COIN);
- add_coin( 2*COIN);
- add_coin( 3*COIN);
- add_coin( 4*COIN); // now we have 5+6+7+8+18+20+30+100+200+300+400 = 1094 cents
- BOOST_CHECK( wallet.SelectCoinsMinConf(95 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 1 * COIN); // we should get 1 BTC in 1 coin
+ // check that the smallest bigger output is used
+ add_coin( 100*COIN);
+ add_coin( 200*COIN);
+ add_coin( 300*COIN);
+ add_coin( 400*COIN); // now we have 5+6+7+8+18+20+30+100+200+300+400 = 1094 coins
+ BOOST_CHECK( wallet.SelectCoinsMinConf(95 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 100 * COIN); // we should get 100 coins in 1 output
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
- BOOST_CHECK( wallet.SelectCoinsMinConf(195 * CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 2 * COIN); // we should get 2 BTC in 1 coin
+ BOOST_CHECK( wallet.SelectCoinsMinConf(195 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ BOOST_CHECK_EQUAL(nValueRet, 200 * COIN); // we should get 200 coins in 1 output
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
- // empty the wallet and start again, now with fractions of a cent, to test small change avoidance
+ // empty the wallet and start again, now with fractions of a coin, to test small change avoidance
empty_wallet();
add_coin(MIN_CHANGE * 1 / 10);
@@ -210,14 +210,14 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
BOOST_CHECK( wallet.SelectCoinsMinConf(MIN_CHANGE, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
BOOST_CHECK_EQUAL(nValueRet, MIN_CHANGE);
- // but if we add a bigger coin, small change is avoided
+ // but if we add a bigger output, small change is avoided
add_coin(1111*MIN_CHANGE);
// try making 1 from 0.1 + 0.2 + 0.3 + 0.4 + 0.5 + 1111 = 1112.5
BOOST_CHECK( wallet.SelectCoinsMinConf(1 * MIN_CHANGE, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
BOOST_CHECK_EQUAL(nValueRet, 1 * MIN_CHANGE); // we should get the exact amount
- // if we add more small coins:
+ // if we add more small output:
add_coin(MIN_CHANGE * 6 / 10);
add_coin(MIN_CHANGE * 7 / 10);
@@ -226,26 +226,26 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
BOOST_CHECK_EQUAL(nValueRet, 1 * MIN_CHANGE); // we should get the exact amount
// run the 'mtgox' test (see http://blockexplorer.com/tx/29a3efd3ef04f9153d47a990bd7b048a4b2d213daaa5fb8ed670fb85f13bdbcf)
- // they tried to consolidate 10 50k coins into one 500k coin, and ended up with 50k in change
+ // they tried to consolidate 10 50k outputs into one 500k output, and ended up with 50k in change
empty_wallet();
for (int j = 0; j < 20; j++)
add_coin(50000 * COIN);
BOOST_CHECK( wallet.SelectCoinsMinConf(500000 * COIN, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
BOOST_CHECK_EQUAL(nValueRet, 500000 * COIN); // we should get the exact amount
- BOOST_CHECK_EQUAL(setCoinsRet.size(), 10U); // in ten coins
+ BOOST_CHECK_EQUAL(setCoinsRet.size(), 10U); // in ten outputs
// if there's not enough in the smaller coins to make at least 1 * MIN_CHANGE change (0.5+0.6+0.7 < 1.0+1.0),
// we need to try finding an exact subset anyway
- // sometimes it will fail, and so we use the next biggest coin:
+ // sometimes it will fail, and so we use the next biggest output:
empty_wallet();
add_coin(MIN_CHANGE * 5 / 10);
add_coin(MIN_CHANGE * 6 / 10);
add_coin(MIN_CHANGE * 7 / 10);
add_coin(1111 * MIN_CHANGE);
BOOST_CHECK( wallet.SelectCoinsMinConf(1 * MIN_CHANGE, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, 1111 * MIN_CHANGE); // we get the bigger coin
+ BOOST_CHECK_EQUAL(nValueRet, 1111 * MIN_CHANGE); // we get the bigger output
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
// but sometimes it's possible, and we use an exact subset (0.4 + 0.6 = 1.0)
@@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
add_coin(1111 * MIN_CHANGE);
BOOST_CHECK( wallet.SelectCoinsMinConf(MIN_CHANGE, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
BOOST_CHECK_EQUAL(nValueRet, MIN_CHANGE); // we should get the exact amount
- BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U); // in two coins 0.4+0.6
+ BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U); // in two outputs 0.4+0.6
// test avoiding small change
empty_wallet();
@@ -264,26 +264,26 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
add_coin(MIN_CHANGE * 1);
add_coin(MIN_CHANGE * 100);
- // trying to make 100.01 from these three coins
+ // trying to make 100.01 from these three outputs
BOOST_CHECK(wallet.SelectCoinsMinConf(MIN_CHANGE * 10001 / 100, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- BOOST_CHECK_EQUAL(nValueRet, MIN_CHANGE * 10105 / 100); // we should get all coins
+ BOOST_CHECK_EQUAL(nValueRet, MIN_CHANGE * 10105 / 100); // we should get all outputs
BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U);
- // but if we try to make 99.9, we should take the bigger of the two small coins to avoid small change
+ // but if we try to make 99.9, we should take the bigger of the two small outputs to avoid small change
BOOST_CHECK(wallet.SelectCoinsMinConf(MIN_CHANGE * 9990 / 100, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
BOOST_CHECK_EQUAL(nValueRet, 101 * MIN_CHANGE);
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U);
// test with many inputs
- for (CAmount amt=1500; amt < COIN; amt*=10) {
+ for (CAmount amt=15*CENT; amt < 10000 * COIN; amt*=10) {
empty_wallet();
// Create 676 inputs (= (old MAX_STANDARD_TX_SIZE == 100000) / 148 bytes per input)
for (uint16_t j = 0; j < 676; j++)
add_coin(amt);
- BOOST_CHECK(wallet.SelectCoinsMinConf(2000, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
- if (amt - 2000 < MIN_CHANGE) {
+ BOOST_CHECK(wallet.SelectCoinsMinConf(20*CENT, 1, 1, 0, vCoins, setCoinsRet, nValueRet));
+ if (amt - 20*CENT < MIN_CHANGE) {
// needs more than one input:
- uint16_t returnSize = std::ceil((2000.0 + MIN_CHANGE)/amt);
+ uint16_t returnSize = std::ceil((20.0 * CENT + MIN_CHANGE)/amt);
CAmount returnValue = amt * returnSize;
BOOST_CHECK_EQUAL(nValueRet, returnValue);
BOOST_CHECK_EQUAL(setCoinsRet.size(), returnSize);
@@ -300,7 +300,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
for (int i2 = 0; i2 < 100; i2++)
add_coin(COIN);
- // picking 50 from 100 coins doesn't depend on the shuffle,
+ // picking 50 from 100 outputs doesn't depend on the shuffle,
// but does depend on randomness in the stochastic approximation code
BOOST_CHECK(wallet.SelectCoinsMinConf(50 * COIN, 1, 6, 0, vCoins, setCoinsRet , nValueRet));
BOOST_CHECK(wallet.SelectCoinsMinConf(50 * COIN, 1, 6, 0, vCoins, setCoinsRet2, nValueRet));
@@ -309,7 +309,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
int fails = 0;
for (int j = 0; j < RANDOM_REPEATS; j++)
{
- // selecting 1 from 100 identical coins depends on the shuffle; this test will fail 1% of the time
+ // selecting 1 from 100 identical outputs depends on the shuffle; this test will fail 1% of the time
// run the test RANDOM_REPEATS times and only complain if all of them fail
BOOST_CHECK(wallet.SelectCoinsMinConf(COIN, 1, 6, 0, vCoins, setCoinsRet , nValueRet));
BOOST_CHECK(wallet.SelectCoinsMinConf(COIN, 1, 6, 0, vCoins, setCoinsRet2, nValueRet));
@@ -318,22 +318,22 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
}
BOOST_CHECK_NE(fails, RANDOM_REPEATS);
- // add 75 cents in small change. not enough to make 90 cents,
- // then try making 90 cents. there are multiple competing "smallest bigger" coins,
+ // add 75 coins in small change. not enough to make 90 coins,
+ // then try making 90 coins. there are multiple competing "smallest bigger" outputs,
// one of which should be picked at random
- add_coin(5 * CENT);
- add_coin(10 * CENT);
- add_coin(15 * CENT);
- add_coin(20 * CENT);
- add_coin(25 * CENT);
+ add_coin(5 * COIN);
+ add_coin(10 * COIN);
+ add_coin(15 * COIN);
+ add_coin(20 * COIN);
+ add_coin(25 * COIN);
fails = 0;
for (int j = 0; j < RANDOM_REPEATS; j++)
{
- // selecting 1 from 100 identical coins depends on the shuffle; this test will fail 1% of the time
+ // selecting 1 from 100 identical outputs depends on the shuffle; this test will fail 1% of the time
// run the test RANDOM_REPEATS times and only complain if all of them fail
- BOOST_CHECK(wallet.SelectCoinsMinConf(90*CENT, 1, 6, 0, vCoins, setCoinsRet , nValueRet));
- BOOST_CHECK(wallet.SelectCoinsMinConf(90*CENT, 1, 6, 0, vCoins, setCoinsRet2, nValueRet));
+ BOOST_CHECK(wallet.SelectCoinsMinConf(90*COIN, 1, 6, 0, vCoins, setCoinsRet , nValueRet));
+ BOOST_CHECK(wallet.SelectCoinsMinConf(90*COIN, 1, 6, 0, vCoins, setCoinsRet2, nValueRet));
if (equal_sets(setCoinsRet, setCoinsRet2))
fails++;
}