diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp --- a/src/test/validation_tests.cpp +++ b/src/test/validation_tests.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2011-2016 The Bitcoin Core developers // Copyright (c) 2017 The Bitcoin developers +// Copyright (c) 2018 The Bitcoin Cash developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -7,6 +8,7 @@ #include "config.h" #include "consensus/consensus.h" #include "primitives/transaction.h" +#include "script/interpreter.h" #include "test/test_bitcoin.h" #include "util.h" #include "validation.h" @@ -17,6 +19,12 @@ #include +// defined in validation.cpp but not declared in validation.h - dont want to +// expose in header just for tests +// extern uint32_t GetBlockScriptFlags(const CBlockIndex *pindex, const Config +// &config); +uint32_t GetBlockScriptFlags(const CBlockIndex *pindex, const Config &config); + static CBlock makeLargeDummyBlock(const size_t num_tx) { CBlock block; block.vtx.reserve(num_tx); @@ -76,4 +84,32 @@ BOOST_CHECK_NO_THROW({ LoadExternalBlockFile(config, fp, 0); }); } +/** test that GetBlockScriptFlags produces the correct flags for monolith + * upgrade (May 2018) */ +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(&newBlock, config); + 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(&newBlock, config); + BOOST_CHECK((flags & SCRIPT_ENABLE_OPCODES_MONOLITH) != 0); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 The Bitcoin Core developers // Copyright (c) 2017 The Bitcoin developers +// Copyright (c) 2018 The Bitcoin Cash developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -195,8 +196,7 @@ static void FindFilesToPrune(std::set &setFilesToPrune, uint64_t nPruneAfterHeight); static FILE *OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly = false); -static uint32_t GetBlockScriptFlags(const CBlockIndex *pindex, - const Config &config); +uint32_t GetBlockScriptFlags(const CBlockIndex *pindex, const Config &config); static bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) { @@ -1847,8 +1847,7 @@ static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS]; // Returns the script flags which should be checked for a given block -static uint32_t GetBlockScriptFlags(const CBlockIndex *pindex, - const Config &config) { +uint32_t GetBlockScriptFlags(const CBlockIndex *pindex, const Config &config) { AssertLockHeld(cs_main); const Consensus::Params &consensusparams = config.GetChainParams().GetConsensus(); @@ -1892,6 +1891,11 @@ flags |= SCRIPT_VERIFY_NULLFAIL; } + if (IsMonolithEnabled(config, pindex->pprev)) { + // When the May 15, 2018 HF is enabled, activate new opcodes. + flags |= SCRIPT_ENABLE_OPCODES_MONOLITH; + } + return flags; }