| 102 | } |
| 103 | |
| 104 | void fillDifficulty(string const& _testFileFullName, Ethash& _sealEngine) |
| 105 | { |
| 106 | int testN = 0; |
| 107 | ostringstream finalTest; |
| 108 | finalTest << "{" << std::endl; |
| 109 | dev::test::TestOutputHelper::initTest(900); |
| 110 | |
| 111 | for (int stampDelta = 0; stampDelta < 45; stampDelta+=2) |
| 112 | { |
| 113 | for (u256 blockNumber = 1; blockNumber < 1500000; blockNumber += 25000) |
| 114 | { |
| 115 | testN++; |
| 116 | json_spirit::mObject m; |
| 117 | string testName = "DifficultyTest"+toString(testN); |
| 118 | if (!dev::test::TestOutputHelper::passTest(m, testName)) |
| 119 | continue; |
| 120 | |
| 121 | u256 pStamp = dev::test::RandomCode::randomUniInt(); |
| 122 | u256 pDiff = dev::test::RandomCode::randomUniInt(); |
| 123 | u256 cStamp = pStamp + stampDelta; |
| 124 | u256 cNum = blockNumber; |
| 125 | |
| 126 | BlockHeader parent; |
| 127 | parent.setTimestamp(pStamp); |
| 128 | parent.setDifficulty(pDiff); |
| 129 | parent.setNumber(cNum - 1); |
| 130 | |
| 131 | BlockHeader current; |
| 132 | current.setTimestamp(cStamp); |
| 133 | current.setNumber(cNum); |
| 134 | |
| 135 | string tmptest = c_testDifficulty; |
| 136 | std::map<string, string> replaceMap; |
| 137 | replaceMap["[N]"] = toString(testN); |
| 138 | replaceMap["[PDIFF]"] = toCompactHex(pDiff, HexPrefix::Add); |
| 139 | replaceMap["[PSTAMP]"] = toCompactHex(pStamp, HexPrefix::Add); |
| 140 | replaceMap["[СSTAMP]"] = toCompactHex(cStamp, HexPrefix::Add); |
| 141 | replaceMap["[CNUM]"] = toCompactHex(cNum, HexPrefix::Add); |
| 142 | replaceMap["[CDIFF]"] = toCompactHex(_sealEngine.calculateDifficulty(current, parent), HexPrefix::Add); |
| 143 | |
| 144 | dev::test::RandomCode::parseTestWithTypes(tmptest, replaceMap); |
| 145 | finalTest << tmptest; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | finalTest << std::endl << "}"; |
| 150 | string testFile = finalTest.str(); |
| 151 | testFile = testFile.replace(testFile.find_last_of(","), 1, ""); |
| 152 | writeFile(_testFileFullName, asBytes(testFile)); |
| 153 | } |
| 154 | |
| 155 | void testDifficulty(string const& _testFileFullName, Ethash& _sealEngine, Network _n) |
| 156 | { |
no test coverage detected