Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/util.cpp
Show All 11 Lines | |||||
#include <validation.h> | #include <validation.h> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
#include <limits> | #include <limits> | ||||
namespace avalanche { | namespace avalanche { | ||||
std::shared_ptr<Proof> buildRandomProof(uint32_t score, const CKey &masterKey) { | ProofRef buildRandomProof(uint32_t score, const CKey &masterKey) { | ||||
auto key = CKey::MakeCompressedKey(); | auto key = CKey::MakeCompressedKey(); | ||||
const COutPoint o(TxId(GetRandHash()), 0); | const COutPoint o(TxId(GetRandHash()), 0); | ||||
const Amount v = (int64_t(score) * COIN) / 100; | const Amount v = (int64_t(score) * COIN) / 100; | ||||
const int height = 1234; | const int height = 1234; | ||||
const bool is_coinbase = false; | const bool is_coinbase = false; | ||||
{ | { | ||||
CScript script = GetScriptForDestination(PKHash(key.GetPubKey())); | CScript script = GetScriptForDestination(PKHash(key.GetPubKey())); | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CCoinsViewCache &coins = ::ChainstateActive().CoinsTip(); | CCoinsViewCache &coins = ::ChainstateActive().CoinsTip(); | ||||
coins.AddCoin(o, Coin(CTxOut(v, script), height, is_coinbase), false); | coins.AddCoin(o, Coin(CTxOut(v, script), height, is_coinbase), false); | ||||
} | } | ||||
ProofBuilder pb(0, std::numeric_limits<uint32_t>::max(), masterKey); | ProofBuilder pb(0, std::numeric_limits<uint32_t>::max(), masterKey); | ||||
BOOST_CHECK(pb.addUTXO(o, v, height, is_coinbase, std::move(key))); | BOOST_CHECK(pb.addUTXO(o, v, height, is_coinbase, std::move(key))); | ||||
return std::make_shared<Proof>(pb.build()); | return std::make_shared<Proof>(pb.build()); | ||||
} | } | ||||
bool hasDustStake(const std::shared_ptr<Proof> &proof) { | bool hasDustStake(const ProofRef &proof) { | ||||
for (const SignedStake &s : proof->getStakes()) { | for (const SignedStake &s : proof->getStakes()) { | ||||
if (s.getStake().getAmount() < PROOF_DUST_THRESHOLD) { | if (s.getStake().getAmount() < PROOF_DUST_THRESHOLD) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |