Skip to content

Commit 72a5822

Browse files
committed
tests: add tests for KeyPair
Reuse existing BIP340 tests, as there should be no behavior change between the two
1 parent cebb08b commit 72a5822

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/test/key_tests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ BOOST_AUTO_TEST_CASE(bip340_test_vectors)
300300
// Verify those signatures for good measure.
301301
BOOST_CHECK(pubkey.VerifySchnorr(msg256, sig64));
302302

303+
// Repeat the same check, but use the KeyPair directly without any merkle tweak
304+
KeyPair keypair = key.ComputeKeyPair(/*merkle_root=*/nullptr);
305+
bool kp_ok = keypair.SignSchnorr(msg256, sig64, aux256);
306+
BOOST_CHECK(kp_ok);
307+
BOOST_CHECK(pubkey.VerifySchnorr(msg256, sig64));
308+
BOOST_CHECK(std::vector<unsigned char>(sig64, sig64 + 64) == sig);
309+
303310
// Do 10 iterations where we sign with a random Merkle root to tweak,
304311
// and compare against the resulting tweaked keys, with random aux.
305312
// In iteration i=0 we tweak with empty Merkle tree.
@@ -313,6 +320,12 @@ BOOST_AUTO_TEST_CASE(bip340_test_vectors)
313320
bool ok = key.SignSchnorr(msg256, sig64, &merkle_root, aux256);
314321
BOOST_CHECK(ok);
315322
BOOST_CHECK(tweaked_key.VerifySchnorr(msg256, sig64));
323+
324+
// Repeat the same check, but use the KeyPair class directly
325+
KeyPair keypair = key.ComputeKeyPair(&merkle_root);
326+
bool kp_ok = keypair.SignSchnorr(msg256, sig64, aux256);
327+
BOOST_CHECK(kp_ok);
328+
BOOST_CHECK(tweaked_key.VerifySchnorr(msg256, sig64));
316329
}
317330
}
318331
}

0 commit comments

Comments
 (0)