-
+ 675DAF2BC964697D1E1291E3ADC0CA291F813AE5875BB2C00CB796841C16B0C6D2BC92347ABBD83472F0A52ABEBBF596D51548E442289D9B908A148F5157D5A2bitcoin/src/test/base58_tests.cpp(0 . 0)(1 . 87)
21233 #include <boost/test/unit_test.hpp>
21234
21235 #include "../util.h"
21236
21237 BOOST_AUTO_TEST_SUITE(base58_tests)
21238
21239 // TODO:
21240 // EncodeBase58Check
21241 // DecodeBase58Check
21242 // CBase58Data
21243 // bool SetString(const char* psz)
21244 // bool SetString(const std::string& str)
21245 // std::string ToString() const
21246 // int CompareTo(const CBase58Data& b58) const
21247 // bool operator==(const CBase58Data& b58) const
21248 // bool operator<=(const CBase58Data& b58) const
21249 // bool operator>=(const CBase58Data& b58) const
21250 // bool operator< (const CBase58Data& b58) const
21251 // bool operator> (const CBase58Data& b58) const
21252
21253 // CBitcoinAddress
21254 // bool SetHash160(const uint160& hash160)
21255 // bool SetPubKey(const std::vector<unsigned char>& vchPubKey)
21256 // bool IsValid() const
21257 // CBitcoinAddress()
21258 // CBitcoinAddress(uint160 hash160In)
21259 // CBitcoinAddress(const std::vector<unsigned char>& vchPubKey)
21260 // CBitcoinAddress(const std::string& strAddress)
21261 // CBitcoinAddress(const char* pszAddress)
21262 // uint160 GetHash160() const
21263
21264 #define U(x) (reinterpret_cast<const unsigned char*>(x))
21265 static struct {
21266 const unsigned char *data;
21267 int size;
21268 } vstrIn[] = {
21269 {U(""), 0},
21270 {U("\x61"), 1},
21271 {U("\x62\x62\x62"), 3},
21272 {U("\x63\x63\x63"), 3},
21273 {U("\x73\x69\x6d\x70\x6c\x79\x20\x61\x20\x6c\x6f\x6e\x67\x20\x73\x74\x72\x69\x6e\x67"), 20},
21274 {U("\x00\xeb\x15\x23\x1d\xfc\xeb\x60\x92\x58\x86\xb6\x7d\x06\x52\x99\x92\x59\x15\xae\xb1\x72\xc0\x66\x47"), 25},
21275 {U("\x51\x6b\x6f\xcd\x0f"), 5},
21276 {U("\xbf\x4f\x89\x00\x1e\x67\x02\x74\xdd"), 9},
21277 {U("\x57\x2e\x47\x94"), 4},
21278 {U("\xec\xac\x89\xca\xd9\x39\x23\xc0\x23\x21"), 10},
21279 {U("\x10\xc8\x51\x1e"), 4},
21280 {U("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"), 10},
21281 };
21282
21283 const char *vstrOut[] = {
21284 "",
21285 "2g",
21286 "a3gV",
21287 "aPEr",
21288 "2cFupjhnEsSn59qHXstmK2ffpLv2",
21289 "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L",
21290 "ABnLTmg",
21291 "3SEo3LWLoPntC",
21292 "3EFU7m",
21293 "EJDM8drfXA6uyA",
21294 "Rt5zm",
21295 "1111111111"
21296 };
21297
21298 BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
21299 {
21300 for (int i=0; i<sizeof(vstrIn)/sizeof(vstrIn[0]); i++)
21301 {
21302 BOOST_CHECK_EQUAL(EncodeBase58(vstrIn[i].data, vstrIn[i].data + vstrIn[i].size), vstrOut[i]);
21303 }
21304 }
21305
21306 BOOST_AUTO_TEST_CASE(base58_DecodeBase58)
21307 {
21308 std::vector<unsigned char> result;
21309 for (int i=0; i<sizeof(vstrIn)/sizeof(vstrIn[0]); i++)
21310 {
21311 std::vector<unsigned char> expected(vstrIn[i].data, vstrIn[i].data + vstrIn[i].size);
21312 BOOST_CHECK(DecodeBase58(vstrOut[i], result));
21313 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
21314 }
21315 BOOST_CHECK(!DecodeBase58("invalid", result));
21316 }
21317
21318 BOOST_AUTO_TEST_SUITE_END()
21319