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