mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
test: Fuzz Base32/Base58/Base64 roundtrip conversions
This commit introduces symmetric encode-decode roundtrips for all bases. Minor refactors were also included: • Split each base into a separate fuzz target. • Added symmetric encode-decode roundtrip tests for all bases. • Removed trim testing for encoded_string, as Base58 does not use whitespace padding. • Made comparisons stricter by removing unnecessary lowercase conversions for bases that have mixed-case alphabets. Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
This commit is contained in:
@@ -82,20 +82,4 @@ BOOST_AUTO_TEST_CASE(base58_DecodeBase58)
|
||||
BOOST_CHECK(!DecodeBase58Check("3vQB7B6MrGQZaxCuFg4oh\0" "0IOl"s, result, 100));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(base58_random_encode_decode)
|
||||
{
|
||||
for (int n = 0; n < 1000; ++n) {
|
||||
unsigned int len = 1 + m_rng.randbits(8);
|
||||
unsigned int zeroes = m_rng.randbool() ? m_rng.randrange(len + 1) : 0;
|
||||
auto data = Cat(std::vector<unsigned char>(zeroes, '\000'), m_rng.randbytes(len - zeroes));
|
||||
auto encoded = EncodeBase58Check(data);
|
||||
std::vector<unsigned char> decoded;
|
||||
auto ok_too_small = DecodeBase58Check(encoded, decoded, m_rng.randrange(len));
|
||||
BOOST_CHECK(!ok_too_small);
|
||||
auto ok = DecodeBase58Check(encoded, decoded, len + m_rng.randrange(257 - len));
|
||||
BOOST_CHECK(ok);
|
||||
BOOST_CHECK(data == decoded);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user