raw
experimental-genesis    1 //  /****************************\
experimental-genesis 2 // * EXPERIMENTAL BRANCH. *
experimental-genesis 3 // * FOR LABORATORY USE ONLY. *
experimental-genesis 4 // ********************************
experimental-genesis 5 // ************
experimental-genesis 6 // **************
experimental-genesis 7 // ****************
experimental-genesis 8 // **** **** ****
experimental-genesis 9 // *** *** ***
experimental-genesis 10 // *** *** ***
experimental-genesis 11 // *** * * **
experimental-genesis 12 // ******** ********
experimental-genesis 13 // ******* ******
experimental-genesis 14 // *** **
experimental-genesis 15 // * ******* **
experimental-genesis 16 // ** * * * * *
experimental-genesis 17 // ** * * ***
experimental-genesis 18 // **** * * * * ****
experimental-genesis 19 // **** *** * * ** ***
experimental-genesis 20 // **** ********* ******
experimental-genesis 21 // ******* ***** *******
experimental-genesis 22 // ********* ****** **
experimental-genesis 23 // ** ****** ******
experimental-genesis 24 // ** ******* **
experimental-genesis 25 // ** ******* ***
experimental-genesis 26 // **** ******** ************
experimental-genesis 27 // ************ ************
experimental-genesis 28 // ******** *******
experimental-genesis 29 // ****** ****
experimental-genesis 30 // *** ***
experimental-genesis 31 // ********************************
experimental-genesis 32 #include <boost/test/unit_test.hpp>
experimental-genesis 33
experimental-genesis 34 #include "../util.h"
experimental-genesis 35
experimental-genesis 36 BOOST_AUTO_TEST_SUITE(base58_tests)
experimental-genesis 37
experimental-genesis 38 // TODO:
experimental-genesis 39 // EncodeBase58Check
experimental-genesis 40 // DecodeBase58Check
experimental-genesis 41 // CBase58Data
experimental-genesis 42 // bool SetString(const char* psz)
experimental-genesis 43 // bool SetString(const std::string& str)
experimental-genesis 44 // std::string ToString() const
experimental-genesis 45 // int CompareTo(const CBase58Data& b58) const
experimental-genesis 46 // bool operator==(const CBase58Data& b58) const
experimental-genesis 47 // bool operator<=(const CBase58Data& b58) const
experimental-genesis 48 // bool operator>=(const CBase58Data& b58) const
experimental-genesis 49 // bool operator< (const CBase58Data& b58) const
experimental-genesis 50 // bool operator> (const CBase58Data& b58) const
experimental-genesis 51
experimental-genesis 52 // CBitcoinAddress
experimental-genesis 53 // bool SetHash160(const uint160& hash160)
experimental-genesis 54 // bool SetPubKey(const std::vector<unsigned char>& vchPubKey)
experimental-genesis 55 // bool IsValid() const
experimental-genesis 56 // CBitcoinAddress()
experimental-genesis 57 // CBitcoinAddress(uint160 hash160In)
experimental-genesis 58 // CBitcoinAddress(const std::vector<unsigned char>& vchPubKey)
experimental-genesis 59 // CBitcoinAddress(const std::string& strAddress)
experimental-genesis 60 // CBitcoinAddress(const char* pszAddress)
experimental-genesis 61 // uint160 GetHash160() const
experimental-genesis 62
experimental-genesis 63 #define U(x) (reinterpret_cast<const unsigned char*>(x))
experimental-genesis 64 static struct {
experimental-genesis 65 const unsigned char *data;
experimental-genesis 66 int size;
experimental-genesis 67 } vstrIn[] = {
experimental-genesis 68 {U(""), 0},
experimental-genesis 69 {U("\x61"), 1},
experimental-genesis 70 {U("\x62\x62\x62"), 3},
experimental-genesis 71 {U("\x63\x63\x63"), 3},
experimental-genesis 72 {U("\x73\x69\x6d\x70\x6c\x79\x20\x61\x20\x6c\x6f\x6e\x67\x20\x73\x74\x72\x69\x6e\x67"), 20},
experimental-genesis 73 {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},
experimental-genesis 74 {U("\x51\x6b\x6f\xcd\x0f"), 5},
experimental-genesis 75 {U("\xbf\x4f\x89\x00\x1e\x67\x02\x74\xdd"), 9},
experimental-genesis 76 {U("\x57\x2e\x47\x94"), 4},
experimental-genesis 77 {U("\xec\xac\x89\xca\xd9\x39\x23\xc0\x23\x21"), 10},
experimental-genesis 78 {U("\x10\xc8\x51\x1e"), 4},
experimental-genesis 79 {U("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"), 10},
experimental-genesis 80 };
experimental-genesis 81
experimental-genesis 82 const char *vstrOut[] = {
experimental-genesis 83 "",
experimental-genesis 84 "2g",
experimental-genesis 85 "a3gV",
experimental-genesis 86 "aPEr",
experimental-genesis 87 "2cFupjhnEsSn59qHXstmK2ffpLv2",
experimental-genesis 88 "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L",
experimental-genesis 89 "ABnLTmg",
experimental-genesis 90 "3SEo3LWLoPntC",
experimental-genesis 91 "3EFU7m",
experimental-genesis 92 "EJDM8drfXA6uyA",
experimental-genesis 93 "Rt5zm",
experimental-genesis 94 "1111111111"
experimental-genesis 95 };
experimental-genesis 96
experimental-genesis 97 BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
experimental-genesis 98 {
experimental-genesis 99 for (int i=0; i<sizeof(vstrIn)/sizeof(vstrIn[0]); i++)
experimental-genesis 100 {
experimental-genesis 101 BOOST_CHECK_EQUAL(EncodeBase58(vstrIn[i].data, vstrIn[i].data + vstrIn[i].size), vstrOut[i]);
experimental-genesis 102 }
experimental-genesis 103 }
experimental-genesis 104
experimental-genesis 105 BOOST_AUTO_TEST_CASE(base58_DecodeBase58)
experimental-genesis 106 {
experimental-genesis 107 std::vector<unsigned char> result;
experimental-genesis 108 for (int i=0; i<sizeof(vstrIn)/sizeof(vstrIn[0]); i++)
experimental-genesis 109 {
experimental-genesis 110 std::vector<unsigned char> expected(vstrIn[i].data, vstrIn[i].data + vstrIn[i].size);
experimental-genesis 111 BOOST_CHECK(DecodeBase58(vstrOut[i], result));
experimental-genesis 112 BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), expected.begin(), expected.end());
experimental-genesis 113 }
experimental-genesis 114 BOOST_CHECK(!DecodeBase58("invalid", result));
experimental-genesis 115 }
experimental-genesis 116
experimental-genesis 117 BOOST_AUTO_TEST_SUITE_END()
experimental-genesis 118