Changeset View
Changeset View
Standalone View
Standalone View
src/test/base58_tests.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | for (unsigned int idx = 0; idx < tests.size(); idx++) { | ||||
BOOST_CHECK_MESSAGE(DecodeBase58(base58string, result, 256), strTest); | BOOST_CHECK_MESSAGE(DecodeBase58(base58string, result, 256), strTest); | ||||
BOOST_CHECK_MESSAGE( | BOOST_CHECK_MESSAGE( | ||||
result.size() == expected.size() && | result.size() == expected.size() && | ||||
std::equal(result.begin(), result.end(), expected.begin()), | std::equal(result.begin(), result.end(), expected.begin()), | ||||
strTest); | strTest); | ||||
} | } | ||||
BOOST_CHECK(!DecodeBase58("invalid", result, 100)); | BOOST_CHECK(!DecodeBase58("invalid", result, 100)); | ||||
BOOST_CHECK(!DecodeBase58(std::string("invalid"), result, 100)); | |||||
BOOST_CHECK(!DecodeBase58(std::string("\0invalid", 8), result, 100)); | |||||
BOOST_CHECK(DecodeBase58(std::string("good", 4), result, 100)); | |||||
BOOST_CHECK(!DecodeBase58(std::string("bad0IOl", 7), result, 100)); | |||||
BOOST_CHECK(!DecodeBase58(std::string("goodbad0IOl", 11), result, 100)); | |||||
BOOST_CHECK(!DecodeBase58(std::string("good\0bad0IOl", 12), result, 100)); | |||||
// check that DecodeBase58 skips whitespace, but still fails with unexpected | // check that DecodeBase58 skips whitespace, but still fails with unexpected | ||||
// non-whitespace at the end. | // non-whitespace at the end. | ||||
BOOST_CHECK(!DecodeBase58(" \t\n\v\f\r skip \r\f\v\n\t a", result, 3)); | BOOST_CHECK(!DecodeBase58(" \t\n\v\f\r skip \r\f\v\n\t a", result, 3)); | ||||
BOOST_CHECK(DecodeBase58(" \t\n\v\f\r skip \r\f\v\n\t ", result, 3)); | BOOST_CHECK(DecodeBase58(" \t\n\v\f\r skip \r\f\v\n\t ", result, 3)); | ||||
std::vector<uint8_t> expected = ParseHex("971a55"); | std::vector<uint8_t> expected = ParseHex("971a55"); | ||||
BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), | BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), | ||||
expected.begin(), expected.end()); | expected.begin(), expected.end()); | ||||
BOOST_CHECK(DecodeBase58Check(std::string("3vQB7B6MrGQZaxCuFg4oh", 21), | |||||
result, 100)); | |||||
BOOST_CHECK(!DecodeBase58Check(std::string("3vQB7B6MrGQZaxCuFg4oi", 21), | |||||
result, 100)); | |||||
BOOST_CHECK(!DecodeBase58Check(std::string("3vQB7B6MrGQZaxCuFg4oh0IOl", 25), | |||||
result, 100)); | |||||
BOOST_CHECK(!DecodeBase58Check( | |||||
std::string("3vQB7B6MrGQZaxCuFg4oh\00IOl", 26), result, 100)); | |||||
} | } | ||||
BOOST_AUTO_TEST_CASE(base58_random_encode_decode) { | BOOST_AUTO_TEST_CASE(base58_random_encode_decode) { | ||||
for (int n = 0; n < 1000; ++n) { | for (int n = 0; n < 1000; ++n) { | ||||
unsigned int len = 1 + InsecureRandBits(8); | unsigned int len = 1 + InsecureRandBits(8); | ||||
unsigned int zeroes = | unsigned int zeroes = | ||||
InsecureRandBool() ? InsecureRandRange(len + 1) : 0; | InsecureRandBool() ? InsecureRandRange(len + 1) : 0; | ||||
auto data = Cat(std::vector<uint8_t>(zeroes, '\000'), | auto data = Cat(std::vector<uint8_t>(zeroes, '\000'), | ||||
Show All 14 Lines |