diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2023-09-12 03:35:40 +0200 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2023-12-23 13:26:00 +0100 |
commit | fa1d49542e4b69a5d8b1177ffe4207f051a468bb (patch) | |
tree | 9c2cf8f46ea9d058c7c1c38d7244eb8eefc3b6fd /src/test/script_tests.cpp | |
parent | 4b1196a9855dcd188a24f393aa2fa21e2d61f061 (diff) | |
download | bitcoin-fa1d49542e4b69a5d8b1177ffe4207f051a468bb.tar.xz |
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/script_tests.cpp')
-rw-r--r-- | src/test/script_tests.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index e988ce2194..1f674408b2 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -1051,10 +1051,9 @@ sign_multisig(const CScript& scriptPubKey, const CKey& key, const CTransaction& BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG12) { ScriptError err; - CKey key1, key2, key3; - key1.MakeNewKey(true); - key2.MakeNewKey(false); - key3.MakeNewKey(true); + CKey key1 = GenerateRandomKey(); + CKey key2 = GenerateRandomKey(/*compressed=*/false); + CKey key3 = GenerateRandomKey(); CScript scriptPubKey12; scriptPubKey12 << OP_1 << ToByteVector(key1.GetPubKey()) << ToByteVector(key2.GetPubKey()) << OP_2 << OP_CHECKMULTISIG; @@ -1081,11 +1080,10 @@ BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG12) BOOST_AUTO_TEST_CASE(script_CHECKMULTISIG23) { ScriptError err; - CKey key1, key2, key3, key4; - key1.MakeNewKey(true); - key2.MakeNewKey(false); - key3.MakeNewKey(true); - key4.MakeNewKey(false); + CKey key1 = GenerateRandomKey(); + CKey key2 = GenerateRandomKey(/*compressed=*/false); + CKey key3 = GenerateRandomKey(); + CKey key4 = GenerateRandomKey(/*compressed=*/false); CScript scriptPubKey23; scriptPubKey23 << OP_2 << ToByteVector(key1.GetPubKey()) << ToByteVector(key2.GetPubKey()) << ToByteVector(key3.GetPubKey()) << OP_3 << OP_CHECKMULTISIG; @@ -1165,8 +1163,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs) std::vector<CPubKey> pubkeys; for (int i = 0; i < 3; i++) { - CKey key; - key.MakeNewKey(i%2 == 1); + CKey key = GenerateRandomKey(/*compressed=*/i%2 == 1); keys.push_back(key); pubkeys.push_back(key.GetPubKey()); BOOST_CHECK(keystore.AddKey(key)); |