1 #include <boost/test/unit_test.hpp>
12 BOOST_AUTO_TEST_SUITE(base58_tests)
19 BOOST_FOREACH(
Value& tv, tests)
25 BOOST_ERROR(
"Bad test: " << strTest);
29 std::string base58string = test[1].get_str();
31 EncodeBase58(&sourcedata[0], &sourcedata[sourcedata.size()]) == base58string,
40 std::vector<unsigned char> result;
42 BOOST_FOREACH(
Value& tv, tests)
48 BOOST_ERROR(
"Bad test: " << strTest);
52 std::string base58string = test[1].get_str();
53 BOOST_CHECK_MESSAGE(
DecodeBase58(base58string, result), strTest);
54 BOOST_CHECK_MESSAGE(result.size() == expected.size() && std::equal(result.begin(), result.end(), expected.begin()), strTest);
69 return (exp_addrType ==
"pubkey");
73 return (exp_addrType ==
"script");
77 return (exp_addrType ==
"none");
100 return exp_payload.size() == 0;
108 std::vector<unsigned char> result;
114 BOOST_FOREACH(
Value& tv, tests)
120 BOOST_ERROR(
"Bad test: " << strTest);
123 std::string exp_base58string = test[0].get_str();
125 const Object &metadata = test[2].get_obj();
126 bool isPrivkey =
find_value(metadata,
"isPrivkey").get_bool();
127 bool isTestnet =
find_value(metadata,
"isTestnet").get_bool();
131 bool isCompressed =
find_value(metadata,
"isCompressed").get_bool();
134 BOOST_CHECK_MESSAGE(secret.
SetString(exp_base58string),
"!SetString:"+ strTest);
135 BOOST_CHECK_MESSAGE(secret.
IsValid(),
"!IsValid:" + strTest);
137 BOOST_CHECK_MESSAGE(privkey.IsCompressed() == isCompressed,
"compressed mismatch:" + strTest);
138 BOOST_CHECK_MESSAGE(privkey.size() == exp_payload.size() && std::equal(privkey.begin(), privkey.end(), exp_payload.begin()),
"key mismatch:" + strTest);
142 BOOST_CHECK_MESSAGE(!addr.
IsValid(),
"IsValid privkey as pubkey:" + strTest);
146 std::string exp_addrType =
find_value(metadata,
"addrType").get_str();
148 BOOST_CHECK_MESSAGE(addr.
SetString(exp_base58string),
"SetString:" + strTest);
149 BOOST_CHECK_MESSAGE(addr.
IsValid(),
"!IsValid:" + strTest);
150 BOOST_CHECK_MESSAGE(addr.
IsScript() == (exp_addrType ==
"script"),
"isScript mismatch" + strTest);
152 BOOST_CHECK_MESSAGE(boost::apply_visitor(
TestAddrTypeVisitor(exp_addrType), dest),
"addrType mismatch" + strTest);
156 BOOST_CHECK_MESSAGE(!secret.
IsValid(),
"IsValid pubkey as privkey:" + strTest);
167 std::vector<unsigned char> result;
171 BOOST_FOREACH(
Value& tv, tests)
177 BOOST_ERROR(
"Bad test: " << strTest);
180 std::string exp_base58string = test[0].get_str();
182 const Object &metadata = test[2].get_obj();
183 bool isPrivkey =
find_value(metadata,
"isPrivkey").get_bool();
184 bool isTestnet =
find_value(metadata,
"isTestnet").get_bool();
188 bool isCompressed =
find_value(metadata,
"isCompressed").get_bool();
190 key.
Set(exp_payload.begin(), exp_payload.end(), isCompressed);
194 BOOST_CHECK_MESSAGE(secret.ToString() == exp_base58string,
"result mismatch: " + strTest);
198 std::string exp_addrType =
find_value(metadata,
"addrType").get_str();
200 if(exp_addrType ==
"pubkey")
204 else if(exp_addrType ==
"script")
208 else if(exp_addrType ==
"none")
214 BOOST_ERROR(
"Bad addrtype: " << strTest);
218 BOOST_CHECK_MESSAGE(boost::apply_visitor(
CBitcoinAddressVisitor(&addrOut), dest),
"encode dest: " + strTest);
219 BOOST_CHECK_MESSAGE(addrOut.
ToString() == exp_base58string,
"mismatch: " + strTest);
236 std::vector<unsigned char> result;
240 BOOST_FOREACH(
Value& tv, tests)
246 BOOST_ERROR(
"Bad test: " << strTest);
249 std::string exp_base58string = test[0].get_str();
253 BOOST_CHECK_MESSAGE(!addr.
IsValid(),
"IsValid pubkey:" + strTest);
255 BOOST_CHECK_MESSAGE(!secret.
IsValid(),
"IsValid privkey:" + strTest);
260 BOOST_AUTO_TEST_SUITE_END()
bool operator()(const CScriptID &id) const
void SetKey(const CKey &vchSecret)
BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
bool DecodeBase58(const char *psz, std::vector< unsigned char > &vchRet)
bool operator()(const CScriptID &id) const
Array read_json(const std::string &filename)
bool operator()(const CKeyID &id) const
bool operator()(const CNoDestination &no) const
CTxDestination Get() const
Config::Object_type Object
const Array & get_array() const
bool SetString(const char *pszSecret)
bool operator()(const CNoDestination &no) const
A base58-encoded secret key.
TestAddrTypeVisitor(const std::string &exp_addrType)
const Object_type::value_type::Value_type & find_value(const Object_type &obj, const String_type &name)
std::string ToString() const
void Set(const T pbegin, const T pend, bool fCompressedIn)
TestPayloadVisitor(std::vector< unsigned char > &exp_payload)
bool operator()(const CKeyID &id) const
Value_type::String_type write_string(const Value_type &value, bool pretty)
std::vector< unsigned char > exp_payload
A reference to a CKey: the Hash160 of its serialized public key.
bool SetString(const char *psz)
std::string EncodeBase58(const unsigned char *pbegin, const unsigned char *pend)
A reference to a CScript: the Hash160 of its serialization (see script.h)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
An encapsulated private key.
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
vector< unsigned char > ParseHex(const char *psz)