@@ -60,6 +60,60 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
60
60
BOOST_CHECK_EQUAL (CalculateNextWorkRequired (&pindexLast, nLastRetargetTime, chainParams->GetConsensus ()), 0x1d00e1fdU );
61
61
}
62
62
63
+ BOOST_AUTO_TEST_CASE (CheckProofOfWork_test_negative_target)
64
+ {
65
+ const auto consensus = CreateChainParams (CBaseChainParams::MAIN)->GetConsensus ();
66
+ uint256 hash;
67
+ unsigned int nBits;
68
+ nBits = UintToArith256 (consensus.powLimit ).GetCompact (true );
69
+ hash.SetHex (" 0x1" );
70
+ BOOST_CHECK (!CheckProofOfWork (hash, nBits, consensus));
71
+ }
72
+
73
+ BOOST_AUTO_TEST_CASE (CheckProofOfWork_test_overflow_target)
74
+ {
75
+ const auto consensus = CreateChainParams (CBaseChainParams::MAIN)->GetConsensus ();
76
+ uint256 hash;
77
+ unsigned int nBits = ~0x00800000 ;
78
+ hash.SetHex (" 0x1" );
79
+ BOOST_CHECK (!CheckProofOfWork (hash, nBits, consensus));
80
+ }
81
+
82
+ BOOST_AUTO_TEST_CASE (CheckProofOfWork_test_too_easy_target)
83
+ {
84
+ const auto consensus = CreateChainParams (CBaseChainParams::MAIN)->GetConsensus ();
85
+ uint256 hash;
86
+ unsigned int nBits;
87
+ arith_uint256 nBits_arith = UintToArith256 (consensus.powLimit );
88
+ nBits_arith *= 2 ;
89
+ nBits = nBits_arith.GetCompact ();
90
+ hash.SetHex (" 0x1" );
91
+ BOOST_CHECK (!CheckProofOfWork (hash, nBits, consensus));
92
+ }
93
+
94
+ BOOST_AUTO_TEST_CASE (CheckProofOfWork_test_biger_hash_than_target)
95
+ {
96
+ const auto consensus = CreateChainParams (CBaseChainParams::MAIN)->GetConsensus ();
97
+ uint256 hash;
98
+ unsigned int nBits;
99
+ arith_uint256 hash_arith = UintToArith256 (consensus.powLimit );
100
+ nBits = hash_arith.GetCompact ();
101
+ hash_arith *= 2 ; // hash > nBits
102
+ hash = ArithToUint256 (hash_arith);
103
+ BOOST_CHECK (!CheckProofOfWork (hash, nBits, consensus));
104
+ }
105
+
106
+ BOOST_AUTO_TEST_CASE (CheckProofOfWork_test_zero_target)
107
+ {
108
+ const auto consensus = CreateChainParams (CBaseChainParams::MAIN)->GetConsensus ();
109
+ uint256 hash;
110
+ unsigned int nBits;
111
+ arith_uint256 hash_arith{0 };
112
+ nBits = hash_arith.GetCompact ();
113
+ hash = ArithToUint256 (hash_arith);
114
+ BOOST_CHECK (!CheckProofOfWork (hash, nBits, consensus));
115
+ }
116
+
63
117
BOOST_AUTO_TEST_CASE (GetBlockProofEquivalentTime_test)
64
118
{
65
119
const auto chainParams = CreateChainParams (CBaseChainParams::MAIN);
0 commit comments