util: check MoneyRange() inside ParseMoney()

This commit is contained in:
fanquake 2021-07-09 13:12:51 +08:00
parent 5ef2738089
commit f7752adba5
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1
2 changed files with 5 additions and 1 deletions

View File

@ -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

View File

@ -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;
}