aboutsummaryrefslogtreecommitdiff
path: root/src/test/pow_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/pow_tests.cpp')
-rw-r--r--src/test/pow_tests.cpp55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/test/pow_tests.cpp b/src/test/pow_tests.cpp
index 1123d4202c..6c99021d97 100644
--- a/src/test/pow_tests.cpp
+++ b/src/test/pow_tests.cpp
@@ -5,7 +5,6 @@
#include <chain.h>
#include <chainparams.h>
#include <pow.h>
-#include <util/system.h>
#include <test/setup_common.h>
#include <boost/test/unit_test.hpp>
@@ -60,6 +59,60 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1d00e1fdU);
}
+BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_negative_target)
+{
+ const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
+ uint256 hash;
+ unsigned int nBits;
+ nBits = UintToArith256(consensus.powLimit).GetCompact(true);
+ hash.SetHex("0x1");
+ BOOST_CHECK(!CheckProofOfWork(hash, nBits, consensus));
+}
+
+BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_overflow_target)
+{
+ const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
+ uint256 hash;
+ unsigned int nBits = ~0x00800000;
+ hash.SetHex("0x1");
+ BOOST_CHECK(!CheckProofOfWork(hash, nBits, consensus));
+}
+
+BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_too_easy_target)
+{
+ const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
+ uint256 hash;
+ unsigned int nBits;
+ arith_uint256 nBits_arith = UintToArith256(consensus.powLimit);
+ nBits_arith *= 2;
+ nBits = nBits_arith.GetCompact();
+ hash.SetHex("0x1");
+ BOOST_CHECK(!CheckProofOfWork(hash, nBits, consensus));
+}
+
+BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_biger_hash_than_target)
+{
+ const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
+ uint256 hash;
+ unsigned int nBits;
+ arith_uint256 hash_arith = UintToArith256(consensus.powLimit);
+ nBits = hash_arith.GetCompact();
+ hash_arith *= 2; // hash > nBits
+ hash = ArithToUint256(hash_arith);
+ BOOST_CHECK(!CheckProofOfWork(hash, nBits, consensus));
+}
+
+BOOST_AUTO_TEST_CASE(CheckProofOfWork_test_zero_target)
+{
+ const auto consensus = CreateChainParams(CBaseChainParams::MAIN)->GetConsensus();
+ uint256 hash;
+ unsigned int nBits;
+ arith_uint256 hash_arith{0};
+ nBits = hash_arith.GetCompact();
+ hash = ArithToUint256(hash_arith);
+ BOOST_CHECK(!CheckProofOfWork(hash, nBits, consensus));
+}
+
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
{
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);