From 2102792f23d7edb19e75cffeb441d4c013db949d Mon Sep 17 00:00:00 2001 From: Faiz Khan Date: Fri, 6 Mar 2015 11:09:30 -0600 Subject: [PATCH] Auto loader for per-commit tests --- ethereumj-core/build.gradle | 1 + .../ethereum/jsontestsuite/JSONReader.java | 34 ++++++++++++++++++- .../ethereum/jsontestsuite/GitHubVMTest.java | 6 +++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ethereumj-core/build.gradle b/ethereumj-core/build.gradle index 8e1094dc..73878c02 100644 --- a/ethereumj-core/build.gradle +++ b/ethereumj-core/build.gradle @@ -69,6 +69,7 @@ dependencies { compile "com.google.code.findbugs:jsr305:3.0.0" compile "com.fasterxml.jackson.core:jackson-databind:2.2.0" compile "org.apache.commons:commons-collections4:4.0" + compile "commons-codec:commons-codec:1.10" compile "org.springframework:spring-context:${springVersion}" compile "org.springframework:spring-tx:${springVersion}" compile "org.springframework:spring-orm:${springVersion}" diff --git a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/JSONReader.java b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/JSONReader.java index 361a8afe..1d181b9f 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/JSONReader.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/JSONReader.java @@ -20,6 +20,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.apache.commons.codec.binary.Base64; + public class JSONReader { public static String loadJSON(String filename) { @@ -71,6 +73,36 @@ public class JSONReader { return result; } + public static String getTestBlobForTreeSha(String shacommit, String testcase){ + + String result = getFromUrl("https://api.github.com/repos/ethereum/tests/git/trees/" + shacommit); + + JSONParser parser = new JSONParser(); + JSONObject testSuiteObj = null; + + List fileNames = new ArrayList(); + try { + testSuiteObj = (JSONObject) parser.parse(result); + JSONArray tree = (JSONArray)testSuiteObj.get("tree"); + + for (Object oEntry : tree) { + JSONObject entry = (JSONObject) oEntry; + String testName = (String) entry.get("path"); + if ( testName.equals(testcase) ) { + String blobresult = getFromUrl( (String) entry.get("url") ); + + testSuiteObj = (JSONObject) parser.parse(blobresult); + String blob = (String) testSuiteObj.get("content"); + byte[] valueDecoded= Base64.decodeBase64(blob.getBytes() ); + //System.out.println("Decoded value is " + new String(valueDecoded)); + return new String(valueDecoded); + } + } + } catch (ParseException e) {e.printStackTrace();} + + return ""; + } + public static List getFileNamesForTreeSha(String sha){ String result = getFromUrl("https://api.github.com/repos/ethereum/tests/git/trees/" + sha); @@ -92,4 +124,4 @@ public class JSONReader { return fileNames; } -} \ No newline at end of file +} diff --git a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubVMTest.java b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubVMTest.java index bbf6333c..9e23266d 100644 --- a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubVMTest.java +++ b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubVMTest.java @@ -18,6 +18,10 @@ import static org.ethereum.jsontestsuite.JSONReader.getFileNamesForTreeSha; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubVMTest { + //SHACOMMIT of VMTESTS TREE (not main tree) + public String shacommit = "a713843af6e6274915bdbbc03d62dc5a0007548b"; + public List vmTestFiles = getFileNamesForTreeSha(shacommit); + @Test public void runSingle() throws ParseException { String json = JSONReader.loadJSON("VMTests/vmEnvironmentalInfoTest.json"); @@ -29,7 +33,7 @@ public class GitHubVMTest { Set excluded = new HashSet<>(); excluded.add("addmod1_overflowDiff"); excluded.add("addmod1_overflow3"); - String json = JSONReader.loadJSON("VMTests/vmArithmeticTest.json"); + String json = JSONReader.getTestBlobForTreeSha(shacommit, "vmArithmeticTest.json"); GitHubJSONTestSuite.runGitHubJsonVMTest(json, excluded); }