mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
tests: Add tests for decoding/parsing of base32, base64 and money strings containing NUL characters
This commit is contained in:
parent
a6fc26da55
commit
137c80d579
3 changed files with 27 additions and 0 deletions
|
@ -20,6 +20,17 @@ BOOST_AUTO_TEST_CASE(base32_testvectors)
|
|||
std::string strDec = DecodeBase32(vstrOut[i]);
|
||||
BOOST_CHECK_EQUAL(strDec, vstrIn[i]);
|
||||
}
|
||||
|
||||
// Decoding strings with embedded NUL characters should fail
|
||||
bool failure;
|
||||
(void)DecodeBase32(std::string("invalid", 7), &failure);
|
||||
BOOST_CHECK_EQUAL(failure, true);
|
||||
(void)DecodeBase32(std::string("AWSX3VPP", 8), &failure);
|
||||
BOOST_CHECK_EQUAL(failure, false);
|
||||
(void)DecodeBase32(std::string("AWSX3VPP\0invalid", 16), &failure);
|
||||
BOOST_CHECK_EQUAL(failure, true);
|
||||
(void)DecodeBase32(std::string("AWSX3VPPinvalid", 15), &failure);
|
||||
BOOST_CHECK_EQUAL(failure, true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
|
@ -20,6 +20,17 @@ BOOST_AUTO_TEST_CASE(base64_testvectors)
|
|||
std::string strDec = DecodeBase64(strEnc);
|
||||
BOOST_CHECK_EQUAL(strDec, vstrIn[i]);
|
||||
}
|
||||
|
||||
// Decoding strings with embedded NUL characters should fail
|
||||
bool failure;
|
||||
(void)DecodeBase64(std::string("invalid", 7), &failure);
|
||||
BOOST_CHECK_EQUAL(failure, true);
|
||||
(void)DecodeBase64(std::string("nQB/pZw=", 8), &failure);
|
||||
BOOST_CHECK_EQUAL(failure, false);
|
||||
(void)DecodeBase64(std::string("nQB/pZw=\0invalid", 16), &failure);
|
||||
BOOST_CHECK_EQUAL(failure, true);
|
||||
(void)DecodeBase64(std::string("nQB/pZw=invalid", 15), &failure);
|
||||
BOOST_CHECK_EQUAL(failure, true);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
|
|
@ -1069,6 +1069,11 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney)
|
|||
|
||||
// Parsing negative amounts must fail
|
||||
BOOST_CHECK(!ParseMoney("-1", ret));
|
||||
|
||||
// Parsing strings with embedded NUL characters should fail
|
||||
BOOST_CHECK(!ParseMoney(std::string("\0-1", 3), ret));
|
||||
BOOST_CHECK(!ParseMoney(std::string("\01", 2), ret));
|
||||
BOOST_CHECK(!ParseMoney(std::string("1\0", 2), ret));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_IsHex)
|
||||
|
|
Loading…
Add table
Reference in a new issue