16 #include "validation.h"
19 #include <boost/test/unit_test.hpp>
30 {4, 0xa4a3e223}, {2, 0x15c32f9e}, {1, 0x0375b547}, {1, 0x7004a8a5},
31 {2, 0xce440296}, {2, 0x52cfe198}, {1, 0x77a72cd0}, {2, 0xbb5d6f84},
32 {2, 0x83f30c2c}, {1, 0x48a73d5b}, {1, 0xef7dcd01}, {2, 0x6809c6c4},
33 {2, 0x0883ab3c}, {1, 0x087bbbe2}, {2, 0x2104a814}, {2, 0xdffb6daa},
34 {1, 0xee8a0a08}, {2, 0xba4237c1}, {1, 0xa70349dc}, {1, 0x344722bb},
35 {3, 0xd6294733}, {2, 0xec9f5c94}, {2, 0xca2fbc28}, {1, 0x6ba4f406},
36 {2, 0x015d4532}, {1, 0x6e119b7c}, {2, 0x43e8f314}, {2, 0x27962f38},
37 {2, 0xb571b51b}, {2, 0xb36bee23}, {2, 0xd17924a8}, {2, 0x6bc212d9},
38 {1, 0x630d4948}, {2, 0x9a4c4ebb}, {2, 0x554be537}, {1, 0xd63ddfc7},
39 {2, 0xa10acc11}, {1, 0x759a8363}, {2, 0xfb73090d}, {1, 0xe82c6a34},
40 {1, 0xe33e92d7}, {3, 0x658ef5cb}, {2, 0xba32ff22}, {5, 0x0227a10c},
41 {1, 0xa9a70155}, {5, 0xd096d809}, {1, 0x37176174}, {1, 0x830b8d0f},
42 {1, 0xc6e3910e}, {2, 0x823f3ca8}, {1, 0x99850849}, {1, 0x7521fb81},
43 {1, 0xaacaabab}, {1, 0xd645a2eb}, {5, 0x7aea1781}, {5, 0x9d6e4b78},
44 {1, 0x4ce90fd8}, {1, 0xabdc832d}, {6, 0x4a34f32a}, {2, 0xf2524c1c},
45 {2, 0x1bbeb08a}, {1, 0xad47f480}, {1, 0x9f026aeb}, {1, 0x15a95049},
46 {2, 0xd1cb95b2}, {2, 0xf84bbda5}, {1, 0x0fa62cd1}, {1, 0xe05f9169},
47 {1, 0x78d194a9}, {5, 0x3e38147b}, {5, 0x737ba0d4}, {1, 0x63378e10},
48 {1, 0x6d5f91cf}, {2, 0x88612eb8}, {2, 0xe9639484}, {1, 0xb7fabc9d},
49 {2, 0x19b01592}, {1, 0x5a90dd31}, {2, 0x5bd7e028}, {2, 0x94d00323},
50 {1, 0xa9b9c01a}, {1, 0x3a40de61}, {1, 0x56e7eec7}, {5, 0x859f7ef6},
51 {1, 0xfd8e5630}, {1, 0x2b0c9f7f}, {1, 0xba700e26}, {1, 0x7170a408},
52 {1, 0x70de86a8}, {1, 0x74d64cd5}, {1, 0x49e738a1}, {2, 0x6910b602},
53 {0, 0x643c565f}, {1, 0x54264b3f}, {2, 0x97ea6396}, {2, 0x55174459},
54 {2, 0x03e8779a}, {1, 0x98f34d8f}, {1, 0xc07b2b07}, {1, 0xdfe29668},
55 {1, 0x3141c7c1}, {1, 0xb3b595f4}, {1, 0x735abf08}, {5, 0x623bfbce},
56 {2, 0xd351e722}, {1, 0xf4ca48c9}, {1, 0x5b19c670}, {1, 0xa164bf0e},
57 {2, 0xbbbeb305}, {2, 0xfe1c810a},
73 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
74 tx.
vin[0].prevout.n = 0;
76 tx.
vout[0].nValue = 5000000000LL - 1000;
82 tx.
vin[0].prevout.hash = txFirst[1]->GetHash();
83 tx.
vout[0].nValue = 5000000000LL - 10000;
88 tx.
vin[0].prevout.hash = hashParentTx;
89 tx.
vout[0].nValue = 5000000000LL - 1000 - 50000;
95 BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashParentTx);
96 BOOST_CHECK(pblocktemplate->block.vtx[2]->GetHash() == hashHighFeeTx);
97 BOOST_CHECK(pblocktemplate->block.vtx[3]->GetHash() == hashMediumFeeTx);
100 tx.
vin[0].prevout.hash = hashHighFeeTx;
101 tx.
vout[0].nValue = 5000000000LL - 1000 - 50000;
110 tx.
vin[0].prevout.hash = hashFreeTx;
111 tx.
vout[0].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
116 for (
size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
117 BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashFreeTx);
118 BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashLowFeeTx);
125 tx.
vout[0].nValue -= 2;
129 BOOST_CHECK(pblocktemplate->block.vtx[4]->GetHash() == hashFreeTx);
130 BOOST_CHECK(pblocktemplate->block.vtx[5]->GetHash() == hashLowFeeTx);
135 tx.
vin[0].prevout.hash = txFirst[2]->GetHash();
137 tx.
vout[0].nValue = 5000000000LL - 100000000;
138 tx.
vout[1].nValue = 100000000;
143 tx.
vin[0].prevout.hash = hashFreeTx2;
146 tx.
vout[0].nValue = 5000000000LL - 100000000 - feeToUse;
152 for (
size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
153 BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashFreeTx2);
154 BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashLowFeeTx2);
159 tx.
vin[0].prevout.n = 1;
160 tx.
vout[0].nValue = 100000000 - 10000;
163 BOOST_CHECK(pblocktemplate->block.vtx[8]->GetHash() == hashLowFeeTx2);
173 std::unique_ptr<CBlockTemplate> pblocktemplate;
190 std::vector<CTransactionRef>txFirst;
191 std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(pblocktemplate->block);
192 for (
unsigned int i = 0; i <
sizeof(blockinfo)/
sizeof(*blockinfo); ++i) {
198 if (txFirst.size() < 4)
199 txFirst.emplace_back(pblock->vtx[0]);
201 pblock->nNonce = blockinfo[i].nonce;
207 pblock->hashPrevBlock = pblock->GetHash();
217 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
218 tx.
vin[0].prevout.n = 0;
220 tx.
vout[0].nValue = 5000000000LL;
221 for (
unsigned int i = 0; i < 2001; ++i) {
222 tx.
vout[0].nValue -= 1000000;
224 bool spendsCoinbase = (i == 0) ?
true :
false;
227 tx.
vin[0].prevout.hash = hash;
229 BOOST_CHECK_EXCEPTION(pblocktemplate =
BlockAssembler(
Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, &m_wallet,
false), std::runtime_error,
HasReason(
"bad-blk-sigops"));
232 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
233 tx.
vout[0].nValue = 5000000000LL;
234 for (
unsigned int i = 0; i < 1001; ++i) {
235 tx.
vout[0].nValue -= 1000000;
237 bool spendsCoinbase = (i == 0) ?
true :
false;
240 tx.
vin[0].prevout.hash = hash;
248 std::vector<unsigned char> vchData(520);
249 for (
unsigned int i = 0; i < 18; ++i)
252 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
253 tx.
vin[0].prevout.n = 0;
254 tx.
vout[0].nValue = 5000000000LL;
255 for (
unsigned int i = 0; i < 215; ++i) {
256 tx.
vout[0].nValue -= 10000000;
258 bool spendsCoinbase = i == 0;
260 tx.
vin[0].prevout.hash = hash;
268 BOOST_CHECK_EXCEPTION(pblocktemplate =
BlockAssembler(
Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, &m_wallet,
false), std::runtime_error,
HasReason(
"bad-txns-inputs-missingorspent"));
273 tx.
vin[0].prevout.hash = txFirst[1]->GetHash();
274 tx.
vout[0].nValue = 4900000000LL;
277 tx.
vin[0].prevout.hash = hash;
280 tx.
vin[1].prevout.hash = txFirst[0]->GetHash();
281 tx.
vin[1].prevout.n = 0;
282 tx.
vout[0].nValue = 5900000000LL;
290 tx.
vin[0].prevout.SetNull();
292 tx.
vout[0].nValue = 0;
296 BOOST_CHECK_EXCEPTION(pblocktemplate =
BlockAssembler(
Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, &m_wallet,
false), std::runtime_error,
HasReason(
"bad-cb-multiple"));
300 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
301 tx.
vin[0].prevout.n = 0;
303 tx.
vout[0].nValue = 4900000000LL;
308 tx.
vin[0].prevout.hash = hash;
309 tx.
vin[0].scriptSig =
CScript() << std::vector<unsigned char>(script.
begin(), script.
end());
310 tx.
vout[0].nValue -= 1000000;
314 BOOST_CHECK_EXCEPTION(pblocktemplate =
BlockAssembler(
Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, &m_wallet,
false), std::runtime_error,
HasReason(
"block-validation-failed"));
318 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
320 tx.
vout[0].nValue = 4900000000LL;
327 BOOST_CHECK_EXCEPTION(pblocktemplate =
BlockAssembler(
Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptPubKey, &m_wallet,
false), std::runtime_error,
HasReason(
"bad-txns-inputs-missingorspent"));
334 tx.
vin[0].prevout.hash = txFirst[0]->GetHash();
336 tx.
vin[0].nSequence = 0;
337 tx.
vout[0].nValue = 4900000000LL;
346 tx2.
vin[0].prevout.hash = txFirst[1]->GetHash();
347 tx2.
vin[0].prevout.n = 0;
349 tx2.
vin[0].nSequence = 0;
351 tx2.
vout[0].nValue = 4900000000LL;
int64_t CAmount
Amount in PIV (Can be negative)
CMutableTransaction CreateCoinbaseTx(const CScript &scriptPubKeyIn, CBlockIndex *pindexPrev)
const CChainParams & Params()
Return the currently selected parameters.
std::unique_ptr< CBlockTemplate > CreateNewBlock(const CScript &scriptPubKeyIn, CWallet *pwallet=nullptr, bool fProofOfStake=false, std::vector< CStakeableOutput > *availableCoins=nullptr, bool fNoMempoolTx=false, bool fTestValidity=true, CBlockIndex *prevBlock=nullptr, bool stopPoSOnNewBlock=true, bool fIncludeQfc=true)
Construct a new block template with coinbase to scriptPubKeyIn.
BlockStateCatcher & get() const
The block chain is a tree shaped structure starting with the genesis block at the root,...
int64_t GetMedianTimePast() const
int nHeight
height of the entry in the chain. The genesis block has height 0
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or nullptr if none.
CChainParams defines various tweakable parameters of a given instance of the PIVX system.
const Consensus::Params & GetConsensus() const
CAmount GetFee(size_t size) const
Serialized script, used inside transaction inputs and outputs.
A reference to a CScript: the Hash160 of its serialization (see script.h)
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
bool addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, bool validFeeEstimate=true)
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
BOOST_AUTO_TEST_SUITE_END()
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
void TestPackageSelection(const CChainParams &chainparams, CScript scriptPubKey, std::vector< CTransactionRef > &txFirst)
RecursiveMutex cs_main
Global state.
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
unsigned int GetSerializeSize(const std::array< T, N > &item)
array
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
A mutable version of CTransaction.
uint256 GetHash() const
Compute the hash of this CMutableTransaction.
std::vector< CTxOut > vout
TestMemPoolEntryHelper & SigOps(unsigned int _sigops)
TestMemPoolEntryHelper & SpendsCoinbaseOrCoinstake(bool _flag)
TestMemPoolEntryHelper & Time(int64_t _time)
TestMemPoolEntryHelper & Fee(CAmount _fee)
CTxMemPoolEntry FromTx(const CMutableTransaction &tx)
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
std::vector< unsigned char > ParseHex(const char *psz)
void SetMockTime(int64_t nMockTimeIn)
For testing.
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
bool CheckFinalTx(const CTransactionRef &tx, int flags)
Check if transaction will be final in the next block to be created.
CTxMemPool mempool(::minRelayTxFee)
CFeeRate minRelayTxFee
Fees smaller than this (in upiv) are considered zero fee (for relaying, mining and transaction creati...
bool ProcessNewBlock(const std::shared_ptr< const CBlock > &pblock, const FlatFilePos *dbp)
Process an incoming block.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...