Search in sources :

Example 1 with MainNetConfig

use of org.ethereum.config.net.MainNetConfig in project rskj by rsksmart.

the class GitHubBasicTest method runDifficultyTest.

@Test
public void runDifficultyTest() throws IOException, ParseException {
    config.setBlockchainConfig(new MainNetConfig());
    String json = JSONReader.loadJSONFromCommit("BasicTests/difficulty.json", shacommit);
    DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
    for (DifficultyTestCase testCase : testSuite.getTestCases()) {
        logger.info("Running {}\n", testCase.getName());
        BlockHeader current = testCase.getCurrent();
        BlockHeader parent = testCase.getParent();
        assertEquals(testCase.getExpectedDifficulty(), DIFFICULTY_CALCULATOR.calcDifficulty(current, parent));
    }
}
Also used : MainNetConfig(org.ethereum.config.net.MainNetConfig) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 2 with MainNetConfig

use of org.ethereum.config.net.MainNetConfig 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 3 with MainNetConfig

use of org.ethereum.config.net.MainNetConfig in project rskj by rsksmart.

the class SystemProperties method getBlockchainConfig.

@ValidateMe
public BlockchainNetConfig getBlockchainConfig() {
    if (blockchainConfig == null) {
        String netName = netName();
        if (netName != null && configFromFiles.hasPath("blockchain.config.class")) {
            throw new RuntimeException("Only one of two options should be defined: 'blockchain.config.name' and 'blockchain.config.class'");
        }
        if (netName != null) {
            switch(netName) {
                case "main":
                    blockchainConfig = new MainNetConfig();
                    break;
                case "fallbackmain":
                    blockchainConfig = new FallbackMainNetConfig();
                    break;
                case "testnet":
                    blockchainConfig = new TestNetConfig();
                    break;
                case "devnet":
                    blockchainConfig = new DevNetConfig();
                    break;
                case "regtest":
                    blockchainConfig = new RegTestConfig();
                    break;
                default:
                    throw new RuntimeException("Unknown value for 'blockchain.config.name': '" + configFromFiles.getString("blockchain.config.name") + "'");
            }
        } else {
            String className = configFromFiles.getString("blockchain.config.class");
            try {
                Class<? extends BlockchainNetConfig> aClass = (Class<? extends BlockchainNetConfig>) Class.forName(className);
                blockchainConfig = aClass.newInstance();
            } catch (ClassNotFoundException e) {
                throw new RuntimeException("The class specified via blockchain.config.class '" + className + "' not found", e);
            } catch (ClassCastException e) {
                throw new RuntimeException("The class specified via blockchain.config.class '" + className + "' is not instance of org.ethereum.config.BlockchainForkConfig", e);
            } catch (InstantiationException | IllegalAccessException e) {
                throw new RuntimeException("The class specified via blockchain.config.class '" + className + "' couldn't be instantiated (check for default constructor and its accessibility)", e);
            }
        }
    }
    return blockchainConfig;
}
Also used : RegTestConfig(org.ethereum.config.blockchain.RegTestConfig) FallbackMainNetConfig(org.ethereum.config.blockchain.FallbackMainNetConfig) DevNetConfig(org.ethereum.config.blockchain.DevNetConfig) TestNetConfig(org.ethereum.config.net.TestNetConfig) FallbackMainNetConfig(org.ethereum.config.blockchain.FallbackMainNetConfig) MainNetConfig(org.ethereum.config.net.MainNetConfig)

Example 4 with MainNetConfig

use of org.ethereum.config.net.MainNetConfig in project rskj by rsksmart.

the class TransactionTest method contractCreationTest.

// This test fails post EIP150
@Ignore
@Test
public void contractCreationTest() throws Exception {
    // Checks Homestead updates (1) & (3) from
    // https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.mediawiki
    /*
          trying to create a contract with the following Solidity code:

         contract Test {
            uint a = 256;

            function set(uint s) {
                a = s;
            }

            function get() returns (uint) {
                return a;
            }
         }
        */
    // [actual gas required] - 1
    int iBitLowGas = 0x015f84;
    String aBitLowGas = "0x0" + Integer.toHexString(iBitLowGas);
    String senderPostBalance = "0x0" + Long.toHexString(1000000000000000000L - iBitLowGas);
    String json = "{ " + "    'test1' : { " + "        'env' : { " + "            'currentCoinbase' : '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba', " + "            'currentDifficulty' : '0x0100', " + "            'currentGasLimit' : '0x0f4240', " + "            'currentNumber' : '0x01', " + "            'currentTimestamp' : '0x01', " + "            'previousHash' : '5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6' " + "        }, " + "        'logs' : [ " + "        ], " + "        'out' : '0x', " + "        'post' : { " + "            '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba' : { " + "                'balance' : '" + aBitLowGas + "', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            }," + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '" + senderPostBalance + "', " + "                'code' : '0x', " + "                'nonce' : '0x01', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'postStateRoot' : '17454a767e5f04461256f3812ffca930443c04a47d05ce3f38940c4a14b8c479', " + "        'pre' : { " + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '0x0de0b6b3a7640000', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'transaction' : { " + "            'data' : '0x6060604052610100600060005055603b8060196000396000f3606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " + "            'gasLimit' : '" + aBitLowGas + "', " + "            'gasPrice' : '0x01', " + "            'nonce' : '0x00', " + "            'secretKey' : '45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8', " + "            'to' : '', " + "            'value' : '0x0' " + "        } " + "    } " + "}";
    StateTestSuite stateTestSuite = new StateTestSuite(json.replaceAll("'", "\""));
    System.out.println(json.replaceAll("'", "\""));
    try {
        config.setBlockchainConfig(new GenesisConfig());
        List<String> res = new StateTestRunner(stateTestSuite.getTestCases().get("test1")).runImpl();
        if (!res.isEmpty())
            throw new RuntimeException("Test failed: " + res);
    } finally {
        config.setBlockchainConfig(new MainNetConfig());
    }
}
Also used : StateTestRunner(org.ethereum.jsontestsuite.runners.StateTestRunner) StateTestSuite(org.ethereum.jsontestsuite.StateTestSuite) MainNetConfig(org.ethereum.config.net.MainNetConfig) GenesisConfig(org.ethereum.config.blockchain.GenesisConfig) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with MainNetConfig

use of org.ethereum.config.net.MainNetConfig in project rskj by rsksmart.

the class GitHubBasicTest method runDifficultyFrontierTest.

@Test
public void runDifficultyFrontierTest() throws IOException, ParseException {
    config.setBlockchainConfig(new MainNetConfig());
    String json = JSONReader.loadJSONFromCommit("BasicTests/difficultyFrontier.json", shacommit);
    DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
    for (DifficultyTestCase testCase : testSuite.getTestCases()) {
        logger.info("Running {}\n", testCase.getName());
        BlockHeader current = testCase.getCurrent();
        BlockHeader parent = testCase.getParent();
        assertEquals(testCase.getExpectedDifficulty(), DIFFICULTY_CALCULATOR.calcDifficulty(current, parent));
    }
}
Also used : MainNetConfig(org.ethereum.config.net.MainNetConfig) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Aggregations

MainNetConfig (org.ethereum.config.net.MainNetConfig)6 Test (org.junit.Test)4 BlockHeader (org.ethereum.core.BlockHeader)3 GenesisConfig (org.ethereum.config.blockchain.GenesisConfig)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1 DifficultyCalculator (co.rsk.core.DifficultyCalculator)1 DevNetConfig (org.ethereum.config.blockchain.DevNetConfig)1 FallbackMainNetConfig (org.ethereum.config.blockchain.FallbackMainNetConfig)1 RegTestConfig (org.ethereum.config.blockchain.RegTestConfig)1 TestNetConfig (org.ethereum.config.net.TestNetConfig)1 DifficultyTestCase (org.ethereum.jsontestsuite.DifficultyTestCase)1 DifficultyTestSuite (org.ethereum.jsontestsuite.DifficultyTestSuite)1 StateTestSuite (org.ethereum.jsontestsuite.StateTestSuite)1 StateTestRunner (org.ethereum.jsontestsuite.runners.StateTestRunner)1 Ignore (org.junit.Ignore)1