diff --git a/src/Makefile.test.include b/src/Makefile.test.include --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -26,6 +26,7 @@ # test_bitcoin binary # BITCOIN_TESTS =\ test/scriptnum10.h \ + test/activation_tests.cpp \ test/addrman_tests.cpp \ test/allocator_tests.cpp \ test/amount_tests.cpp \ diff --git a/src/consensus/activation.h b/src/consensus/activation.h --- a/src/consensus/activation.h +++ b/src/consensus/activation.h @@ -25,4 +25,7 @@ */ bool IsMagneticAnomalyEnabled(const Config &config, int64_t nMedianTimePast); +/** Check if May 15th, 2019 protocol upgrade has activated. */ +bool IsGreatWallEnabled(const Config &config, const CBlockIndex *pindexPrev); + #endif // BITCOIN_CONSENSUS_ACTIVATION_H diff --git a/src/consensus/activation.cpp b/src/consensus/activation.cpp --- a/src/consensus/activation.cpp +++ b/src/consensus/activation.cpp @@ -48,3 +48,15 @@ return IsMagneticAnomalyEnabled(config, pindexPrev->GetMedianTimePast()); } + +bool IsGreatWallEnabled(const Config &config, const CBlockIndex *pindexPrev) { + + if (pindexPrev == nullptr) { + return false; + } + + return pindexPrev->GetMedianTimePast() >= + gArgs.GetArg( + "-greatwallactivationtime", + config.GetChainParams().GetConsensus().greatWallActivationTime); +} diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -44,6 +44,7 @@ add_dependencies(check check-bitcoin) add_test_to_suite(bitcoin test_bitcoin + activation_tests.cpp addrman_tests.cpp allocator_tests.cpp amount_tests.cpp diff --git a/src/test/activation_tests.cpp b/src/test/activation_tests.cpp new file mode 100644 --- /dev/null +++ b/src/test/activation_tests.cpp @@ -0,0 +1,35 @@ +// Copyright (c) 2019 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "chain.h" +#include "chainparams.h" +#include "config.h" +#include "consensus/activation.h" +#include "test/test_bitcoin.h" + +#include + +BOOST_FIXTURE_TEST_SUITE(activation_tests, BasicTestingSetup) + +BOOST_AUTO_TEST_CASE(isgreatwallenabled) { + + DummyConfig cfg; + CBlockIndex prev; + + const auto activation = + cfg.GetChainParams().GetConsensus().greatWallActivationTime; + + BOOST_CHECK(!IsGreatWallEnabled(cfg, nullptr)); + + prev.nTime = activation - 1; + BOOST_CHECK(!IsGreatWallEnabled(cfg, &prev)); + + prev.nTime = activation; + BOOST_CHECK(IsGreatWallEnabled(cfg, &prev)); + + prev.nTime = activation + 1; + BOOST_CHECK(IsGreatWallEnabled(cfg, &prev)); +} + +BOOST_AUTO_TEST_SUITE_END()