@ -16,14 +16,10 @@
@@ -16,14 +16,10 @@
# include <boost/test/unit_test.hpp>
static const std : : string strSecret1 = " 6uGFQ4DSW7zh1viHZi6iiVT17CncvoaV4MHvGvJKPDaLCdymj87 " ;
static const std : : string strSecret2 = " 6vVo7sPkeLTwVdAntrv4Gbnsyr75H8ChD3P5iyHziwaqe8mCYR5 " ;
static const std : : string strSecret1C = " T3gJYmBuZXsdd65E7NQF88ZmUP2MaUanqnZg9GFS94W7kND4Ebjq " ;
static const std : : string strSecret2C = " T986ZKRRdnuuXLeDZuKBRrZW1ujotAncU9WTrFU1n7vMgRW75ZtF " ;
static const std : : string addr1 = " LiUo6Zn39joYJBzPUhssbDwAywhjFcoHE3 " ;
static const std : : string addr2 = " LZJvLSP5SGKcFS13MHgdrVhpFUbEMB5XVC " ;
static const std : : string addr1C = " Lh2G82Bi33RNuzz4UfSMZbh54jnWHVnmw8 " ;
static const std : : string addr2C = " LWegHWHB5rmaF5rgWYt1YN3StapRdnGJfU " ;
static const std : : string strSecret1C = " MdT1ZhNgpaNhvtcobunP8MHdxbBB1HLUf1FJAUkEmQqtSLtjCCo4 " ;
static const std : : string strSecret2C = " MesUJk4iXuXdau3LgYX1Se1VPzFyGkm9S4MEPRfXrYnqmaRySqDV " ;
static const std : : string addr1C = " VRwo4qgyARQSy331bhyBPrdbp9pjgjPZiC " ;
static const std : : string addr2C = " VMJySeGqf5o9YNkw6ma5GGWYTL5Z4Kuisw " ;
static const std : : string strAddressBad = " Lbi6bpMhSwp2CXkivEeUK9wzyQEFzHDfSr " ;
@ -32,51 +28,31 @@ BOOST_FIXTURE_TEST_SUITE(key_tests, BasicTestingSetup)
@@ -32,51 +28,31 @@ BOOST_FIXTURE_TEST_SUITE(key_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE ( key_test1 )
{
CBitcoinSecret bsecret1 , bsecret2 , bsecret1C , bsecret2C , baddress1 ;
BOOST_CHECK ( bsecret1 . SetString ( strSecret1 ) ) ;
BOOST_CHECK ( bsecret2 . SetString ( strSecret2 ) ) ;
CBitcoinSecret bsecret1C , bsecret2C , baddress1 ;
BOOST_CHECK ( bsecret1C . SetString ( strSecret1C ) ) ;
BOOST_CHECK ( bsecret2C . SetString ( strSecret2C ) ) ;
BOOST_CHECK ( ! baddress1 . SetString ( strAddressBad ) ) ;
CKey key1 = bsecret1 . GetKey ( ) ;
BOOST_CHECK ( key1 . IsCompressed ( ) = = false ) ;
CKey key2 = bsecret2 . GetKey ( ) ;
BOOST_CHECK ( key2 . IsCompressed ( ) = = false ) ;
CKey key1C = bsecret1C . GetKey ( ) ;
BOOST_CHECK ( key1C . IsCompressed ( ) = = true ) ;
CKey key2C = bsecret2C . GetKey ( ) ;
BOOST_CHECK ( key2C . IsCompressed ( ) = = true ) ;
CPubKey pubkey1 = key1 . GetPubKey ( ) ;
CPubKey pubkey2 = key2 . GetPubKey ( ) ;
CPubKey pubkey1C = key1C . GetPubKey ( ) ;
CPubKey pubkey2C = key2C . GetPubKey ( ) ;
BOOST_CHECK ( key1 . VerifyPubKey ( pubkey1 ) ) ;
BOOST_CHECK ( ! key1 . VerifyPubKey ( pubkey1C ) ) ;
BOOST_CHECK ( ! key1 . VerifyPubKey ( pubkey2 ) ) ;
BOOST_CHECK ( ! key1 . VerifyPubKey ( pubkey2C ) ) ;
BOOST_CHECK ( ! key1C . VerifyPubKey ( pubkey1 ) ) ;
BOOST_CHECK ( key1C . VerifyPubKey ( pubkey1C ) ) ;
BOOST_CHECK ( ! key1C . VerifyPubKey ( pubkey2 ) ) ;
BOOST_CHECK ( ! key1C . VerifyPubKey ( pubkey2C ) ) ;
BOOST_CHECK ( ! key2 . VerifyPubKey ( pubkey1 ) ) ;
BOOST_CHECK ( ! key2 . VerifyPubKey ( pubkey1C ) ) ;
BOOST_CHECK ( key2 . VerifyPubKey ( pubkey2 ) ) ;
BOOST_CHECK ( ! key2 . VerifyPubKey ( pubkey2C ) ) ;
BOOST_CHECK ( ! key2C . VerifyPubKey ( pubkey1 ) ) ;
BOOST_CHECK ( ! key2C . VerifyPubKey ( pubkey1C ) ) ;
BOOST_CHECK ( ! key2C . VerifyPubKey ( pubkey2 ) ) ;
BOOST_CHECK ( key2C . VerifyPubKey ( pubkey2C ) ) ;
BOOST_CHECK ( DecodeDestination ( addr1 ) = = CTxDestination ( pubkey1 . GetID ( ) ) ) ;
BOOST_CHECK ( DecodeDestination ( addr2 ) = = CTxDestination ( pubkey2 . GetID ( ) ) ) ;
#if 0
// Kevacoin: addr1C is Script-hash-addresses, cannot be compared
// to legacy public key hash.
BOOST_CHECK ( DecodeDestination ( addr1C ) = = CTxDestination ( pubkey1C . GetID ( ) ) ) ;
BOOST_CHECK ( DecodeDestination ( addr2C ) = = CTxDestination ( pubkey2C . GetID ( ) ) ) ;
# endif
for ( int n = 0 ; n < 16 ; n + + )
{
@ -85,76 +61,46 @@ BOOST_AUTO_TEST_CASE(key_test1)
@@ -85,76 +61,46 @@ BOOST_AUTO_TEST_CASE(key_test1)
// normal signatures
std : : vector < unsigned char > sign1 , sign2 , sign1 C, sign2C ;
std : : vector < unsigned char > sign1C , sign2C ;
BOOST_CHECK ( key1 . Sign ( hashMsg , sign1 ) ) ;
BOOST_CHECK ( key2 . Sign ( hashMsg , sign2 ) ) ;
BOOST_CHECK ( key1C . Sign ( hashMsg , sign1C ) ) ;
BOOST_CHECK ( key2C . Sign ( hashMsg , sign2C ) ) ;
BOOST_CHECK ( pubkey1 . Verify ( hashMsg , sign1 ) ) ;
BOOST_CHECK ( ! pubkey1 . Verify ( hashMsg , sign2 ) ) ;
BOOST_CHECK ( pubkey1 . Verify ( hashMsg , sign1C ) ) ;
BOOST_CHECK ( ! pubkey1 . Verify ( hashMsg , sign2C ) ) ;
BOOST_CHECK ( ! pubkey2 . Verify ( hashMsg , sign1 ) ) ;
BOOST_CHECK ( pubkey2 . Verify ( hashMsg , sign2 ) ) ;
BOOST_CHECK ( ! pubkey2 . Verify ( hashMsg , sign1C ) ) ;
BOOST_CHECK ( pubkey2 . Verify ( hashMsg , sign2C ) ) ;
BOOST_CHECK ( pubkey1C . Verify ( hashMsg , sign1 ) ) ;
BOOST_CHECK ( ! pubkey1C . Verify ( hashMsg , sign2 ) ) ;
BOOST_CHECK ( pubkey1C . Verify ( hashMsg , sign1C ) ) ;
BOOST_CHECK ( ! pubkey1C . Verify ( hashMsg , sign2C ) ) ;
BOOST_CHECK ( ! pubkey2C . Verify ( hashMsg , sign1 ) ) ;
BOOST_CHECK ( pubkey2C . Verify ( hashMsg , sign2 ) ) ;
BOOST_CHECK ( ! pubkey2C . Verify ( hashMsg , sign1C ) ) ;
BOOST_CHECK ( pubkey2C . Verify ( hashMsg , sign2C ) ) ;
// compact signatures (with key recovery)
std : : vector < unsigned char > csign1 , csign2 , csign1 C, csign2C ;
std : : vector < unsigned char > csign1C , csign2C ;
BOOST_CHECK ( key1 . SignCompact ( hashMsg , csign1 ) ) ;
BOOST_CHECK ( key2 . SignCompact ( hashMsg , csign2 ) ) ;
BOOST_CHECK ( key1C . SignCompact ( hashMsg , csign1C ) ) ;
BOOST_CHECK ( key2C . SignCompact ( hashMsg , csign2C ) ) ;
CPubKey rkey1 , rkey2 , rkey1 C, rkey2C ;
CPubKey rkey1C , rkey2C ;
BOOST_CHECK ( rkey1 . RecoverCompact ( hashMsg , csign1 ) ) ;
BOOST_CHECK ( rkey2 . RecoverCompact ( hashMsg , csign2 ) ) ;
BOOST_CHECK ( rkey1C . RecoverCompact ( hashMsg , csign1C ) ) ;
BOOST_CHECK ( rkey2C . RecoverCompact ( hashMsg , csign2C ) ) ;
BOOST_CHECK ( rkey1 = = pubkey1 ) ;
BOOST_CHECK ( rkey2 = = pubkey2 ) ;
BOOST_CHECK ( rkey1C = = pubkey1C ) ;
BOOST_CHECK ( rkey2C = = pubkey2C ) ;
}
// test deterministic signing
std : : vector < unsigned char > detsig , detsig c;
std : : vector < unsigned char > detsigc ;
std : : string strMsg = " Very deterministic message " ;
uint256 hashMsg = Hash ( strMsg . begin ( ) , strMsg . end ( ) ) ;
BOOST_CHECK ( key1 . Sign ( hashMsg , detsig ) ) ;
BOOST_CHECK ( key1C . Sign ( hashMsg , detsigc ) ) ;
BOOST_CHECK ( detsig = = detsigc ) ;
BOOST_CHECK ( detsig = = ParseHex ( " 304402205dbbddda71772d95ce91cd2d14b592cfbc1dd0aabd6a394b6c2d377bbe59d31d022014ddda21494a4e221f0824f0b8b924c43fa43c0ad57dccdaa11f81a6bd4582f6 " ) ) ;
BOOST_CHECK ( key2 . Sign ( hashMsg , detsig ) ) ;
BOOST_CHECK ( detsigc = = ParseHex ( " 304402201e5a963b63e4b7f4a22ab47080fa745e313d722e92e1c38127f6675cbac4851d02205a5e67b5c1f72a496424a33e68692af9373e94ffcafbc39e4270dbd5017f078a " ) ) ;
BOOST_CHECK ( key2C . Sign ( hashMsg , detsigc ) ) ;
BOOST_CHECK ( detsig = = detsigc ) ;
BOOST_CHECK ( detsig = = ParseHex ( " 3044022052d8a32079c11e79db95af63bb9600c5b04f21a9ca33dc129c2bfa8ac9dc1cd5022061d8ae5e0f6c1a16bde3719c64c2fd70e404b6428ab9a69566962e8771b5944d " ) ) ;
BOOST_CHECK ( key1 . SignCompact ( hashMsg , detsig ) ) ;
BOOST_CHECK ( detsigc = = ParseHex ( " 3044022041d16f2e09478c24599a94710a12025f77431af913d9322f9baeac5d810d968f022056cc1b07e17b4f803454cbe3d842168ac4b04d676dfd18d601079b662c1df443 " ) ) ;
BOOST_CHECK ( key1C . SignCompact ( hashMsg , detsigc ) ) ;
BOOST_CHECK ( detsig = = ParseHex ( " 1c5dbbddda71772d95ce91cd2d14b592cfbc1dd0aabd6a394b6c2d377bbe59d31d14ddda21494a4e221f0824f0b8b924c43fa43c0ad57dccdaa11f81a6bd4582f6 " ) ) ;
BOOST_CHECK ( detsigc = = ParseHex ( " 205dbbddda71772d95ce91cd2d14b592cfbc1dd0aabd6a394b6c2d377bbe59d31d14ddda21494a4e221f0824f0b8b924c43fa43c0ad57dccdaa11f81a6bd4582f6 " ) ) ;
BOOST_CHECK ( key2 . SignCompact ( hashMsg , detsig ) ) ;
BOOST_CHECK ( detsigc = = ParseHex ( " 1f1e5a963b63e4b7f4a22ab47080fa745e313d722e92e1c38127f6675cbac4851d5a5e67b5c1f72a496424a33e68692af9373e94ffcafbc39e4270dbd5017f078a " ) ) ;
BOOST_CHECK ( key2C . SignCompact ( hashMsg , detsigc ) ) ;
BOOST_CHECK ( detsig = = ParseHex ( " 1c52d8a32079c11e79db95af63bb9600c5b04f21a9ca33dc129c2bfa8ac9dc1cd561d8ae5e0f6c1a16bde3719c64c2fd70e404b6428ab9a69566962e8771b5944d " ) ) ;
BOOST_CHECK ( detsigc = = ParseHex ( " 2052d8a32079c11e79db95af63bb9600c5b04f21a9ca33dc129c2bfa8ac9dc1cd561d8ae5e0f6c1a16bde3719c64c2fd70e404b6428ab9a69566962e8771b5944d " ) ) ;
BOOST_CHECK ( detsigc = = ParseHex ( " 2041d16f2e09478c24599a94710a12025f77431af913d9322f9baeac5d810d968f56cc1b07e17b4f803454cbe3d842168ac4b04d676dfd18d601079b662c1df443 " ) ) ;
}
BOOST_AUTO_TEST_SUITE_END ( )