Skip to content

Commit ff7a999

Browse files
tests: Add tests for base58-decoding of std::string:s containing non-base58 characters
1 parent 3914e87 commit ff7a999

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/test/base58_tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,24 @@ BOOST_AUTO_TEST_CASE(base58_DecodeBase58)
5959
}
6060

6161
BOOST_CHECK(!DecodeBase58("invalid", result, 100));
62+
BOOST_CHECK(!DecodeBase58(std::string("invalid"), result, 100));
63+
BOOST_CHECK(!DecodeBase58(std::string("\0invalid", 8), result, 100));
64+
65+
BOOST_CHECK(DecodeBase58(std::string("good", 4), result, 100));
66+
BOOST_CHECK(!DecodeBase58(std::string("bad0IOl", 7), result, 100));
67+
BOOST_CHECK(!DecodeBase58(std::string("goodbad0IOl", 11), result, 100));
68+
BOOST_CHECK(!DecodeBase58(std::string("good\0bad0IOl", 12), result, 100));
6269

6370
// check that DecodeBase58 skips whitespace, but still fails with unexpected non-whitespace at the end.
6471
BOOST_CHECK(!DecodeBase58(" \t\n\v\f\r skip \r\f\v\n\t a", result, 3));
6572
BOOST_CHECK( DecodeBase58(" \t\n\v\f\r skip \r\f\v\n\t ", result, 3));
6673
std::vector<unsigned char> expected = ParseHex("971a55");
6774
BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
75+
76+
BOOST_CHECK(DecodeBase58Check(std::string("3vQB7B6MrGQZaxCuFg4oh", 21), result, 100));
77+
BOOST_CHECK(!DecodeBase58Check(std::string("3vQB7B6MrGQZaxCuFg4oi", 21), result, 100));
78+
BOOST_CHECK(!DecodeBase58Check(std::string("3vQB7B6MrGQZaxCuFg4oh0IOl", 25), result, 100));
79+
BOOST_CHECK(!DecodeBase58Check(std::string("3vQB7B6MrGQZaxCuFg4oh\00IOl", 26), result, 100));
6880
}
6981

7082
BOOST_AUTO_TEST_CASE(base58_random_encode_decode)

0 commit comments

Comments
 (0)