use of org.ethereum.jsontestsuite.DifficultyTestCase in project rskj by rsksmart.
the class LocalBasicTest method runDifficultyTest.
@Test
public void runDifficultyTest() throws IOException, ParseException {
config.setGenesisInfo("frontier.json");
config.setBlockchainConfig(new MainNetConfig());
String json = getJSON("difficulty");
DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
for (DifficultyTestCase testCase : testSuite.getTestCases()) {
logger.info("Running {}\n", testCase.getName());
BlockHeader current = testCase.getCurrent();
BlockHeader parent = testCase.getParent();
BlockDifficulty calc = new DifficultyCalculator(config).calcDifficulty(current, parent);
int c = calc.compareTo(parent.getDifficulty());
if (c > 0)
logger.info(" Difficulty increase test\n");
else if (c < 0)
logger.info(" Difficulty decrease test\n");
else
logger.info(" Difficulty without change test\n");
assertEquals(testCase.getExpectedDifficulty(), calc);
}
}
use of org.ethereum.jsontestsuite.DifficultyTestCase in project rskj by rsksmart.
the class LocalBasicTest method runJsonTest.
private void runJsonTest(String jsonName, ActivationConfig activationConfig, Constants networkConstants) throws IOException {
BlockFactory blockFactory = new BlockFactory(activationConfig);
String json = getJSON(jsonName);
DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
for (DifficultyTestCase testCase : testSuite.getTestCases()) {
logger.info("Running {}\n", testCase.getName());
BlockHeader current = testCase.getCurrent(blockFactory);
BlockHeader parent = testCase.getParent(blockFactory);
BlockDifficulty calc = new DifficultyCalculator(activationConfig, networkConstants).calcDifficulty(current, parent);
int c = calc.compareTo(parent.getDifficulty());
if (c > 0)
logger.info(" Difficulty increase test\n");
else if (c < 0)
logger.info(" Difficulty decrease test\n");
else
logger.info(" Difficulty without change test\n");
assertEquals(testCase.getExpectedDifficulty(), calc);
}
}
Aggregations