diff options
author | josibake <josibake@protonmail.com> | 2024-07-16 17:42:32 +0200 |
---|---|---|
committer | josibake <josibake@protonmail.com> | 2024-08-04 08:52:21 +0200 |
commit | 72a5822d43d47431b2838ebfcb1f2e21210f5ccb (patch) | |
tree | 23a999429fa3eb7877cf9ee1826578a21b9e93e3 /src/test/key_tests.cpp | |
parent | cebb08b121ce8c4c5e68bd043b8668c106e31169 (diff) |
tests: add tests for KeyPair
Reuse existing BIP340 tests, as there should be
no behavior change between the two
Diffstat (limited to 'src/test/key_tests.cpp')
-rw-r--r-- | src/test/key_tests.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp index 6714d8445b..112d6db193 100644 --- a/src/test/key_tests.cpp +++ b/src/test/key_tests.cpp @@ -300,6 +300,13 @@ BOOST_AUTO_TEST_CASE(bip340_test_vectors) // Verify those signatures for good measure. BOOST_CHECK(pubkey.VerifySchnorr(msg256, sig64)); + // Repeat the same check, but use the KeyPair directly without any merkle tweak + KeyPair keypair = key.ComputeKeyPair(/*merkle_root=*/nullptr); + bool kp_ok = keypair.SignSchnorr(msg256, sig64, aux256); + BOOST_CHECK(kp_ok); + BOOST_CHECK(pubkey.VerifySchnorr(msg256, sig64)); + BOOST_CHECK(std::vector<unsigned char>(sig64, sig64 + 64) == sig); + // Do 10 iterations where we sign with a random Merkle root to tweak, // and compare against the resulting tweaked keys, with random aux. // In iteration i=0 we tweak with empty Merkle tree. @@ -313,6 +320,12 @@ BOOST_AUTO_TEST_CASE(bip340_test_vectors) bool ok = key.SignSchnorr(msg256, sig64, &merkle_root, aux256); BOOST_CHECK(ok); BOOST_CHECK(tweaked_key.VerifySchnorr(msg256, sig64)); + + // Repeat the same check, but use the KeyPair class directly + KeyPair keypair = key.ComputeKeyPair(&merkle_root); + bool kp_ok = keypair.SignSchnorr(msg256, sig64, aux256); + BOOST_CHECK(kp_ok); + BOOST_CHECK(tweaked_key.VerifySchnorr(msg256, sig64)); } } } |