Mercurial > hg > bitcoin
comparison src/test/key_tests.cpp @ 2688:2c65e5d626eb draft
Refactor: split CKeyID/CScriptID/CTxDestination from CBitcoinAddress
This introduces internal types:
* CKeyID: reference (hash160) of a key
* CScriptID: reference (hash160) of a script
* CTxDestination: a boost::variant of the former two
CBitcoinAddress is retrofitted to be a Base58 encoding of a
CTxDestination. This allows all internal code to only use the
internal types, and only have RPC and GUI depend on the base58 code.
Furthermore, the header dependencies are a lot saner now. base58.h is
at the top (right below rpc and gui) instead of at the bottom. For the
rest: wallet -> script -> keystore -> key. Only keystore still requires
a forward declaration of CScript. Solving that would require splitting
script into two layers.
author | Pieter Wuille <pieter.wuille@gmail.com> |
---|---|
date | Mon, 14 May 2012 23:44:52 +0200 |
parents | 2ab73d205b72 |
children |
comparison
equal
deleted
inserted
replaced
2687:2cca172f83a9 | 2688:2c65e5d626eb |
---|---|
8 #include "uint256.h" | 8 #include "uint256.h" |
9 #include "util.h" | 9 #include "util.h" |
10 | 10 |
11 using namespace std; | 11 using namespace std; |
12 | 12 |
13 static const string strSecret1 ("5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj"); | 13 static const string strSecret1 ("5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj"); |
14 static const string strSecret2 ("5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3"); | 14 static const string strSecret2 ("5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3"); |
15 static const string strSecret1C("Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw"); | 15 static const string strSecret1C ("Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw"); |
16 static const string strSecret2C("L3Hq7a8FEQwJkW1M2GNKDW28546Vp5miewcCzSqUD9kCAXrJdS3g"); | 16 static const string strSecret2C ("L3Hq7a8FEQwJkW1M2GNKDW28546Vp5miewcCzSqUD9kCAXrJdS3g"); |
17 static const string strAddress1("1HV9Lc3sNHZxwj4Zk6fB38tEmBryq2cBiF"); | 17 static const CBitcoinAddress addr1 ("1QFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ"); |
18 static const CBitcoinAddress addr2 ("1F5y5E5FMc5YzdJtB9hLaUe43GDxEKXENJ"); | |
19 static const CBitcoinAddress addr1C("1NoJrossxPBKfCHuJXT4HadJrXRE9Fxiqs"); | |
20 static const CBitcoinAddress addr2C("1CRj2HyM1CXWzHAXLQtiGLyggNT9WQqsDs"); | |
21 | |
22 | |
23 static const string strAddressBad("1HV9Lc3sNHZxwj4Zk6fB38tEmBryq2cBiF"); | |
24 | |
18 | 25 |
19 #ifdef KEY_TESTS_DUMPINFO | 26 #ifdef KEY_TESTS_DUMPINFO |
20 void dumpKeyInfo(uint256 privkey) | 27 void dumpKeyInfo(uint256 privkey) |
21 { | 28 { |
22 CSecret secret; | 29 CSecret secret; |
51 CBitcoinSecret bsecret1, bsecret2, bsecret1C, bsecret2C, baddress1; | 58 CBitcoinSecret bsecret1, bsecret2, bsecret1C, bsecret2C, baddress1; |
52 BOOST_CHECK( bsecret1.SetString (strSecret1)); | 59 BOOST_CHECK( bsecret1.SetString (strSecret1)); |
53 BOOST_CHECK( bsecret2.SetString (strSecret2)); | 60 BOOST_CHECK( bsecret2.SetString (strSecret2)); |
54 BOOST_CHECK( bsecret1C.SetString(strSecret1C)); | 61 BOOST_CHECK( bsecret1C.SetString(strSecret1C)); |
55 BOOST_CHECK( bsecret2C.SetString(strSecret2C)); | 62 BOOST_CHECK( bsecret2C.SetString(strSecret2C)); |
56 BOOST_CHECK(!baddress1.SetString(strAddress1)); | 63 BOOST_CHECK(!baddress1.SetString(strAddressBad)); |
57 | 64 |
58 bool fCompressed; | 65 bool fCompressed; |
59 CSecret secret1 = bsecret1.GetSecret (fCompressed); | 66 CSecret secret1 = bsecret1.GetSecret (fCompressed); |
60 BOOST_CHECK(fCompressed == false); | 67 BOOST_CHECK(fCompressed == false); |
61 CSecret secret2 = bsecret2.GetSecret (fCompressed); | 68 CSecret secret2 = bsecret2.GetSecret (fCompressed); |
72 key1.SetSecret(secret1, false); | 79 key1.SetSecret(secret1, false); |
73 key2.SetSecret(secret2, false); | 80 key2.SetSecret(secret2, false); |
74 key1C.SetSecret(secret1, true); | 81 key1C.SetSecret(secret1, true); |
75 key2C.SetSecret(secret2, true); | 82 key2C.SetSecret(secret2, true); |
76 | 83 |
77 BOOST_CHECK(CBitcoinAddress(key1.GetPubKey ()).ToString() == "1QFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ"); | 84 BOOST_CHECK(addr1.Get() == CTxDestination(key1.GetPubKey().GetID())); |
78 BOOST_CHECK(CBitcoinAddress(key2.GetPubKey ()).ToString() == "1F5y5E5FMc5YzdJtB9hLaUe43GDxEKXENJ"); | 85 BOOST_CHECK(addr2.Get() == CTxDestination(key2.GetPubKey().GetID())); |
79 BOOST_CHECK(CBitcoinAddress(key1C.GetPubKey()).ToString() == "1NoJrossxPBKfCHuJXT4HadJrXRE9Fxiqs"); | 86 BOOST_CHECK(addr1C.Get() == CTxDestination(key1C.GetPubKey().GetID())); |
80 BOOST_CHECK(CBitcoinAddress(key2C.GetPubKey()).ToString() == "1CRj2HyM1CXWzHAXLQtiGLyggNT9WQqsDs"); | 87 BOOST_CHECK(addr2C.Get() == CTxDestination(key2C.GetPubKey().GetID())); |
81 | 88 |
82 for (int n=0; n<16; n++) | 89 for (int n=0; n<16; n++) |
83 { | 90 { |
84 string strMsg = strprintf("Very secret message %i: 11", n); | 91 string strMsg = strprintf("Very secret message %i: 11", n); |
85 uint256 hashMsg = Hash(strMsg.begin(), strMsg.end()); | 92 uint256 hashMsg = Hash(strMsg.begin(), strMsg.end()); |