15 #include "validation.h"
17 #include <boost/test/unit_test.hpp>
25 std::string strError =
strprintf(
"Budget is not as expected for %s. Result: %s, Expected: %s", strNetwork,
FormatMoney(nBudget),
FormatMoney(nExpectedValue));
26 BOOST_CHECK_MESSAGE(nBudget == nExpectedValue, strError);
79 int nHeight = 100; std::string strError;
81 CAmount nExpectedRet = nBlockReward;
100 const CAmount propAmt = 100 * COIN;
109 nExpectedRet = nBlockReward;
114 nExpectedRet = nBlockReward;
119 nExpectedRet = nBlockReward;
124 nExpectedRet = nBlockReward;
136 nExpectedRet = nBlockReward;
179 CFinalizedBudget fin(
"main (test)", 144, {txBudgetPayment, txBudgetPayment2}, finTxId);
183 std::string strError;
185 BOOST_CHECK(fin.AddOrUpdateVote(fvote1_a, strError));
186 BOOST_CHECK(fin.AddOrUpdateVote(fvote1_b, strError));
190 CFinalizedBudget fin2(
"main2 (test)", 144, {txBudgetPayment2, txBudgetPayment}, finTxId2);
193 BOOST_CHECK(fin2.AddOrUpdateVote(fvote2, strError));
194 BOOST_CHECK(fin2.AddOrUpdateVote(fvote2_a, strError));
201 for (
int i=0; i<43; i++) CreateAndProcessBlock({}, coinbaseKey);
209 const CAmount propAmt1 = 100 * COIN;
211 const CAmount propAmt2 = propAmt1;
214 CBlock block = CreateBlock({}, coinbaseKey);
216 CTxOut payeeOut = block.vtx[0]->vout[1];
226 block.vtx[0] = MakeTransactionRef(mtx);
227 std::shared_ptr<CBlock> pblock =
FinalizeBlock(std::make_shared<CBlock>(block));
228 BOOST_CHECK(block.vtx[0]->vout[1].scriptPubKey != payee1);
235 mtx.
vout[1].nValue *= 2;
236 block.vtx[0] = MakeTransactionRef(mtx);
238 BOOST_CHECK(block.vtx[0]->vout[1].scriptPubKey == payee1);
239 BOOST_CHECK(block.vtx[0]->vout[1].nValue == payeeOut.nValue * 2);
244 mtx.
vout[1].nValue /= 2;
245 block.vtx[0] = MakeTransactionRef(mtx);
247 BOOST_CHECK(block.vtx[0]->vout[1].scriptPubKey == payee1);
248 BOOST_CHECK(block.vtx[0]->vout[1].nValue == payeeOut.nValue / 2);
261 for (
auto fin : vecFin) {
262 if (!secondFin || fin->GetVoteCount() < secondFin->GetVoteCount()) {
269 block.vtx[0] = MakeTransactionRef(mtx);
274 block.vtx[0] = MakeTransactionRef(goodMtx);
283 for (
int i=0; i<43; i++) CreateAndProcessBlock({}, coinbaseKey);
289 const CAmount propAmt = 100 * COIN;
291 const CAmount propAmt2 = propAmt * 2;
306 CBlock blockA = CreateBlock({}, coinbaseKey,
false);
307 CBlock blockB = CreateBlock({}, forkCoinbaseScript,
false);
310 CTxOut payeeOut = blockA.
vtx[0]->vout[1];
313 payeeOut = blockB.vtx[0]->vout[1];
318 auto pblockA = std::make_shared<const CBlock>(blockA);
324 CBlock blockC = CreateBlock({}, coinbaseKey,
false);
326 CBlock blockD = CreateBlock({}, forkCoinbaseScript,
false);
334 std::shared_ptr<CBlock> pblockD =
FinalizeBlock(std::make_shared<CBlock>(blockD));
338 CBlock blockE = CreateBlock({}, forkCoinbaseScript,
false);
340 std::shared_ptr<CBlock> pblockE =
FinalizeBlock(std::make_shared<CBlock>(blockE));
345 static CScript GetRandomP2PKH()
355 tx.
vout.emplace_back(cbaseAmt, cbaseScript);
356 tx.
vin.emplace_back();
365 const CScript& cbaseScript = GetRandomP2PKH();
376 cbase.
vout[0].nValue /= 2;
377 cbase.
vout.emplace_back(cbase.
vout[0]);
382 cbase.
vout.emplace_back(mnAmt - 1, cbaseScript);
384 cbase.
vout[0].nValue = mnAmt/2;
385 cbase.
vout.emplace_back(cbase.
vout[0]);
386 cbase.
vout[1].nValue = mnAmt/2 - 1;
391 cbase.
vout.emplace_back(mnAmt + 1, cbaseScript);
395 cbase.
vout[0].nValue = mnAmt/2;
396 cbase.
vout.emplace_back(cbase.
vout[0]);
397 cbase.
vout[1].nValue = mnAmt/2 + 1;
403 int64_t nTime =
GetTime() - 10;
410 cbase.
vout.emplace_back(mnAmt - 1, cbaseScript);
414 cbase.
vout[0].nValue = mnAmt/2;
415 cbase.
vout.emplace_back(cbase.
vout[0]);
416 cbase.
vout[1].nValue = mnAmt/2 - 1;
423 cbase.
vout.emplace_back(mnAmt + 1, cbaseScript);
427 cbase.
vout[0].nValue = mnAmt/2;
428 cbase.
vout.emplace_back(cbase.
vout[0]);
429 cbase.
vout[1].nValue = mnAmt/2 + 1;
434 const CAmount budgAmt = 200 * COIN;
440 cbase.
vout.emplace_back(budgAmt, cbaseScript);
442 cbase.
vout[0].nValue /= 2;
443 cbase.
vout.emplace_back(cbase.
vout[0]);
448 cbase.
vout.emplace_back(budgAmt - 1, cbaseScript);
452 cbase.
vout[0].nValue = budgAmt/2;
453 cbase.
vout.emplace_back(cbase.
vout[0]);
454 cbase.
vout[1].nValue = budgAmt/2 - 1;
461 cbase.
vout.emplace_back(budgAmt + 1, cbaseScript);
465 cbase.
vout[0].nValue = budgAmt/2;
466 cbase.
vout.emplace_back(cbase.
vout[0]);
467 cbase.
vout[1].nValue = budgAmt/2 + 1;
477 BOOST_ASSERT(sk1 != sk2);
483 uint256 budgetHash1 =
uint256S(
"0000000000000000000000000000000000000000000000000000000000000001");
484 uint256 budgetHash2 =
uint256S(
"0000000000000000000000000000000000010000000000000000000000000001");
500 std::vector<unsigned char> sig = _vote.
GetVchSig();
int64_t CAmount
Amount in PIV (Can be negative)
void ProcessBlockAndCheckRejectionReason(std::shared_ptr< CBlock > &pblock, const std::string &blockRejectionReason, int expectedChainHeight)
BOOST_FIXTURE_TEST_CASE(block_value, TestnetSetup)
BOOST_AUTO_TEST_CASE(masternode_value)
void forceAddFakeProposals(const CTxOut &payee1, const CTxOut &payee2)
1) Create two proposals and two budget finalizations with a different proposal payment order: BudA pa...
void enableMnSyncAndSuperblocksPayment()
void CheckBudgetValue(int nHeight, std::string strNetwork, CAmount nExpectedValue)
CBudgetManager g_budgetman
void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight)
Allows modifying the network upgrade regtest parameters.
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
const CChainParams & Params()
Return the currently selected parameters.
CBLSPublicKey GetPublicKey() const
static const std::string REGTEST
static const std::string TESTNET
static const std::string MAIN
Chain name strings.
std::vector< CTransactionRef > vtx
uint256 GetBlockHash() const
static CAmount GetTotalBudget(int nHeight)
std::vector< CFinalizedBudget * > GetFinalizedBudgets()
void ForceAddFinalizedBudget(const uint256 &nHash, const uint256 &feeTxId, const CFinalizedBudget &finalizedBudget)
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or nullptr if none.
int Height() const
Return the maximal height in the chain.
const Consensus::Params & GetConsensus() const
bool GetPayeeAndAmount(int64_t nBlockHeight, CScript &payee, CAmount &nAmount) const
void SetTime(const int64_t &_nTime)
An encapsulated private key.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
A reference to a CKey: the Hash160 of its serialized public key.
An outpoint - a combination of a transaction hash and an index n into its vout.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Serialized script, used inside transaction inputs and outputs.
bool Sign(const CKey &key, const CKeyID &keyID)
CSignedMessage Class Functions inherited by network signed-messages.
bool CheckSignature(const CKeyID &keyID) const
std::vector< unsigned char > GetVchSig() const
void SetVchSig(const std::vector< unsigned char > &vchSigIn)
bool IsSporkActive(SporkId nSporkID)
void AddOrUpdateSporkMessage(const CSporkMessage &spork, bool flush=false)
An input of a transaction.
An output of a transaction.
Capture information about block/transaction validation.
std::string GetRejectReason() const
void SetCurrentSyncPhase(int sync_phase)
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
bool IsBlockValueValid(int nHeight, CAmount &nExpectedValue, CAmount nMinted, CAmount &nBudgetAmt)
bool IsCoinbaseValueValid(const CTransactionRef &tx, CAmount nBudgetAmt, CValidationState &_state)
Check coinbase output value for blocks after v6.0 enforcement.
UniValue spork(const JSONRPCRequest &request)
RecursiveMutex cs_main
Global state.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
uint256 GetRandHash() noexcept
CSporkManager sporkManager
@ SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT
@ SPORK_13_ENABLE_SUPERBLOCKS
@ SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
A mutable version of CTransaction.
std::vector< CTxOut > vout
static constexpr int ALWAYS_ACTIVE
Special value for nActivationHeight indicating that the upgrade is always active.
int nActivationHeight
Height of the first block for which the new consensus rules will be active.
NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES]
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
std::shared_ptr< CBlock > FinalizeBlock(std::shared_ptr< CBlock > pblock)
TierTwoSyncState g_tiertwo_sync_state
#define MASTERNODE_SYNC_FINISHED
uint256 uint256S(const char *str)
std::string FormatMoney(const CAmount &n, bool fPlus)
Money parsing/formatting utilities.
std::vector< unsigned char > ParseHex(const char *psz)
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
bool ProcessNewBlock(const std::shared_ptr< const CBlock > &pblock, const FlatFilePos *dbp)
Process an incoming block.
int64_t GetMasternodePayment(int nHeight)
CAmount GetBlockValue(int nHeight)
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).