mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
util: check MoneyRange() inside ParseMoney()
This commit is contained in:
@@ -1226,7 +1226,6 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney)
|
|||||||
|
|
||||||
BOOST_CHECK_EQUAL(ParseMoney("12345.6789").value(), (COIN/10000)*123456789);
|
BOOST_CHECK_EQUAL(ParseMoney("12345.6789").value(), (COIN/10000)*123456789);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(ParseMoney("100000000.00").value(), COIN*100000000);
|
|
||||||
BOOST_CHECK_EQUAL(ParseMoney("10000000.00").value(), COIN*10000000);
|
BOOST_CHECK_EQUAL(ParseMoney("10000000.00").value(), COIN*10000000);
|
||||||
BOOST_CHECK_EQUAL(ParseMoney("1000000.00").value(), COIN*1000000);
|
BOOST_CHECK_EQUAL(ParseMoney("1000000.00").value(), COIN*1000000);
|
||||||
BOOST_CHECK_EQUAL(ParseMoney("100000.00").value(), COIN*100000);
|
BOOST_CHECK_EQUAL(ParseMoney("100000.00").value(), COIN*100000);
|
||||||
@@ -1252,6 +1251,7 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney)
|
|||||||
BOOST_CHECK_EQUAL(ParseMoney(" 0.00000001").value(), COIN/100000000);
|
BOOST_CHECK_EQUAL(ParseMoney(" 0.00000001").value(), COIN/100000000);
|
||||||
|
|
||||||
// Parsing amount that can not be represented should fail
|
// Parsing amount that can not be represented should fail
|
||||||
|
BOOST_CHECK(!ParseMoney("100000000.00"));
|
||||||
BOOST_CHECK(!ParseMoney("0.000000001"));
|
BOOST_CHECK(!ParseMoney("0.000000001"));
|
||||||
|
|
||||||
// Parsing empty string should fail
|
// Parsing empty string should fail
|
||||||
|
|||||||
@@ -81,5 +81,9 @@ std::optional<CAmount> ParseMoney(const std::string& money_string)
|
|||||||
|
|
||||||
CAmount value = nWhole * COIN + nUnits;
|
CAmount value = nWhole * COIN + nUnits;
|
||||||
|
|
||||||
|
if (!MoneyRange(value)) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user