14#include <boost/test/unit_test.hpp>
30 for (
unsigned int idx = 0; idx < tests.
size(); idx++) {
32 std::string strTest = test.
write();
33 if (test.
size() < 3) {
34 BOOST_ERROR(
"Bad test: " << strTest);
37 std::string exp_base58string = test[0].
get_str();
38 std::vector<unsigned char> exp_payload =
ParseHex(test[1].get_str());
47 BOOST_CHECK_MESSAGE(privkey.
IsValid(),
"!IsValid:" + strTest);
48 BOOST_CHECK_MESSAGE(privkey.
IsCompressed() == isCompressed,
"compressed mismatch:" + strTest);
53 BOOST_CHECK_MESSAGE(!
IsValidDestination(destination),
"IsValid privkey as pubkey:" + strTest);
62 for (
char& c : exp_base58string) {
63 if (c >=
'a' && c <=
'z') {
65 }
else if (c >=
'A' && c <=
'Z') {
70 BOOST_CHECK_MESSAGE(
IsValidDestination(destination) == try_case_flip,
"!IsValid case flipped:" + strTest);
78 BOOST_CHECK_MESSAGE(!privkey.
IsValid(),
"IsValid pubkey as privkey:" + strTest);
88 for (
unsigned int idx = 0; idx < tests.
size(); idx++) {
90 std::string strTest = test.
write();
93 BOOST_ERROR(
"Bad test: " << strTest);
96 std::string exp_base58string = test[0].
get_str();
97 std::vector<unsigned char> exp_payload =
ParseHex(test[1].get_str());
104 key.
Set(exp_payload.begin(), exp_payload.end(), isCompressed);
106 BOOST_CHECK_MESSAGE(
EncodeSecret(key) == exp_base58string,
"result mismatch: " + strTest);
109 CScript exp_script(exp_payload.begin(), exp_payload.end());
128 for (
unsigned int idx = 0; idx < tests.
size(); idx++) {
130 std::string strTest = test.
write();
133 BOOST_ERROR(
"Bad test: " << strTest);
136 std::string exp_base58string = test[0].
get_str();
142 BOOST_CHECK_MESSAGE(!
IsValidDestination(destination),
"IsValid pubkey in mainnet:" + strTest);
144 BOOST_CHECK_MESSAGE(!privkey.
IsValid(),
"IsValid privkey in mainnet:" + strTest);
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
static const std::string REGTEST
static const std::string TESTNET
static const std::string SIGNET
static const std::string MAIN
Chain name strings.
An encapsulated private key.
bool IsValid() const
Check whether this private key is valid.
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.
Serialized script, used inside transaction inputs and outputs.
A Span is an object that can refer to a contiguous sequence of objects.
const std::string & get_str() const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const UniValue & get_obj() const
BOOST_AUTO_TEST_SUITE_END()
std::string EncodeSecret(const CKey &key)
std::string EncodeDestination(const CTxDestination &dest)
CKey DecodeSecret(const std::string &str)
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg)
BOOST_AUTO_TEST_CASE(key_io_valid_parse)
UniValue read_json(const std::string &jsondata)
static unsigned const char key_io_invalid[]
static unsigned const char key_io_valid[]
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
std::vector< unsigned char > ParseHex(const char *psz)
const UniValue & find_value(const UniValue &obj, const std::string &name)