Changeset View
Changeset View
Standalone View
Standalone View
src/test/validation_tests.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2017 The Bitcoin 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 "chainparams.h" | #include "chainparams.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "consensus/consensus.h" | #include "consensus/consensus.h" | ||||
#include "primitives/transaction.h" | #include "primitives/transaction.h" | ||||
#include "script/interpreter.h" | |||||
#include "test/test_bitcoin.h" | #include "test/test_bitcoin.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <vector> | #include <vector> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
// defined in validation.cpp but not declared in validation.h - dont want to | |||||
// expose in header just for tests | |||||
uint32_t GetBlockScriptFlags(const Config &config, const CBlockIndex *pindex); | |||||
static CBlock makeLargeDummyBlock(const size_t num_tx) { | static CBlock makeLargeDummyBlock(const size_t num_tx) { | ||||
CBlock block; | CBlock block; | ||||
block.vtx.reserve(num_tx); | block.vtx.reserve(num_tx); | ||||
CTransaction tx; | CTransaction tx; | ||||
for (size_t i = 0; i < num_tx; i++) { | for (size_t i = 0; i < num_tx; i++) { | ||||
block.vtx.push_back(MakeTransactionRef(tx)); | block.vtx.push_back(MakeTransactionRef(tx)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | unsigned int size = GetSerializeSize(block, SER_DISK, CLIENT_VERSION); | ||||
outs << block; | outs << block; | ||||
outs.release(); | outs.release(); | ||||
} | } | ||||
fseek(fp, 0, SEEK_SET); | fseek(fp, 0, SEEK_SET); | ||||
BOOST_CHECK_NO_THROW({ LoadExternalBlockFile(config, fp, 0); }); | BOOST_CHECK_NO_THROW({ LoadExternalBlockFile(config, fp, 0); }); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(getblockscriptflags_monolith) { | |||||
GlobalConfig config; | |||||
// add a block to the chain - chain will be (genesis block, new block) | |||||
CBlockIndex newBlock; | |||||
CBlockIndex *genesisBlock = chainActive.Tip(); | |||||
newBlock.pprev = genesisBlock; | |||||
chainActive.SetTip(&newBlock); | |||||
// monolith not enabled | |||||
BOOST_CHECK(!IsMonolithEnabled(config, genesisBlock)); | |||||
uint32_t flags = GetBlockScriptFlags(config, &newBlock); | |||||
BOOST_CHECK((flags & SCRIPT_ENABLE_OPCODES_MONOLITH) == 0); | |||||
// Activate May 15, 2018 HF the dirty way | |||||
const int64_t monolithTime = | |||||
config.GetChainParams().GetConsensus().monolithActivationTime; | |||||
genesisBlock->nTime = monolithTime; | |||||
BOOST_CHECK(IsMonolithEnabled(config, genesisBlock)); | |||||
flags = GetBlockScriptFlags(config, &newBlock); | |||||
BOOST_CHECK((flags & SCRIPT_ENABLE_OPCODES_MONOLITH) != 0); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |