aboutsummaryrefslogtreecommitdiff
path: root/src/test/key_tests.cpp
diff options
context:
space:
mode:
authorJonas Schnelli <dev@jonasschnelli.ch>2018-08-24 11:04:44 +0200
committerJonas Schnelli <dev@jonasschnelli.ch>2019-03-27 13:59:53 +0100
commit3b64f852e400c552f031697d6a86829dc6e74bd6 (patch)
tree536bb3d5f4a7f8aecdee7055c318e85102a4bcac /src/test/key_tests.cpp
parent463921bb649d644f79f9d7f0f96f10aa0d165f76 (diff)
downloadbitcoin-3b64f852e400c552f031697d6a86829dc6e74bd6.tar.xz
QA: add test for CKey::Negate()
Diffstat (limited to 'src/test/key_tests.cpp')
-rw-r--r--src/test/key_tests.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp
index a768b4bcbd..3d8f64e115 100644
--- a/src/test/key_tests.cpp
+++ b/src/test/key_tests.cpp
@@ -188,4 +188,36 @@ BOOST_AUTO_TEST_CASE(key_signature_tests)
BOOST_CHECK(found_small);
}
+BOOST_AUTO_TEST_CASE(key_key_negation)
+{
+ // create a dummy hash for signature comparison
+ unsigned char rnd[8];
+ std::string str = "Bitcoin key verification\n";
+ GetRandBytes(rnd, sizeof(rnd));
+ uint256 hash;
+ CHash256().Write((unsigned char*)str.data(), str.size()).Write(rnd, sizeof(rnd)).Finalize(hash.begin());
+
+ // import the static test key
+ CKey key = DecodeSecret(strSecret1C);
+
+ // create a signature
+ std::vector<unsigned char> vch_sig;
+ std::vector<unsigned char> vch_sig_cmp;
+ key.Sign(hash, vch_sig);
+
+ // negate the key twice
+ BOOST_CHECK(key.GetPubKey().data()[0] == 0x03);
+ key.Negate();
+ // after the first negation, the signature must be different
+ key.Sign(hash, vch_sig_cmp);
+ BOOST_CHECK(vch_sig_cmp != vch_sig);
+ BOOST_CHECK(key.GetPubKey().data()[0] == 0x02);
+ key.Negate();
+ // after the second negation, we should have the original key and thus the
+ // same signature
+ key.Sign(hash, vch_sig_cmp);
+ BOOST_CHECK(vch_sig_cmp == vch_sig);
+ BOOST_CHECK(key.GetPubKey().data()[0] == 0x03);
+}
+
BOOST_AUTO_TEST_SUITE_END()