Skip to content

Commit

Permalink
Unit test for ellswift creation/decoding roundtrip
Browse files Browse the repository at this point in the history
Co-authored-by: Pieter Wuille <bitcoin-dev@wuille.net>
  • Loading branch information
2 people authored and sipa committed Jun 23, 2023
1 parent eff72a0 commit aae432a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/key_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit aae432a

Please sign in to comment.