aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordhruv <856960+dhruv@users.noreply.github.com>2023-04-17 18:04:11 -0400
committerPieter Wuille <pieter@wuille.net>2023-06-23 14:22:39 -0400
commitaae432a764e4ceb7eac305458e585726225c7189 (patch)
tree775822b0f5a0f029f10c9dd76b32188e977f3a07
parenteff72a0dff8fa83af873ad9b15dbac50b8d4eca3 (diff)
downloadbitcoin-aae432a764e4ceb7eac305458e585726225c7189.tar.xz
Unit test for ellswift creation/decoding roundtrip
Co-authored-by: Pieter Wuille <bitcoin-dev@wuille.net>
-rw-r--r--src/test/key_tests.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp
index 8f11bf5db2..86a8d17a76 100644
--- a/src/test/key_tests.cpp
+++ b/src/test/key_tests.cpp
@@ -344,4 +344,24 @@ BOOST_AUTO_TEST_CASE(bip340_test_vectors)
}
}
+BOOST_AUTO_TEST_CASE(key_ellswift)
+{
+ for (const auto& secret : {strSecret1, strSecret2, strSecret1C, strSecret2C}) {
+ CKey key = DecodeSecret(secret);
+ BOOST_CHECK(key.IsValid());
+
+ uint256 ent32 = InsecureRand256();
+ auto ellswift = key.EllSwiftCreate(AsBytes(Span{ent32}));
+
+ CPubKey decoded_pubkey = ellswift.Decode();
+ if (!key.IsCompressed()) {
+ // The decoding constructor returns a compressed pubkey. If the
+ // original was uncompressed, we must decompress the decoded one
+ // to compare.
+ decoded_pubkey.Decompress();
+ }
+ BOOST_CHECK(key.GetPubKey() == decoded_pubkey);
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()