diff options
Diffstat (limited to 'src/test/base58_tests.cpp')
-rw-r--r-- | src/test/base58_tests.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp index 65092f593b..6bc6dd5187 100644 --- a/src/test/base58_tests.cpp +++ b/src/test/base58_tests.cpp @@ -93,6 +93,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse) const UniValue &metadata = test[2].get_obj(); bool isPrivkey = find_value(metadata, "isPrivkey").get_bool(); SelectParams(find_value(metadata, "chain").get_str()); + bool try_case_flip = find_value(metadata, "tryCaseFlip").isNull() ? false : find_value(metadata, "tryCaseFlip").get_bool(); if (isPrivkey) { bool isCompressed = find_value(metadata, "isCompressed").get_bool(); // Must be valid private key @@ -112,6 +113,21 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse) BOOST_CHECK_MESSAGE(IsValidDestination(destination), "!IsValid:" + strTest); BOOST_CHECK_EQUAL(HexStr(script), HexStr(exp_payload)); + // Try flipped case version + for (char& c : exp_base58string) { + if (c >= 'a' && c <= 'z') { + c = (c - 'a') + 'A'; + } else if (c >= 'A' && c <= 'Z') { + c = (c - 'A') + 'a'; + } + } + destination = DecodeDestination(exp_base58string); + BOOST_CHECK_MESSAGE(IsValidDestination(destination) == try_case_flip, "!IsValid case flipped:" + strTest); + if (IsValidDestination(destination)) { + script = GetScriptForDestination(destination); + BOOST_CHECK_EQUAL(HexStr(script), HexStr(exp_payload)); + } + // Public key must be invalid private key secret.SetString(exp_base58string); BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid pubkey as privkey:" + strTest); @@ -150,6 +166,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen) CScript exp_script(exp_payload.begin(), exp_payload.end()); ExtractDestination(exp_script, dest); std::string address = EncodeDestination(dest); + BOOST_CHECK_EQUAL(address, exp_base58string); } } @@ -157,6 +174,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen) SelectParams(CBaseChainParams::MAIN); } + // Goal: check that base58 parsing code is robust against a variety of corrupted data BOOST_AUTO_TEST_CASE(base58_keys_invalid) { @@ -187,4 +205,3 @@ BOOST_AUTO_TEST_CASE(base58_keys_invalid) BOOST_AUTO_TEST_SUITE_END() - |