diff --git a/src/avalanche/proofbuilder.cpp b/src/avalanche/proofbuilder.cpp --- a/src/avalanche/proofbuilder.cpp +++ b/src/avalanche/proofbuilder.cpp @@ -64,12 +64,9 @@ } Proof ProofBuilder::buildRandom(uint32_t score) { - CKey key; - key.MakeNewKey(true); - ProofBuilder pb(0, std::numeric_limits::max(), CPubKey()); pb.addUTXO(COutPoint(TxId(GetRandHash()), 0), (int64_t(score) * COIN) / 100, - 0, false, std::move(key)); + 0, false, CKey{true}); return pb.build(); } diff --git a/src/avalanche/test/delegation_tests.cpp b/src/avalanche/test/delegation_tests.cpp --- a/src/avalanche/test/delegation_tests.cpp +++ b/src/avalanche/test/delegation_tests.cpp @@ -31,8 +31,7 @@ } BOOST_AUTO_TEST_CASE(verify_random) { - CKey key; - key.MakeNewKey(true); + CKey key{true}; const Proof p = buildRandomProof(123456, key.GetPubKey()); DelegationBuilder dgb(p); @@ -43,15 +42,13 @@ CheckDelegation(dg, p, p.getMaster()); } - CKey l1key; - l1key.MakeNewKey(true); + CKey l1key{true}; BOOST_CHECK(!dgb.addLevel(l1key, key.GetPubKey())); dgb.addLevel(key, l1key.GetPubKey()); CheckDelegation(dgb.build(), p, l1key.GetPubKey()); - CKey l2key; - l2key.MakeNewKey(true); + CKey l2key{true}; BOOST_CHECK(!dgb.addLevel(key, l2key.GetPubKey())); BOOST_CHECK(!dgb.addLevel(l2key, l2key.GetPubKey())); diff --git a/src/avalanche/test/orphanproofpool_tests.cpp b/src/avalanche/test/orphanproofpool_tests.cpp --- a/src/avalanche/test/orphanproofpool_tests.cpp +++ b/src/avalanche/test/orphanproofpool_tests.cpp @@ -22,12 +22,10 @@ static std::shared_ptr makeProof(const size_t nStakes) { const Amount v = 5 * COIN; const int height = 1234; - CKey key; - key.MakeNewKey(true); ProofBuilder pb(0, 0, CPubKey()); for (size_t i = 0; i < nStakes; i++) { TxId txid(GetRandHash()); - pb.addUTXO(COutPoint(txid, 0), v, height, false, key); + pb.addUTXO(COutPoint(txid, 0), v, height, false, CKey{true}); } return std::make_shared(pb.build()); } diff --git a/src/avalanche/test/peermanager_tests.cpp b/src/avalanche/test/peermanager_tests.cpp --- a/src/avalanche/test/peermanager_tests.cpp +++ b/src/avalanche/test/peermanager_tests.cpp @@ -459,8 +459,7 @@ avalanche::PeerManager pm; ProofBuilder pb(0, 0, CPubKey()); - CKey key; - key.MakeNewKey(true); + CKey key{true}; const CScript script = GetScriptForDestination(PKHash(key.GetPubKey())); COutPoint utxo(TxId(GetRandHash()), 0); Amount amount = 1 * COIN; @@ -523,8 +522,7 @@ } BOOST_AUTO_TEST_CASE(proof_conflict) { - CKey key; - key.MakeNewKey(true); + CKey key{true}; const CScript script = GetScriptForDestination(PKHash(key.GetPubKey())); TxId txid1(GetRandHash()); @@ -598,8 +596,7 @@ BOOST_AUTO_TEST_CASE(orphan_proofs) { avalanche::PeerManager pm; - CKey key; - key.MakeNewKey(true); + CKey key{true}; const CScript script = GetScriptForDestination(PKHash(key.GetPubKey())); COutPoint outpoint1 = COutPoint(TxId(GetRandHash()), 0); diff --git a/src/avalanche/test/processor_tests.cpp b/src/avalanche/test/processor_tests.cpp --- a/src/avalanche/test/processor_tests.cpp +++ b/src/avalanche/test/processor_tests.cpp @@ -69,10 +69,11 @@ std::unique_ptr m_processor; + // The master private key we delegate to. CKey masterpriv; AvalancheTestingSetup() - : TestChain100Setup(), config(GetConfig()), masterpriv() { + : TestChain100Setup(), config(GetConfig()), masterpriv(true) { // Deterministic randomness for tests. auto connman = std::make_unique(config, 0x1337, 0x1337); m_connman = connman.get(); @@ -87,9 +88,6 @@ m_processor = Processor::MakeProcessor(*m_node.args, *m_node.chain, m_node.connman.get(), error); BOOST_CHECK(m_processor); - - // The master private key we delegate to. - masterpriv.MakeNewKey(true); } ~AvalancheTestingSetup() { diff --git a/src/avalanche/test/proof_tests.cpp b/src/avalanche/test/proof_tests.cpp --- a/src/avalanche/test/proof_tests.cpp +++ b/src/avalanche/test/proof_tests.cpp @@ -38,10 +38,8 @@ } BOOST_AUTO_TEST_CASE(proofbuilder) { - CKey key; - // Master key. - key.MakeNewKey(true); + CKey key{true}; const CPubKey master = key.GetPubKey(); const uint64_t sequence = InsecureRandBits(64); @@ -328,8 +326,7 @@ CCoinsView coinsDummy; CCoinsViewCache coins(&coinsDummy); - CKey key; - key.MakeNewKey(true); + CKey key{true}; const CPubKey pubkey = key.GetPubKey(); const Amount value = 12345 * COIN; @@ -398,10 +395,8 @@ // Mismatching key { - CKey altkey; - altkey.MakeNewKey(true); runCheck(ProofValidationResult::DESTINATION_MISMATCH, pkh_outpoint, - value, height, false, altkey); + value, height, false, CKey{true}); } // No stake diff --git a/src/avalanche/test/util.cpp b/src/avalanche/test/util.cpp --- a/src/avalanche/test/util.cpp +++ b/src/avalanche/test/util.cpp @@ -16,8 +16,7 @@ namespace avalanche { Proof buildRandomProof(uint32_t score, const CPubKey &master) { - CKey key; - key.MakeNewKey(true); + CKey key{true}; const COutPoint o(TxId(GetRandHash()), 0); const Amount v = (int64_t(score) * COIN) / 100; diff --git a/src/key.h b/src/key.h --- a/src/key.h +++ b/src/key.h @@ -61,6 +61,8 @@ // Important: vch must be 32 bytes in length to not break serialization keydata.resize(32); } + //! Syntactic sugar for constructing a valid key + CKey(bool isCompressed) : CKey() { this->MakeNewKey(isCompressed); } friend bool operator==(const CKey &a, const CKey &b) { return a.fCompressed == b.fCompressed && a.size() == b.size() &&