Changeset View
Changeset View
Standalone View
Standalone View
src/test/base58_tests.cpp
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | for (unsigned int idx = 0; idx < tests.size(); idx++) { | ||||
BOOST_CHECK_MESSAGE(privkey.IsCompressed() == isCompressed, | BOOST_CHECK_MESSAGE(privkey.IsCompressed() == isCompressed, | ||||
"compressed mismatch:" + strTest); | "compressed mismatch:" + strTest); | ||||
BOOST_CHECK_MESSAGE(privkey.size() == exp_payload.size() && | BOOST_CHECK_MESSAGE(privkey.size() == exp_payload.size() && | ||||
std::equal(privkey.begin(), privkey.end(), | std::equal(privkey.begin(), privkey.end(), | ||||
exp_payload.begin()), | exp_payload.begin()), | ||||
"key mismatch:" + strTest); | "key mismatch:" + strTest); | ||||
// Private key must be invalid public key | // Private key must be invalid public key | ||||
destination = DecodeDestination(exp_base58string); | destination = DecodeLegacyAddr(exp_base58string, Params()); | ||||
BOOST_CHECK_MESSAGE(!IsValidDestination(destination), | BOOST_CHECK_MESSAGE(!IsValidDestination(destination), | ||||
"IsValid privkey as pubkey:" + strTest); | "IsValid privkey as pubkey:" + strTest); | ||||
} else { | } else { | ||||
// "script" or "pubkey" | // "script" or "pubkey" | ||||
std::string exp_addrType = | std::string exp_addrType = | ||||
find_value(metadata, "addrType").get_str(); | find_value(metadata, "addrType").get_str(); | ||||
// Must be valid public key | // Must be valid public key | ||||
destination = DecodeDestination(exp_base58string); | destination = DecodeLegacyAddr(exp_base58string, Params()); | ||||
BOOST_CHECK_MESSAGE(IsValidDestination(destination), | BOOST_CHECK_MESSAGE(IsValidDestination(destination), | ||||
"!IsValid:" + strTest); | "!IsValid:" + strTest); | ||||
BOOST_CHECK_MESSAGE((boost::get<CScriptID>(&destination) != | BOOST_CHECK_MESSAGE((boost::get<CScriptID>(&destination) != | ||||
nullptr) == (exp_addrType == "script"), | nullptr) == (exp_addrType == "script"), | ||||
"isScript mismatch" + strTest); | "isScript mismatch" + strTest); | ||||
BOOST_CHECK_MESSAGE( | BOOST_CHECK_MESSAGE( | ||||
boost::apply_visitor(TestAddrTypeVisitor(exp_addrType), | boost::apply_visitor(TestAddrTypeVisitor(exp_addrType), | ||||
destination), | destination), | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | for (unsigned int idx = 0; idx < tests.size(); idx++) { | ||||
} else if (exp_addrType == "script") { | } else if (exp_addrType == "script") { | ||||
dest = CScriptID(uint160(exp_payload)); | dest = CScriptID(uint160(exp_payload)); | ||||
} else if (exp_addrType == "none") { | } else if (exp_addrType == "none") { | ||||
dest = CNoDestination(); | dest = CNoDestination(); | ||||
} else { | } else { | ||||
BOOST_ERROR("Bad addrtype: " << strTest); | BOOST_ERROR("Bad addrtype: " << strTest); | ||||
continue; | continue; | ||||
} | } | ||||
std::string address = EncodeDestination(dest); | std::string address = EncodeLegacyAddr(dest, Params()); | ||||
BOOST_CHECK_MESSAGE(address == exp_base58string, | BOOST_CHECK_MESSAGE(address == exp_base58string, | ||||
"mismatch: " + strTest); | "mismatch: " + strTest); | ||||
} | } | ||||
} | } | ||||
SelectParams(CBaseChainParams::MAIN); | SelectParams(CBaseChainParams::MAIN); | ||||
} | } | ||||
Show All 14 Lines | for (unsigned int idx = 0; idx < tests.size(); idx++) { | ||||
// Allow for extra stuff (useful for comments) | // Allow for extra stuff (useful for comments) | ||||
if (test.size() < 1) { | if (test.size() < 1) { | ||||
BOOST_ERROR("Bad test: " << strTest); | BOOST_ERROR("Bad test: " << strTest); | ||||
continue; | continue; | ||||
} | } | ||||
std::string exp_base58string = test[0].get_str(); | std::string exp_base58string = test[0].get_str(); | ||||
// must be invalid as public and as private key | // must be invalid as public and as private key | ||||
destination = DecodeDestination(exp_base58string); | destination = DecodeLegacyAddr(exp_base58string, Params()); | ||||
BOOST_CHECK_MESSAGE(!IsValidDestination(destination), | BOOST_CHECK_MESSAGE(!IsValidDestination(destination), | ||||
"IsValid pubkey:" + strTest); | "IsValid pubkey:" + strTest); | ||||
secret.SetString(exp_base58string); | secret.SetString(exp_base58string); | ||||
BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid privkey:" + strTest); | BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid privkey:" + strTest); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |