Changeset View
Changeset View
Standalone View
Standalone View
src/test/key_tests.cpp
Show All 10 Lines | |||||
#include "util.h" | #include "util.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
static const std::string | static const std::string strSecret1 = | ||||
strSecret1("5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj"); | "5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj"; | ||||
static const std::string | static const std::string strSecret2 = | ||||
strSecret2("5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3"); | "5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3"; | ||||
static const std::string | static const std::string strSecret1C = | ||||
strSecret1C("Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw"); | "Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw"; | ||||
static const std::string | static const std::string strSecret2C = | ||||
strSecret2C("L3Hq7a8FEQwJkW1M2GNKDW28546Vp5miewcCzSqUD9kCAXrJdS3g"); | "L3Hq7a8FEQwJkW1M2GNKDW28546Vp5miewcCzSqUD9kCAXrJdS3g"; | ||||
static const CBitcoinAddress addr1("1QFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ"); | static const std::string addr1 = "1QFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ"; | ||||
static const CBitcoinAddress addr2("1F5y5E5FMc5YzdJtB9hLaUe43GDxEKXENJ"); | static const std::string addr2 = "1F5y5E5FMc5YzdJtB9hLaUe43GDxEKXENJ"; | ||||
static const CBitcoinAddress addr1C("1NoJrossxPBKfCHuJXT4HadJrXRE9Fxiqs"); | static const std::string addr1C = "1NoJrossxPBKfCHuJXT4HadJrXRE9Fxiqs"; | ||||
static const CBitcoinAddress addr2C("1CRj2HyM1CXWzHAXLQtiGLyggNT9WQqsDs"); | static const std::string addr2C = "1CRj2HyM1CXWzHAXLQtiGLyggNT9WQqsDs"; | ||||
static const std::string strAddressBad("1HV9Lc3sNHZxwj4Zk6fB38tEmBryq2cBiF"); | static const std::string strAddressBad = "1HV9Lc3sNHZxwj4Zk6fB38tEmBryq2cBiF"; | ||||
#ifdef KEY_TESTS_DUMPINFO | #ifdef KEY_TESTS_DUMPINFO | ||||
void dumpKeyInfo(uint256 privkey) { | void dumpKeyInfo(uint256 privkey) { | ||||
CKey key; | CKey key; | ||||
key.resize(32); | key.resize(32); | ||||
memcpy(&secret[0], &privkey, 32); | memcpy(&secret[0], &privkey, 32); | ||||
std::vector<uint8_t> sec; | std::vector<uint8_t> sec; | ||||
sec.resize(32); | sec.resize(32); | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(key_test1) { | ||||
BOOST_CHECK(key2.VerifyPubKey(pubkey2)); | BOOST_CHECK(key2.VerifyPubKey(pubkey2)); | ||||
BOOST_CHECK(!key2.VerifyPubKey(pubkey2C)); | BOOST_CHECK(!key2.VerifyPubKey(pubkey2C)); | ||||
BOOST_CHECK(!key2C.VerifyPubKey(pubkey1)); | BOOST_CHECK(!key2C.VerifyPubKey(pubkey1)); | ||||
BOOST_CHECK(!key2C.VerifyPubKey(pubkey1C)); | BOOST_CHECK(!key2C.VerifyPubKey(pubkey1C)); | ||||
BOOST_CHECK(!key2C.VerifyPubKey(pubkey2)); | BOOST_CHECK(!key2C.VerifyPubKey(pubkey2)); | ||||
BOOST_CHECK(key2C.VerifyPubKey(pubkey2C)); | BOOST_CHECK(key2C.VerifyPubKey(pubkey2C)); | ||||
BOOST_CHECK(addr1.Get() == CTxDestination(pubkey1.GetID())); | BOOST_CHECK(DecodeDestination(addr1) == CTxDestination(pubkey1.GetID())); | ||||
BOOST_CHECK(addr2.Get() == CTxDestination(pubkey2.GetID())); | BOOST_CHECK(DecodeDestination(addr2) == CTxDestination(pubkey2.GetID())); | ||||
BOOST_CHECK(addr1C.Get() == CTxDestination(pubkey1C.GetID())); | BOOST_CHECK(DecodeDestination(addr1C) == CTxDestination(pubkey1C.GetID())); | ||||
BOOST_CHECK(addr2C.Get() == CTxDestination(pubkey2C.GetID())); | BOOST_CHECK(DecodeDestination(addr2C) == CTxDestination(pubkey2C.GetID())); | ||||
for (int n = 0; n < 16; n++) { | for (int n = 0; n < 16; n++) { | ||||
std::string strMsg = strprintf("Very secret message %i: 11", n); | std::string strMsg = strprintf("Very secret message %i: 11", n); | ||||
uint256 hashMsg = Hash(strMsg.begin(), strMsg.end()); | uint256 hashMsg = Hash(strMsg.begin(), strMsg.end()); | ||||
// normal signatures | // normal signatures | ||||
std::vector<uint8_t> sign1, sign2, sign1C, sign2C; | std::vector<uint8_t> sign1, sign2, sign1C, sign2C; | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |