aboutsummaryrefslogtreecommitdiff
path: root/src/test/transaction_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/transaction_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/transaction_tests.cpp')
-rw-r--r--src/test/transaction_tests.cpp28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
index 5329c6ac99..d1cb2531aa 100644
--- a/src/test/transaction_tests.cpp
+++ b/src/test/transaction_tests.cpp
@@ -487,8 +487,7 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction)
CMutableTransaction mtx;
mtx.nVersion = 1;
- CKey key;
- key.MakeNewKey(true); // Need to use compressed keys in segwit or the signing will fail
+ CKey key = GenerateRandomKey(); // Need to use compressed keys in segwit or the signing will fail
FillableSigningProvider keystore;
BOOST_CHECK(keystore.AddKeyPubKey(key, key.GetPubKey()));
CKeyID hash = key.GetPubKey().GetID();
@@ -564,18 +563,16 @@ SignatureData CombineSignatures(const CMutableTransaction& input1, const CMutabl
BOOST_AUTO_TEST_CASE(test_witness)
{
FillableSigningProvider keystore, keystore2;
- CKey key1, key2, key3, key1L, key2L;
- CPubKey pubkey1, pubkey2, pubkey3, pubkey1L, pubkey2L;
- key1.MakeNewKey(true);
- key2.MakeNewKey(true);
- key3.MakeNewKey(true);
- key1L.MakeNewKey(false);
- key2L.MakeNewKey(false);
- pubkey1 = key1.GetPubKey();
- pubkey2 = key2.GetPubKey();
- pubkey3 = key3.GetPubKey();
- pubkey1L = key1L.GetPubKey();
- pubkey2L = key2L.GetPubKey();
+ CKey key1 = GenerateRandomKey();
+ CKey key2 = GenerateRandomKey();
+ CKey key3 = GenerateRandomKey();
+ CKey key1L = GenerateRandomKey(/*compressed=*/false);
+ CKey key2L = GenerateRandomKey(/*compressed=*/false);
+ CPubKey pubkey1 = key1.GetPubKey();
+ CPubKey pubkey2 = key2.GetPubKey();
+ CPubKey pubkey3 = key3.GetPubKey();
+ CPubKey pubkey1L = key1L.GetPubKey();
+ CPubKey pubkey2L = key2L.GetPubKey();
BOOST_CHECK(keystore.AddKeyPubKey(key1, pubkey1));
BOOST_CHECK(keystore.AddKeyPubKey(key2, pubkey2));
BOOST_CHECK(keystore.AddKeyPubKey(key1L, pubkey1L));
@@ -756,8 +753,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
t.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
t.vout.resize(1);
t.vout[0].nValue = 90*CENT;
- CKey key;
- key.MakeNewKey(true);
+ CKey key = GenerateRandomKey();
t.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
constexpr auto CheckIsStandard = [](const auto& t) {