mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-19 18:09:47 +01:00
util: check MoneyRange() inside ParseMoney()
This commit is contained in:
parent
5ef2738089
commit
f7752adba5
@ -1226,7 +1226,6 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney)
|
||||
|
||||
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("1000000.00").value(), COIN*1000000);
|
||||
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);
|
||||
|
||||
// Parsing amount that can not be represented should fail
|
||||
BOOST_CHECK(!ParseMoney("100000000.00"));
|
||||
BOOST_CHECK(!ParseMoney("0.000000001"));
|
||||
|
||||
// Parsing empty string should fail
|
||||
|
@ -81,5 +81,9 @@ std::optional<CAmount> ParseMoney(const std::string& money_string)
|
||||
|
||||
CAmount value = nWhole * COIN + nUnits;
|
||||
|
||||
if (!MoneyRange(value)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user