aboutsummaryrefslogtreecommitdiff
path: root/src/test/dogecoin_tests.cpp
diff options
context:
space:
mode:
authorRoss Nicoll <[email protected]>2021-05-22 14:10:45 +0100
committerRoss Nicoll <[email protected]>2021-05-29 00:48:49 +0100
commit53068fb220ad8ee4a73373f8d8db62ab70b4ee50 (patch)
tree9002150020c871f76a4d56b7fb9d636a951e482c /src/test/dogecoin_tests.cpp
parentMerge pull request #1988 from rnicoll/1.21-message-headers (diff)
downloaddiscoin-53068fb220ad8ee4a73373f8d8db62ab70b4ee50.tar.xz
discoin-53068fb220ad8ee4a73373f8d8db62ab70b4ee50.zip
Introduce Dogecoin difficulty calculations
Diffstat (limited to 'src/test/dogecoin_tests.cpp')
-rw-r--r--src/test/dogecoin_tests.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/test/dogecoin_tests.cpp b/src/test/dogecoin_tests.cpp
new file mode 100644
index 000000000..b446ff685
--- /dev/null
+++ b/src/test/dogecoin_tests.cpp
@@ -0,0 +1,104 @@
+// Copyright (c) 2015-2021 The Dogecoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <arith_uint256.h>
+#include <chainparams.h>
+#include <dogecoin.h>
+
+#include <test/util/setup_common.h>
+
+#include <boost/test/unit_test.hpp>
+
+BOOST_FIXTURE_TEST_SUITE(dogecoin_tests, TestingSetup)
+
+BOOST_AUTO_TEST_CASE(get_next_work_difficulty_limit)
+{
+ SelectParams(CBaseChainParams::MAIN);
+ const Consensus::Params& params = Params().GetConsensus();
+
+ CBlockIndex pindexLast;
+ int64_t nLastRetargetTime = 1386474927; // Block # 1
+
+ pindexLast.nHeight = 239;
+ pindexLast.nTime = 1386475638; // Block #239
+ pindexLast.nBits = 0x1e0ffff0;
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1e00ffff);
+}
+
+BOOST_AUTO_TEST_CASE(get_next_work_pre_digishield)
+{
+ SelectParams(CBaseChainParams::MAIN);
+ const Consensus::Params& params = Params().GetConsensus();
+
+ CBlockIndex pindexLast;
+ int64_t nLastRetargetTime = 1386942008; // Block 9359
+
+ pindexLast.nHeight = 9599;
+ pindexLast.nTime = 1386954113;
+ pindexLast.nBits = 0x1c1a1206;
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c15ea59);
+}
+
+BOOST_AUTO_TEST_CASE(get_next_work_digishield)
+{
+ SelectParams(CBaseChainParams::MAIN);
+ const Consensus::Params& params = Params().GetConsensus();
+
+ CBlockIndex pindexLast;
+ int64_t nLastRetargetTime = 1395094427;
+
+ // First hard-fork at 145,000, which applies to block 145,001 onwards
+ pindexLast.nHeight = 145000;
+ pindexLast.nTime = 1395094679;
+ pindexLast.nBits = 0x1b499dfd;
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b671062);
+}
+
+BOOST_AUTO_TEST_CASE(get_next_work_digishield_modulated_upper)
+{
+ SelectParams(CBaseChainParams::MAIN);
+ const Consensus::Params& params = Params().GetConsensus();
+
+ CBlockIndex pindexLast;
+ int64_t nLastRetargetTime = 1395100835;
+
+ // Test the upper bound on modulated time using mainnet block #145,107
+ pindexLast.nHeight = 145107;
+ pindexLast.nTime = 1395101360;
+ pindexLast.nBits = 0x1b3439cd;
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b4e56b3);
+}
+
+BOOST_AUTO_TEST_CASE(get_next_work_digishield_modulated_lower)
+{
+ SelectParams(CBaseChainParams::MAIN);
+ const Consensus::Params& params = Params().GetConsensus();
+
+ CBlockIndex pindexLast;
+ int64_t nLastRetargetTime = 1395380517;
+
+ // Test the lower bound on modulated time using mainnet block #149,423
+ pindexLast.nHeight = 149423;
+ pindexLast.nTime = 1395380447;
+ pindexLast.nBits = 0x1b446f21;
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b335358);
+}
+
+BOOST_AUTO_TEST_CASE(get_next_work_digishield_rounding)
+{
+ SelectParams(CBaseChainParams::MAIN);
+ const Consensus::Params& params = Params().GetConsensus();
+
+ CBlockIndex pindexLast;
+ int64_t nLastRetargetTime = 1395094679;
+
+ // Test case for correct rounding of modulated time - this depends on
+ // handling of integer division, and is not obvious from the code
+ pindexLast.nHeight = 145001;
+ pindexLast.nTime = 1395094727;
+ pindexLast.nBits = 0x1b671062;
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b6558a4);
+}
+
+BOOST_AUTO_TEST_SUITE_END()