Search in sources :

Example 1 with DifficultyTestCase

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);
    }
}
Also used : DifficultyTestCase(org.ethereum.jsontestsuite.DifficultyTestCase) BlockDifficulty(co.rsk.core.BlockDifficulty) DifficultyCalculator(co.rsk.core.DifficultyCalculator) MainNetConfig(org.ethereum.config.net.MainNetConfig) BlockHeader(org.ethereum.core.BlockHeader) DifficultyTestSuite(org.ethereum.jsontestsuite.DifficultyTestSuite) Test(org.junit.Test)

Example 2 with DifficultyTestCase

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);
    }
}
Also used : DifficultyTestCase(org.ethereum.jsontestsuite.DifficultyTestCase) BlockDifficulty(co.rsk.core.BlockDifficulty) DifficultyCalculator(co.rsk.core.DifficultyCalculator) BlockFactory(org.ethereum.core.BlockFactory) BlockHeader(org.ethereum.core.BlockHeader) DifficultyTestSuite(org.ethereum.jsontestsuite.DifficultyTestSuite)

Aggregations

BlockDifficulty (co.rsk.core.BlockDifficulty)2 DifficultyCalculator (co.rsk.core.DifficultyCalculator)2 BlockHeader (org.ethereum.core.BlockHeader)2 DifficultyTestCase (org.ethereum.jsontestsuite.DifficultyTestCase)2 DifficultyTestSuite (org.ethereum.jsontestsuite.DifficultyTestSuite)2 MainNetConfig (org.ethereum.config.net.MainNetConfig)1 BlockFactory (org.ethereum.core.BlockFactory)1 Test (org.junit.Test)1