Page MenuHomePhabricator

D2375.diff
No OneTemporary

D2375.diff

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
@@ -22,4 +22,7 @@
bool IsMagneticAnomalyEnabled(const Config &config,
const CBlockIndex *pindexPrev);
+/** 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
@@ -46,3 +46,14 @@
return IsMagneticAnomalyEnabled(config, pindexPrev->nHeight);
}
+
+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,49 @@
+// 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/test/unit_test.hpp>
+
+BOOST_FIXTURE_TEST_SUITE(activation_tests, BasicTestingSetup)
+
+static void SetMTP(std::array<CBlockIndex, 12> &blocks, int64_t mtp) {
+ size_t len = blocks.size();
+
+ for (size_t i = 0; i < len; ++i) {
+ blocks[i].nTime = mtp + (i - (len / 2));
+ }
+
+ assert(blocks.back().GetMedianTimePast() == mtp);
+}
+
+BOOST_AUTO_TEST_CASE(isgreatwallenabled) {
+ DummyConfig config;
+ CBlockIndex prev;
+
+ const auto activation =
+ config.GetChainParams().GetConsensus().greatWallActivationTime;
+
+ BOOST_CHECK(!IsGreatWallEnabled(config, nullptr));
+
+ std::array<CBlockIndex, 12> blocks;
+ for (size_t i = 1; i < blocks.size(); ++i) {
+ blocks[i].pprev = &blocks[i - 1];
+ }
+
+ SetMTP(blocks, activation - 1);
+ BOOST_CHECK(!IsGreatWallEnabled(config, &blocks.back()));
+
+ SetMTP(blocks, activation);
+ BOOST_CHECK(IsGreatWallEnabled(config, &blocks.back()));
+
+ SetMTP(blocks, activation + 1);
+ BOOST_CHECK(IsGreatWallEnabled(config, &blocks.back()));
+}
+
+BOOST_AUTO_TEST_SUITE_END()

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 10:22 (11 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187341
Default Alt Text
D2375.diff (3 KB)

Event Timeline