mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
util: check MoneyRange() inside ParseMoney()
This commit is contained in:
parent
5ef2738089
commit
f7752adba5
2 changed files with 5 additions and 1 deletions
|
@ -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 a new issue