aboutsummaryrefslogtreecommitdiff
path: root/src/test/compress_tests.cpp
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-09-12 03:35:40 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-12-23 13:26:00 +0100
commitfa1d49542e4b69a5d8b1177ffe4207f051a468bb (patch)
tree9c2cf8f46ea9d058c7c1c38d7244eb8eefc3b6fd /src/test/compress_tests.cpp
parent4b1196a9855dcd188a24f393aa2fa21e2d61f061 (diff)
refactor: share and use `GenerateRandomKey` helper
Making the `GenerateRandomKey` helper available to other modules via key.{h.cpp} allows us to create random private keys directly at instantiation of CKey, in contrast to the two-step process of creating the instance and then having to call `MakeNewKey(...)`.
Diffstat (limited to 'src/test/compress_tests.cpp')
-rw-r--r--src/test/compress_tests.cpp9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/test/compress_tests.cpp b/src/test/compress_tests.cpp
index b56629ae40..264b47b07c 100644
--- a/src/test/compress_tests.cpp
+++ b/src/test/compress_tests.cpp
@@ -65,8 +65,7 @@ BOOST_AUTO_TEST_CASE(compress_amounts)
BOOST_AUTO_TEST_CASE(compress_script_to_ckey_id)
{
// case CKeyID
- CKey key;
- key.MakeNewKey(true);
+ CKey key = GenerateRandomKey();
CPubKey pubkey = key.GetPubKey();
CScript script = CScript() << OP_DUP << OP_HASH160 << ToByteVector(pubkey.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
@@ -101,8 +100,7 @@ BOOST_AUTO_TEST_CASE(compress_script_to_cscript_id)
BOOST_AUTO_TEST_CASE(compress_script_to_compressed_pubkey_id)
{
- CKey key;
- key.MakeNewKey(true); // case compressed PubKeyID
+ CKey key = GenerateRandomKey(); // case compressed PubKeyID
CScript script = CScript() << ToByteVector(key.GetPubKey()) << OP_CHECKSIG; // COMPRESSED_PUBLIC_KEY_SIZE (33)
BOOST_CHECK_EQUAL(script.size(), 35U);
@@ -119,8 +117,7 @@ BOOST_AUTO_TEST_CASE(compress_script_to_compressed_pubkey_id)
BOOST_AUTO_TEST_CASE(compress_script_to_uncompressed_pubkey_id)
{
- CKey key;
- key.MakeNewKey(false); // case uncompressed PubKeyID
+ CKey key = GenerateRandomKey(/*compressed=*/false); // case uncompressed PubKeyID
CScript script = CScript() << ToByteVector(key.GetPubKey()) << OP_CHECKSIG; // PUBLIC_KEY_SIZE (65)
BOOST_CHECK_EQUAL(script.size(), 67U); // 1 char code + 65 char pubkey + OP_CHECKSIG