MCPcopy Create free account
hub / github.com/LUX-Core/lux / testDifficulty

Function testDifficulty

src/cpp-ethereum/test/libethcore/difficulty.cpp:155–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155void 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
190BOOST_AUTO_TEST_SUITE(DifficultyTests)
191

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 8

toIntFunction · 0.85
calculateDifficultyMethod · 0.80
read_stringFunction · 0.50
lengthMethod · 0.45
setTimestampMethod · 0.45
setDifficultyMethod · 0.45
setNumberMethod · 0.45

Tested by

no test coverage detected