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));
}
}
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);
}
}
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;
}
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());
}
}
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));
}
}
Aggregations