/* * Copyright (c) [2016] [ <ether.camp> ] * This file is part of the ethereumJ library. * * The ethereumJ library is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The ethereumJ library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>. */ package org.ethereum.jsontestsuite; import org.ethereum.config.BlockchainNetConfig; import org.ethereum.config.SystemProperties; import org.ethereum.config.blockchain.DaoHFConfig; import org.ethereum.config.blockchain.Eip150HFConfig; import org.ethereum.config.blockchain.FrontierConfig; import org.ethereum.config.blockchain.HomesteadConfig; import org.ethereum.config.net.BaseNetConfig; import org.ethereum.config.net.MainNetConfig; import org.ethereum.jsontestsuite.suite.JSONReader; import org.json.simple.parser.ParseException; import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.Collections; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubBlockTest { //SHACOMMIT of tested commit, ethereum/tests.git public String shacommit = "289b3e4524786618c7ec253b516bc8e76350f947"; @Ignore // test for conveniently running a single test @Test public void runSingleTest() throws ParseException, IOException { SystemProperties.getDefault().setGenesisInfo("frontier.json"); SystemProperties.getDefault().setBlockchainConfig(new HomesteadConfig()); String json = JSONReader.loadJSONFromCommit("BlockchainTests/Homestead/bcTotalDifficultyTest.json", shacommit); GitHubJSONTestSuite.runGitHubJsonSingleBlockTest(json, "sideChainWithNewMaxDifficultyStartingFromBlock3AfterBlock4"); } private void runFrontier(String name) throws IOException, ParseException { String json = JSONReader.loadJSONFromCommit("BlockchainTests/" + name + ".json", shacommit); GitHubJSONTestSuite.runGitHubJsonBlockTest(json, Collections.EMPTY_SET); } private void runHomestead(String name) throws IOException, ParseException { String json = JSONReader.loadJSONFromCommit("BlockchainTests/Homestead/" + name + ".json", shacommit); SystemProperties.getDefault().setBlockchainConfig(new HomesteadConfig()); try { GitHubJSONTestSuite.runGitHubJsonBlockTest(json, Collections.EMPTY_SET); } finally { SystemProperties.getDefault().setBlockchainConfig(MainNetConfig.INSTANCE); } } private void runEIP150(String name) throws IOException, ParseException { String json = JSONReader.loadJSONFromCommit("BlockchainTests/EIP150/" + name + ".json", shacommit); SystemProperties.getDefault().setBlockchainConfig(new Eip150HFConfig(new DaoHFConfig())); try { GitHubJSONTestSuite.runGitHubJsonBlockTest(json, Collections.EMPTY_SET); } finally { SystemProperties.getDefault().setBlockchainConfig(MainNetConfig.INSTANCE); } } private void run(String name, boolean frontier, boolean homestead, boolean eip150) throws IOException, ParseException { if (frontier) runFrontier(name); if (homestead) runHomestead(name); if (eip150) runEIP150(name); } @Test public void runBCInvalidHeaderTest() throws ParseException, IOException { run("bcInvalidHeaderTest", true, true, true); } @Test public void runBCInvalidRLPTest() throws ParseException, IOException { run("bcInvalidRLPTest", true, false, true); } @Test public void runBCRPCAPITest() throws ParseException, IOException { run("bcRPC_API_Test", true, true, true); } @Test public void runBCUncleHeaderValidityTest() throws ParseException, IOException { run("bcUncleHeaderValiditiy", true, true, true); } @Test public void runBCUncleTest() throws ParseException, IOException { run("bcUncleTest", true, true, true); } @Test public void runBCValidBlockTest() throws ParseException, IOException { SystemProperties.getDefault().setGenesisInfo("frontier.json"); run("bcValidBlockTest", true, true, true); } @Test public void runBCBlockGasLimitTest() throws ParseException, IOException { run("bcBlockGasLimitTest", true, true, true); } @Test public void runBCForkBlockTest() throws ParseException, IOException { run("bcForkBlockTest", true, false, false); } @Test public void runBCForkUncleTest() throws ParseException, IOException { run("bcForkUncle", true, false, false); } @Test public void runBCForkStressTest() throws ParseException, IOException { run("bcForkStressTest", true, true, true); } @Test public void runBCStateTest() throws ParseException, IOException { run("bcStateTest", true, true, true); } @Test public void runBCGasPricerTest() throws ParseException, IOException { run("bcGasPricerTest", true, true, true); } @Test public void runBCTotalDifficultyTest() throws ParseException, IOException { run("bcTotalDifficultyTest", false, true, true); } @Test public void runBCWalletTest() throws Exception, IOException { run("bcWalletTest", true, true, true); } @Test public void runBCMultiChainTest() throws ParseException, IOException { run("bcMultiChainTest", true, true, true); } @Test public void runDaoHardForkTest() throws Exception { String json = JSONReader.getFromUrl("https://raw.githubusercontent.com/ethereum/tests/hardfork/BlockchainTests/TestNetwork/bcTheDaoTest.json"); BlockchainNetConfig testConfig = new BaseNetConfig() { { add(0, new FrontierConfig()); add(5, new HomesteadConfig()); add(8, new DaoHFConfig(new HomesteadConfig(), 8)); } }; SystemProperties.getDefault().setGenesisInfo("frontier.json"); SystemProperties.getDefault().setBlockchainConfig(testConfig); GitHubJSONTestSuite.runGitHubJsonBlockTest(json, Collections.EMPTY_SET); } }