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