diff --git a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java index 7607b42a..a292665e 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java @@ -299,7 +299,7 @@ public class TestRunner { DataWord actualValue = testStorage.get(new DataWord(storageKey.getData())); if (actualValue == null || - !Arrays.equals(expectedStValue, actualValue.getNoLeadZeroesData())) { + !Arrays.equals(expectedStValue, actualValue.getData())) { String output = String.format("Storage value different: key [ %s ], expectedValue: [ %s ], actualValue: [ %s ]", diff --git a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestSuite.java b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestSuite.java index 98e32a5e..037b4dea 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestSuite.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestSuite.java @@ -25,6 +25,10 @@ public class TestSuite { } } + public List getAllTests(){ + return testList; + } + public Iterator iterator() { return testList.iterator(); } diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java b/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java index f2d82de3..6b7b0e37 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java @@ -253,7 +253,7 @@ public class DataWord implements Comparable { public void addmod(DataWord word1, DataWord word2) { this.add(word1); - BigInteger result = this.value().mod(word2.value()); + BigInteger result = this.sValue().mod(word2.sValue()); this.data = ByteUtil.copyToArray(result.and(MAX_VALUE)); } diff --git a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubJSONTestSuite.java b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubJSONTestSuite.java index 304ad53f..9c4c1432 100644 --- a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubJSONTestSuite.java +++ b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubJSONTestSuite.java @@ -39,7 +39,7 @@ public class GitHubJSONTestSuite { private static Logger logger = LoggerFactory.getLogger("TCK-Test"); - protected static void runGitHubJsonTest(String json) throws ParseException { + protected static void runGitHubJsonVMTest(String json, String testName) throws ParseException { Assume.assumeFalse("Online test is not available", json.equals("")); JSONParser parser = new JSONParser(); @@ -48,9 +48,51 @@ public class GitHubJSONTestSuite { TestSuite testSuite = new TestSuite(testSuiteObj); Iterator testIterator = testSuite.iterator(); + for (TestCase testCase : testSuite.getAllTests()) { + + String prefix = " "; + if (testName.equals(testCase.getName())) prefix = " => "; + + logger.info(prefix + testCase.getName()); + } + while (testIterator.hasNext()) { TestCase testCase = testIterator.next(); + if (testName.equals((testCase.getName()))) { + TestRunner runner = new TestRunner(); + List result = runner.runTestCase(testCase); + Assert.assertTrue(result.isEmpty()); + return; + } + } + } + + + + protected static void runGitHubJsonVMTest(String json, Set excluded) throws ParseException { + Assume.assumeFalse("Online test is not available", json.equals("")); + + JSONParser parser = new JSONParser(); + JSONObject testSuiteObj = (JSONObject) parser.parse(json); + + TestSuite testSuite = new TestSuite(testSuiteObj); + Iterator testIterator = testSuite.iterator(); + + for (TestCase testCase : testSuite.getAllTests()) { + + String prefix = " "; + if (excluded.contains(testCase.getName())) prefix = "[X] "; + + logger.info(prefix + testCase.getName()); + } + + + while (testIterator.hasNext()) { + + TestCase testCase = testIterator.next(); + if (excluded.contains(testCase.getName())) + continue; TestRunner runner = new TestRunner(); List result = runner.runTestCase(testCase); @@ -84,7 +126,7 @@ public class GitHubJSONTestSuite { Assert.assertTrue(result.isEmpty()); } - protected static void runGitHubJsonStateTest(String json, Set exclude) throws ParseException { + protected static void runGitHubJsonStateTest(String json, Set excluded) throws ParseException { Assume.assumeFalse("Online test is not available", json.equals("")); JSONParser parser = new JSONParser(); @@ -96,14 +138,14 @@ public class GitHubJSONTestSuite { for (StateTestCase testCase : testSuite.getAllTests()) { String prefix = " "; - if (exclude.contains(testCase.getName())) prefix = "[X] "; + if (excluded.contains(testCase.getName())) prefix = "[X] "; logger.info(prefix + testCase.getName()); } for (StateTestCase testCase : testCollection) { - if (exclude.contains(testCase.getName())) continue; + if (excluded.contains(testCase.getName())) continue; TestRunner runner = new TestRunner(); List result = runner.runTestCase(testCase); 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 6f2b1c72..6e8b5f80 100644 --- a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubVMTest.java +++ b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubVMTest.java @@ -9,70 +9,109 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runners.MethodSorters; -@Ignore +import java.util.HashSet; +import java.util.Set; + + @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubVMTest { + + @Test + public void runSingle() throws ParseException { + + String json = JSONReader.loadJSON("VMTests/vmArithmeticTest.json"); + GitHubJSONTestSuite.runGitHubJsonVMTest(json, "addmod2_1"); + } + + @Test public void testArithmeticFromGitHub() throws ParseException { + Set excluded = new HashSet<>(); + excluded.add("addmod2"); + excluded.add("addmod3"); // implement mod by negative for BigInt + excluded.add("addmod2_1"); // [?] + excluded.add("mulmoddivByZero2"); // [?] + excluded.add("addmodDivByZero"); // [?] + excluded.add("addmodDivByZero1"); // [?] + excluded.add("mulmoddivByZero1"); // [?] + excluded.add("mulmoddivByZero"); // [?] + excluded.add("addmod3_0"); // [?] + String json = JSONReader.loadJSON("VMTests/vmArithmeticTest.json"); - GitHubJSONTestSuite.runGitHubJsonTest(json); + GitHubJSONTestSuite.runGitHubJsonVMTest(json, excluded); } + @Ignore @Test // testing full suite public void testBitwiseLogicOperationFromGitHub() throws ParseException { + Set excluded = new HashSet<>(); String json = JSONReader.loadJSON("VMTests/vmBitwiseLogicOperationTest.json"); - GitHubJSONTestSuite.runGitHubJsonTest(json); + GitHubJSONTestSuite.runGitHubJsonVMTest(json, excluded); } + @Ignore @Test // testing full suite public void testBlockInfoFromGitHub() throws ParseException { + Set excluded = new HashSet<>(); String json = JSONReader.loadJSON("VMTests/vmBlockInfoTest.json"); - GitHubJSONTestSuite.runGitHubJsonTest(json); + GitHubJSONTestSuite.runGitHubJsonVMTest(json, excluded); } + @Ignore @Test // testing full suite public void testEnvironmentalInfoFromGitHub() throws ParseException { + Set excluded = new HashSet<>(); String json = JSONReader.loadJSON("VMTests/vmEnvironmentalInfoTest.json"); - GitHubJSONTestSuite.runGitHubJsonTest(json); + GitHubJSONTestSuite.runGitHubJsonVMTest(json, excluded); } + @Ignore @Test // testing full suite public void testIOandFlowOperationsFromGitHub() throws ParseException { + Set excluded = new HashSet<>(); String json = JSONReader.loadJSON("VMTests/vmIOandFlowOperationsTest.json"); - GitHubJSONTestSuite.runGitHubJsonTest(json); + GitHubJSONTestSuite.runGitHubJsonVMTest(json, excluded); } + @Ignore @Test // testing full suite public void testPushDupSwapFromGitHub() throws ParseException { + Set excluded = new HashSet<>(); String json = JSONReader.loadJSON("VMTests/vmPushDupSwapTest.json"); - GitHubJSONTestSuite.runGitHubJsonTest(json); + GitHubJSONTestSuite.runGitHubJsonVMTest(json, excluded); } + @Ignore @Test // testing full suite public void testShaFromGitHub() throws ParseException { + Set excluded = new HashSet<>(); String json = JSONReader.loadJSON("VMTests/vmSha3Test.json"); - GitHubJSONTestSuite.runGitHubJsonTest(json); + GitHubJSONTestSuite.runGitHubJsonVMTest(json, excluded); } + @Ignore @Test // testing full suite public void testVMGitHub() throws ParseException { + Set excluded = new HashSet<>(); String json = JSONReader.loadJSON("VMTests/vmtests.json"); - GitHubJSONTestSuite.runGitHubJsonTest(json); + GitHubJSONTestSuite.runGitHubJsonVMTest(json, excluded); } + @Ignore @Test // testing full suite public void testVMLogGitHub() throws ParseException { + Set excluded = new HashSet<>(); String json = JSONReader.loadJSON("VMTests/vmLogTest.json"); - GitHubJSONTestSuite.runGitHubJsonTest(json); + GitHubJSONTestSuite.runGitHubJsonVMTest(json, excluded); } }