Implement BIP173 addresses and tests

This commit is contained in:
Pieter Wuille
2017-08-25 19:55:52 -07:00
parent bd355b8db9
commit c091b99379
19 changed files with 397 additions and 32 deletions

View File

@@ -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()