Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2017-2018 The Bitcoin developers | |||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "miner.h" | #include "miner.h" | ||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "coins.h" | #include "coins.h" | ||||
#include "config.h" | #include "config.h" | ||||
▲ Show 20 Lines • Show All 270 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < sizeof(blockinfo) / sizeof(*blockinfo); ++i) { | ||||
txCoinbase.vin[0].scriptSig = CScript(); | txCoinbase.vin[0].scriptSig = CScript(); | ||||
txCoinbase.vin[0].scriptSig.push_back(blockinfo[i].extranonce); | txCoinbase.vin[0].scriptSig.push_back(blockinfo[i].extranonce); | ||||
txCoinbase.vin[0].scriptSig.push_back(chainActive.Height()); | txCoinbase.vin[0].scriptSig.push_back(chainActive.Height()); | ||||
// Ignore the (optional) segwit commitment added by CreateNewBlock (as | // Ignore the (optional) segwit commitment added by CreateNewBlock (as | ||||
// the hardcoded nonces don't account for this) | // the hardcoded nonces don't account for this) | ||||
txCoinbase.vout.resize(1); | txCoinbase.vout.resize(1); | ||||
txCoinbase.vout[0].scriptPubKey = CScript(); | txCoinbase.vout[0].scriptPubKey = CScript(); | ||||
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); | ||||
if (txFirst.size() == 0) baseheight = chainActive.Height(); | if (txFirst.size() == 0) { | ||||
if (txFirst.size() < 4) txFirst.push_back(pblock->vtx[0]); | baseheight = chainActive.Height(); | ||||
} | |||||
if (txFirst.size() < 4) { | |||||
txFirst.push_back(pblock->vtx[0]); | |||||
} | |||||
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | pblock->hashMerkleRoot = BlockMerkleRoot(*pblock); | ||||
pblock->nNonce = blockinfo[i].nonce; | pblock->nNonce = blockinfo[i].nonce; | ||||
std::shared_ptr<const CBlock> shared_pblock = | std::shared_ptr<const CBlock> shared_pblock = | ||||
std::make_shared<const CBlock>(*pblock); | std::make_shared<const CBlock>(*pblock); | ||||
BOOST_CHECK(ProcessNewBlock(config, shared_pblock, true, nullptr)); | BOOST_CHECK(ProcessNewBlock(config, shared_pblock, true, nullptr)); | ||||
pblock->hashPrevBlock = pblock->GetHash(); | pblock->hashPrevBlock = pblock->GetHash(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 312 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
// Sequence locks pass. | // Sequence locks pass. | ||||
BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | ||||
{ | { | ||||
// Locktime passes on 2nd block. | // Locktime passes on 2nd block. | ||||
GlobalConfig config; | GlobalConfig config; | ||||
CValidationState state; | CValidationState state; | ||||
int64_t nMedianTimePast = chainActive.Tip()->GetMedianTimePast(); | |||||
BOOST_CHECK(ContextualCheckTransaction( | BOOST_CHECK(ContextualCheckTransaction( | ||||
config, CTransaction(tx), state, chainActive.Tip()->nHeight + 2, | config, CTransaction(tx), state, chainActive.Tip()->nHeight + 2, | ||||
chainActive.Tip()->GetMedianTimePast())); | nMedianTimePast, nMedianTimePast)); | ||||
} | } | ||||
// Absolute time locked. | // Absolute time locked. | ||||
tx.vin[0].prevout = COutPoint(txFirst[3]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[3]->GetId(), 0); | ||||
tx.nLockTime = chainActive.Tip()->GetMedianTimePast(); | tx.nLockTime = chainActive.Tip()->GetMedianTimePast(); | ||||
prevheights.resize(1); | prevheights.resize(1); | ||||
prevheights[0] = baseheight + 4; | prevheights[0] = baseheight + 4; | ||||
hash = tx.GetId(); | hash = tx.GetId(); | ||||
Show All 10 Lines | BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { | ||||
// Sequence locks pass. | // Sequence locks pass. | ||||
BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | BOOST_CHECK(TestSequenceLocks(CTransaction(tx), flags)); | ||||
{ | { | ||||
// Locktime passes 1 second later. | // Locktime passes 1 second later. | ||||
GlobalConfig config; | GlobalConfig config; | ||||
CValidationState state; | CValidationState state; | ||||
int64_t nMedianTimePast = chainActive.Tip()->GetMedianTimePast() + 1; | |||||
BOOST_CHECK(ContextualCheckTransaction( | BOOST_CHECK(ContextualCheckTransaction( | ||||
config, CTransaction(tx), state, chainActive.Tip()->nHeight + 1, | config, CTransaction(tx), state, chainActive.Tip()->nHeight + 1, | ||||
chainActive.Tip()->GetMedianTimePast() + 1)); | nMedianTimePast, nMedianTimePast)); | ||||
} | } | ||||
// mempool-dependent transactions (not added) | // mempool-dependent transactions (not added) | ||||
tx.vin[0].prevout = COutPoint(hash, 0); | tx.vin[0].prevout = COutPoint(hash, 0); | ||||
prevheights[0] = chainActive.Tip()->nHeight + 1; | prevheights[0] = chainActive.Tip()->nHeight + 1; | ||||
tx.nLockTime = 0; | tx.nLockTime = 0; | ||||
tx.vin[0].nSequence = 0; | tx.vin[0].nSequence = 0; | ||||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |