| 153 | } |
| 154 | |
| 155 | void testDifficulty(string const& _testFileFullName, Ethash& _sealEngine, Network _n) |
| 156 | { |
| 157 | //Test File |
| 158 | js::mValue v; |
| 159 | string s = contentsString(_testFileFullName); |
| 160 | BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of '" << _testFileFullName << "' is empty. Have you cloned the 'tests' repo branch develop?"); |
| 161 | js::read_string(s, v); |
| 162 | dev::test::TestOutputHelper::initTest(v); |
| 163 | |
| 164 | for (auto& i: v.get_obj()) |
| 165 | { |
| 166 | js::mObject o = i.second.get_obj(); |
| 167 | string testname = i.first; |
| 168 | if (!dev::test::TestOutputHelper::passTest(o, testname)) |
| 169 | continue; |
| 170 | |
| 171 | BlockHeader parent; |
| 172 | parent.setTimestamp(test::toInt(o["parentTimestamp"])); |
| 173 | parent.setDifficulty(test::toInt(o["parentDifficulty"])); |
| 174 | parent.setNumber(test::toInt(o["currentBlockNumber"]) - 1); |
| 175 | |
| 176 | BlockHeader current; |
| 177 | current.setTimestamp(test::toInt(o["currentTimestamp"])); |
| 178 | current.setNumber(test::toInt(o["currentBlockNumber"])); |
| 179 | |
| 180 | u256 difficulty = _sealEngine.calculateDifficulty(current, parent); |
| 181 | current.setDifficulty(difficulty); |
| 182 | BOOST_CHECK_EQUAL(difficulty, test::toInt(o["currentDifficulty"])); |
| 183 | |
| 184 | //Manual formula test |
| 185 | checkCalculatedDifficulty(current, parent, _n, _sealEngine.chainParams(), "(" + i.first + ")"); |
| 186 | } |
| 187 | dev::test::TestOutputHelper::finishTest(); |
| 188 | } |
| 189 | |
| 190 | BOOST_AUTO_TEST_SUITE(DifficultyTests) |
| 191 |
no test coverage detected