mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-18 03:20:24 +01:00
Implement BIP173 addresses and tests
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user