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