Create and use backup of GitHub json test files in case online not available

This commit is contained in:
nicksavers 2014-10-10 13:36:14 +02:00
parent bbaef7e3c7
commit 2b690dd7a6
12 changed files with 12242 additions and 57 deletions

View File

@ -1,10 +1,6 @@
package org.ethereum.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.SecureRandom;
import java.text.DateFormat;
@ -12,7 +8,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
w
import javax.swing.ImageIcon;
import org.spongycastle.util.encoders.DecoderException;
@ -120,30 +116,6 @@ public class Utils {
return Double.parseDouble (version.substring (0, pos - 1));
}
public static String getFromUrl(String urlToRead) {
URL url;
HttpURLConnection conn;
BufferedReader rd;
String line;
String result = "";
try {
url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(3000);
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result += line;
}
rd.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
return result;
}
public static StringBuffer getHashlistShort(List<byte[]> blockHashes) {
StringBuffer sb = new StringBuffer();
String firstHash = Hex.toHexString(blockHashes.get(0));

View File

@ -3,7 +3,6 @@ package org.ethereum.jsontestsuite;
import java.util.Iterator;
import java.util.List;
import org.ethereum.util.Utils;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
@ -22,61 +21,61 @@ public class GitHubJSONTestSuiteTest {
@Test // testing full suite
public void testArithmeticFromGitHub() throws ParseException {
String json = Utils.getFromUrl("https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmArithmeticTest.json");
String json = JSONReader.loadJSON("vmArithmeticTest.json");
runGitHubJsonTest(json);
}
@Test // testing full suite
public void testBitwiseLogicOperationFromGitHub() throws ParseException {
String json = Utils.getFromUrl("https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmBitwiseLogicOperationTest.json");
String json = JSONReader.loadJSON("vmBitwiseLogicOperationTest.json");
runGitHubJsonTest(json);
}
@Test // testing full suite
public void testBlockInfoFromGitHub() throws ParseException {
String json = Utils.getFromUrl("https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmBlockInfoTest.json");
String json = JSONReader.loadJSON("vmBlockInfoTest.json");
runGitHubJsonTest(json);
}
@Test // testing full suite
public void testEnvironmentalInfoFromGitHub() throws ParseException {
String json = Utils.getFromUrl("https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmEnvironmentalInfoTest.json");
String json = JSONReader.loadJSON("vmEnvironmentalInfoTest.json");
runGitHubJsonTest(json);
}
@Test // testing full suite
public void testIOandFlowOperationsFromGitHub() throws ParseException {
String json = Utils.getFromUrl("https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmIOandFlowOperationsTest.json");
String json = JSONReader.loadJSON("vmIOandFlowOperationsTest.json");
runGitHubJsonTest(json);
}
@Test // testing full suite
public void testPushDupSwapFromGitHub() throws ParseException {
String json = Utils.getFromUrl("https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmPushDupSwapTest.json");
String json = JSONReader.loadJSON("vmPushDupSwapTest.json");
runGitHubJsonTest(json);
}
@Test // testing full suite
public void testShaFromGitHub() throws ParseException {
String json = Utils.getFromUrl("https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmSha3Test.json");
String json = JSONReader.loadJSON("vmSha3Test.json");
runGitHubJsonTest(json);
}
@Test // testing full suite
public void testSystemOperationsFromGitHub() throws ParseException {
String json = Utils.getFromUrl("https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmSystemOperationsTest.json");
String json = JSONReader.loadJSON("vmSystemOperationsTest.json");
runGitHubJsonTest(json);
}
private void runGitHubJsonTest(String json) throws ParseException {
Assume.assumeFalse("Online test suite is no available", json.equals(""));
Assume.assumeFalse("Online test is not available", json.equals(""));
JSONParser parser = new JSONParser();
JSONObject testSuiteObj = (JSONObject)parser.parse(json);
@ -94,4 +93,6 @@ public class GitHubJSONTestSuiteTest {
Assert.assertTrue(result.isEmpty());
}
}
}

View File

@ -0,0 +1,54 @@
package org.ethereum.jsontestsuite;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
public class JSONReader {
public static String loadJSON(String filename) {
String json = getFromUrl("https://raw.githubusercontent.com/ethereum/tests/master/vmtests/" + filename);
return json == "" ? json = getFromLocal(filename) : json;
}
public static String getFromLocal(String filename) {
System.out.println("Loading local file: " + filename);
try {
URL vmtest = ClassLoader.getSystemResource("jsontestsuite/" + filename);
File vmTestFile = new File(vmtest.toURI());
return new String(Files.readAllBytes(vmTestFile.toPath()));
} catch (URISyntaxException | IOException e) {
e.printStackTrace();
}
return "";
}
public static String getFromUrl(String urlToRead) {
URL url;
HttpURLConnection conn;
BufferedReader rd;
String line;
String result = "";
try {
url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(3000);
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result += line;
}
rd.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
return result;
}
}

View File

@ -1,25 +1,21 @@
package org.ethereum.jsontestsuite;
import org.ethereum.db.ByteArrayWrapper;
import org.ethereum.util.Utils;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.util.Iterator;
import java.util.List;
import org.ethereum.db.ByteArrayWrapper;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.junit.Assert;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
/**
* www.ethereumJ.com
*
@ -185,12 +181,7 @@ public class LocalJSONTestSuiteTest {
@Test // TestCase file: vmtest-1.json //
public void test6() throws ParseException, IOException, URISyntaxException {
URL vmtest = ClassLoader
.getSystemResource("jsontestsuite/vmtest-1.json");
File vmTestFile = new File(vmtest.toURI());
byte[] testData = Files.readAllBytes(vmTestFile.toPath());
String testSrc = new String(testData);
String testSrc = JSONReader.getFromLocal("vmtest-1.json");
JSONParser parser = new JSONParser();
JSONObject testCaseJSONObj = (JSONObject)parser.parse(testSrc);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,259 @@
{
"coinbase" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "0x41600057",
"data" : "0x",
"gas" : "10000",
"gasPrice" : "100000000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "9798",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x41600057",
"nonce" : "0",
"storage" : {
"0x" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x41600057",
"nonce" : "0",
"storage" : {
}
}
}
},
"difficulty" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "0x44600057",
"data" : "0x",
"gas" : "10000",
"gasPrice" : "100000000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "9798",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x44600057",
"nonce" : "0",
"storage" : {
"0x" : "0x0100"
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x44600057",
"nonce" : "0",
"storage" : {
}
}
}
},
"gaslimit" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "0x45600057",
"data" : "0x",
"gas" : "10000",
"gasPrice" : "100000000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "9798",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x45600057",
"nonce" : "0",
"storage" : {
"0x" : "0x0f4240"
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x45600057",
"nonce" : "0",
"storage" : {
}
}
}
},
"number" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "0x43600057",
"data" : "0x",
"gas" : "10000",
"gasPrice" : "100000000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "9898",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x43600057",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x43600057",
"nonce" : "0",
"storage" : {
}
}
}
},
"prevhash" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "0x40600057",
"data" : "0x",
"gas" : "10000",
"gasPrice" : "100000000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "9798",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x40600057",
"nonce" : "0",
"storage" : {
"0x" : "0x5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x40600057",
"nonce" : "0",
"storage" : {
}
}
}
},
"timestamp" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "0x42600057",
"data" : "0x",
"gas" : "10000",
"gasPrice" : "100000000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "9798",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x42600057",
"nonce" : "0",
"storage" : {
"0x" : "0x01"
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x42600057",
"nonce" : "0",
"storage" : {
}
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,173 @@
{
"sha3_0" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "0x6000600020600057",
"data" : "0x",
"gas" : "100000000000",
"gasPrice" : "1000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "99999999777",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x6000600020600057",
"nonce" : "0",
"storage" : {
"0x" : "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x6000600020600057",
"nonce" : "0",
"storage" : {
}
}
}
},
"sha3_1" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "0x6005600420600057",
"data" : "0x",
"gas" : "10000",
"gasPrice" : "100000000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "9776",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x6005600420600057",
"nonce" : "0",
"storage" : {
"0x" : "0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec"
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x6005600420600057",
"nonce" : "0",
"storage" : {
}
}
}
},
"sha3_2" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "0x600a600a20600057",
"data" : "0x",
"gas" : "10000",
"gasPrice" : "100000000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "9776",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x600a600a20600057",
"nonce" : "0",
"storage" : {
"0x" : "0x6bd2dd6bd408cbee33429358bf24fdc64612fbf8b1b4db604518f40ffd34b607"
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x600a600a20600057",
"nonce" : "0",
"storage" : {
}
}
}
},
"sha3_3" : {
"callcreates" : [
],
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "256",
"currentGasLimit" : "1000000",
"currentNumber" : "0",
"currentTimestamp" : "1",
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
},
"exec" : {
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"code" : "0x6064640fffffffff20600057",
"data" : "0x",
"gas" : "10000",
"gasPrice" : "100000000000000",
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
"value" : "1000000000000000000"
},
"gas" : "0",
"out" : "0x",
"post" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x6064640fffffffff20600057",
"nonce" : "0",
"storage" : {
}
}
},
"pre" : {
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
"balance" : "1000000000000000000",
"code" : "0x6064640fffffffff20600057",
"nonce" : "0",
"storage" : {
}
}
}
}
}

File diff suppressed because it is too large Load Diff