5 #include <test/data/key_io_invalid.json.h> 6 #include <test/data/key_io_valid.json.h> 17 #include <boost/test/unit_test.hpp> 31 for (
unsigned int idx = 0; idx <
tests.size(); idx++) {
33 std::string strTest = test.
write();
34 if (test.
size() < 3) {
35 BOOST_ERROR(
"Bad test: " << strTest);
38 std::string exp_base58string = test[0].
get_str();
39 const std::vector<std::byte> exp_payload{ParseHex<std::byte>(test[1].
get_str())};
48 BOOST_CHECK_MESSAGE(privkey.
IsValid(),
"!IsValid:" + strTest);
49 BOOST_CHECK_MESSAGE(privkey.
IsCompressed() == isCompressed,
"compressed mismatch:" + strTest);
50 BOOST_CHECK_MESSAGE(std::ranges::equal(privkey, exp_payload),
"key mismatch:" + strTest);
54 BOOST_CHECK_MESSAGE(!
IsValidDestination(destination),
"IsValid privkey as pubkey:" + strTest);
63 for (
char& c : exp_base58string) {
64 if (c >=
'a' && c <=
'z') {
66 }
else if (c >=
'A' && c <=
'Z') {
71 BOOST_CHECK_MESSAGE(
IsValidDestination(destination) == try_case_flip,
"!IsValid case flipped:" + strTest);
79 BOOST_CHECK_MESSAGE(!privkey.
IsValid(),
"IsValid pubkey as privkey:" + strTest);
89 for (
unsigned int idx = 0; idx <
tests.size(); idx++) {
91 std::string strTest = test.
write();
94 BOOST_ERROR(
"Bad test: " << strTest);
97 std::string exp_base58string = test[0].
get_str();
98 std::vector<unsigned char> exp_payload =
ParseHex(test[1].get_str());
105 key.
Set(exp_payload.begin(), exp_payload.end(), isCompressed);
107 BOOST_CHECK_MESSAGE(
EncodeSecret(key) == exp_base58string,
"result mismatch: " + strTest);
110 CScript exp_script(exp_payload.begin(), exp_payload.end());
129 for (
unsigned int idx = 0; idx <
tests.size(); idx++) {
131 std::string strTest = test.
write();
134 BOOST_ERROR(
"Bad test: " << strTest);
137 std::string exp_base58string = test[0].
get_str();
143 BOOST_CHECK_MESSAGE(!
IsValidDestination(destination),
"IsValid pubkey in mainnet:" + strTest);
145 BOOST_CHECK_MESSAGE(!privkey.
IsValid(),
"IsValid privkey in mainnet:" + strTest);
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
BOOST_AUTO_TEST_CASE(key_io_valid_parse)
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
const std::string & get_str() const
UniValue read_json(std::string_view jsondata)
constexpr std::array tests
const UniValue & find_value(std::string_view key) const
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a scriptPubKey for the destination.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
#define BOOST_CHECK_EQUAL(v1, v2)
Serialized script, used inside transaction inputs and outputs.
const UniValue & get_obj() const
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::optional< ChainType > ChainTypeFromString(std::string_view chain)
std::string EncodeDestination(const CTxDestination &dest)
An encapsulated private key.
CKey DecodeSecret(const std::string &str)
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
std::string EncodeSecret(const CKey &key)
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
bool IsValid() const
Check whether this private key is valid.
#define BOOST_CHECK(expr)