From 6e723d2ab70678c1092ae2ba8d8dc2f4d8017262 Mon Sep 17 00:00:00 2001 From: josibake Date: Tue, 16 Jul 2024 17:42:32 +0200 Subject: [PATCH] tests: add tests for KeyPair Reuse existing BIP340 tests, as there should be no behavior change between the two --- src/test/key_tests.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp index 13dde7673b6d6..dc7a718c37fbc 100644 --- a/src/test/key_tests.cpp +++ b/src/test/key_tests.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -299,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(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. @@ -312,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)); } } }