Fix signed/unsigned comparison warnings
This commit is contained in:
parent
36fdfb989e
commit
87b9931bed
@ -128,51 +128,51 @@ BOOST_AUTO_TEST_CASE(bignum_SetCompact)
|
||||
CBigNum num;
|
||||
num.SetCompact(0);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "0");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
|
||||
|
||||
num.SetCompact(0x00123456);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "0");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0U);
|
||||
|
||||
num.SetCompact(0x01123456);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "12");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x01120000);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x01120000U);
|
||||
|
||||
// Make sure that we don't generate compacts with the 0x00800000 bit set
|
||||
num = 0x80;
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x02008000);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x02008000U);
|
||||
|
||||
num.SetCompact(0x01fedcba);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "-7e");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x01fe0000);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x01fe0000U);
|
||||
|
||||
num.SetCompact(0x02123456);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "1234");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x02123400);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x02123400U);
|
||||
|
||||
num.SetCompact(0x03123456);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "123456");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x03123456);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x03123456U);
|
||||
|
||||
num.SetCompact(0x04123456);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "12345600");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x04123456);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x04123456U);
|
||||
|
||||
num.SetCompact(0x04923456);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "-12345600");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x04923456);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x04923456U);
|
||||
|
||||
num.SetCompact(0x05009234);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "92340000");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x05009234);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x05009234U);
|
||||
|
||||
num.SetCompact(0x20123456);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "1234560000000000000000000000000000000000000000000000000000000000");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x20123456);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0x20123456U);
|
||||
|
||||
num.SetCompact(0xff123456);
|
||||
BOOST_CHECK_EQUAL(num.GetHex(), "123456000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0xff123456);
|
||||
BOOST_CHECK_EQUAL(num.GetCompact(), 0xff123456U);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -216,7 +216,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
||||
CScript s;
|
||||
s << OP_2 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||
BOOST_CHECK_EQUAL(solutions.size(), 4);
|
||||
BOOST_CHECK_EQUAL(solutions.size(), 4U);
|
||||
CTxDestination addr;
|
||||
BOOST_CHECK(!ExtractDestination(s, addr));
|
||||
BOOST_CHECK(IsMine(keystore, s));
|
||||
@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1)
|
||||
CScript s;
|
||||
s << OP_1 << key[0].GetPubKey() << key[1].GetPubKey() << OP_2 << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK(Solver(s, whichType, solutions));
|
||||
BOOST_CHECK_EQUAL(solutions.size(), 4);
|
||||
BOOST_CHECK_EQUAL(solutions.size(), 4U);
|
||||
vector<CTxDestination> addrs;
|
||||
int nRequired;
|
||||
BOOST_CHECK(ExtractDestinations(s, whichType, addrs, nRequired));
|
||||
|
@ -303,7 +303,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
|
||||
BOOST_CHECK(SignSignature(keystore, txFrom, txTo, 2));
|
||||
|
||||
BOOST_CHECK(txTo.AreInputsStandard(coins));
|
||||
BOOST_CHECK_EQUAL(txTo.GetP2SHSigOpCount(coins), 1);
|
||||
BOOST_CHECK_EQUAL(txTo.GetP2SHSigOpCount(coins), 1U);
|
||||
|
||||
// Make sure adding crap to the scriptSigs makes them non-standard:
|
||||
for (int i = 0; i < 3; i++)
|
||||
@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
|
||||
txToNonStd.vin[1].scriptSig << OP_0 << Serialize(oneOfEleven);
|
||||
|
||||
BOOST_CHECK(!txToNonStd.AreInputsStandard(coins));
|
||||
BOOST_CHECK_EQUAL(txToNonStd.GetP2SHSigOpCount(coins), 11);
|
||||
BOOST_CHECK_EQUAL(txToNonStd.GetP2SHSigOpCount(coins), 11U);
|
||||
|
||||
txToNonStd.vin[0].scriptSig.clear();
|
||||
BOOST_CHECK(!txToNonStd.AreInputsStandard(coins));
|
||||
|
@ -29,13 +29,13 @@ BOOST_AUTO_TEST_CASE(varints)
|
||||
|
||||
// decode
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
int j;
|
||||
int j = -1;
|
||||
ss >> VARINT(j);
|
||||
BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i);
|
||||
}
|
||||
|
||||
for (uint64 i = 0; i < 100000000000ULL; i += 999999937) {
|
||||
uint64 j;
|
||||
uint64 j = -1;
|
||||
ss >> VARINT(j);
|
||||
BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i);
|
||||
}
|
||||
|
@ -21,21 +21,21 @@ BOOST_AUTO_TEST_CASE(GetSigOpCount)
|
||||
{
|
||||
// Test CScript::GetSigOpCount()
|
||||
CScript s1;
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0);
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0);
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U);
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U);
|
||||
|
||||
uint160 dummy;
|
||||
s1 << OP_1 << dummy << dummy << OP_2 << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2);
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 2U);
|
||||
s1 << OP_IF << OP_CHECKSIG << OP_ENDIF;
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3);
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 21);
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3U);
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 21U);
|
||||
|
||||
CScript p2sh;
|
||||
p2sh.SetDestination(s1.GetID());
|
||||
CScript scriptSig;
|
||||
scriptSig << OP_0 << Serialize(s1);
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig), 3);
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig), 3U);
|
||||
|
||||
std::vector<CKey> keys;
|
||||
for (int i = 0; i < 3; i++)
|
||||
@ -46,15 +46,15 @@ BOOST_AUTO_TEST_CASE(GetSigOpCount)
|
||||
}
|
||||
CScript s2;
|
||||
s2.SetMultisig(1, keys);
|
||||
BOOST_CHECK_EQUAL(s2.GetSigOpCount(true), 3);
|
||||
BOOST_CHECK_EQUAL(s2.GetSigOpCount(false), 20);
|
||||
BOOST_CHECK_EQUAL(s2.GetSigOpCount(true), 3U);
|
||||
BOOST_CHECK_EQUAL(s2.GetSigOpCount(false), 20U);
|
||||
|
||||
p2sh.SetDestination(s2.GetID());
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0);
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0);
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0U);
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0U);
|
||||
CScript scriptSig2;
|
||||
scriptSig2 << OP_1 << dummy << dummy << Serialize(s2);
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3);
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig2), 3U);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -104,22 +104,22 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
|
||||
// try making 34 cents from 1,2,5,10,20 - we can't do it exactly
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(34 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_GT(nValueRet, 34 * CENT); // but should get more than 34 cents
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 3); // the best should be 20+10+5. it's incredibly unlikely the 1 or 2 got included (but possible)
|
||||
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, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 7 * CENT);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2);
|
||||
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, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK(nValueRet == 8 * CENT);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 3);
|
||||
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, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 10 * CENT);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1);
|
||||
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();
|
||||
@ -137,26 +137,26 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
|
||||
// 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, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 20 * CENT); // we should get 20 in one coin
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
|
||||
|
||||
add_coin( 5*CENT); // now we have 5+6+7+8+20+30 = 75 cents 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, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 18 * CENT); // we should get 18 in 3 coins
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 3);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U);
|
||||
|
||||
add_coin( 18*CENT); // 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, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 18 * CENT); // we should get 18 in 1 coin
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1); // because in the event of a tie, the biggest coin wins
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U); // because in the event of a tie, the biggest coin wins
|
||||
|
||||
// now try making 11 cents. we should get 5+6
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(11 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 11 * CENT);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U);
|
||||
|
||||
// check that the smallest bigger coin is used
|
||||
add_coin( 1*COIN);
|
||||
@ -165,11 +165,11 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
|
||||
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, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 1 * COIN); // we should get 1 BTC in 1 coin
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
|
||||
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(195 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 2 * COIN); // we should get 2 BTC in 1 coin
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
|
||||
|
||||
// empty the wallet and start again, now with fractions of a cent, to test sub-cent change avoidance
|
||||
empty_wallet();
|
||||
@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
|
||||
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(500000 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 500000 * COIN); // we should get the exact amount
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 10); // in ten coins
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 10U); // in ten coins
|
||||
|
||||
// if there's not enough in the smaller coins to make at least 1 cent change (0.5+0.6+0.7 < 1.0+1.0),
|
||||
// we need to try finding an exact subset anyway
|
||||
@ -220,7 +220,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
|
||||
add_coin(1111 * CENT);
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 1111 * CENT); // we get the bigger coin
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 1U);
|
||||
|
||||
// but sometimes it's possible, and we use an exact subset (0.4 + 0.6 = 1.0)
|
||||
empty_wallet();
|
||||
@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
|
||||
add_coin(1111 * CENT);
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(1 * CENT, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 1 * CENT); // we should get the exact amount
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2); // in two coins 0.4+0.6
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U); // in two coins 0.4+0.6
|
||||
|
||||
// test avoiding sub-cent change
|
||||
empty_wallet();
|
||||
@ -241,12 +241,12 @@ BOOST_AUTO_TEST_CASE(coin_selection_tests)
|
||||
// trying to make 1.0001 from these three coins
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(1.0001 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 1.0105 * COIN); // we should get all coins
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 3);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U);
|
||||
|
||||
// but if we try to make 0.999, we should take the bigger of the two small coins to avoid sub-cent change
|
||||
BOOST_CHECK( wallet.SelectCoinsMinConf(0.999 * COIN, 1, 1, vCoins, setCoinsRet, nValueRet));
|
||||
BOOST_CHECK_EQUAL(nValueRet, 1.01 * COIN); // we should get 1 + 0.01
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2);
|
||||
BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U);
|
||||
|
||||
// test randomness
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user