From 494aee1e58f0daf24e362ab408c6dbdfa86c2406 Mon Sep 17 00:00:00 2001 From: nicksavers Date: Mon, 14 Jul 2014 00:18:28 +0200 Subject: [PATCH] Add random.json and fix in Repository --- .../main/java/org/ethereum/db/Repository.java | 6 +++++ .../ethereum/jsontestsuite/TestRunner.java | 8 ++----- .../main/java/org/ethereum/vm/Program.java | 3 +-- .../jsontestsuite/JSONTestSuiteTest.java | 22 +++++++++++++++++++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/db/Repository.java b/ethereumj-core/src/main/java/org/ethereum/db/Repository.java index 691d86b4..322f502b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/db/Repository.java +++ b/ethereumj-core/src/main/java/org/ethereum/db/Repository.java @@ -95,6 +95,12 @@ public class Repository { public AccountState createAccount(byte[] addr) { + if (addr.length < 20) { + byte[] newAddr = new byte[20]; + System.arraycopy(addr, 0, newAddr, newAddr.length - addr.length, addr.length); + addr = newAddr; + } + // 1. Save AccountState AccountState state = new AccountState(); accountStateDB.update(addr, state.getEncoded()); 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 86d0ba37..54eb06f9 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java @@ -65,7 +65,8 @@ public class TestRunner { Env env = testCase.getEnv(); Exec exec = testCase.getExec(); - byte[] address = exec.getAddress(); //repository.createAccount(address); + byte[] address = exec.getAddress(); + if(repository.getAccountState(address) == null) { repository.createAccount(address); } byte[] origin = exec.getOrigin(); byte[] caller = exec.getCaller(); byte[] balance = ByteUtil.bigIntegerToBytes(repository.getBalance(exec.getAddress())); @@ -96,7 +97,6 @@ public class TestRunner { program.setRuntimeFailure(e); } - /* 5. Assert Post values */ for (ByteArrayWrapper key : testCase.getPost().keySet()){ @@ -185,7 +185,6 @@ public class TestRunner { ); logger.info(output); results.add(output); - } } } @@ -194,7 +193,6 @@ public class TestRunner { // TODO: -> basically the deleted by suicide should be deleted // TODO: -> and no unexpected created - List resultCallCreates = program.getResult().getCallCreateList(); @@ -257,7 +255,6 @@ public class TestRunner { Hex.toHexString( resultCallCreate.getGasLimit()) ); logger.info(output); results.add(output); - } boolean assertValue = Arrays.equals(expectedCallCreate.getValue(), @@ -271,7 +268,6 @@ public class TestRunner { logger.info(output); results.add(output); } - } // assert out diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java index 0f7adb06..3e0b4ba4 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/Program.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/Program.java @@ -220,8 +220,7 @@ public class Program { logger.info("Transfer to: [ {} ] heritage: [ {} ]", Hex.toHexString(obtainer.getNoLeadZeroesData()) , balance.longValue()); - this.result.getRepository().addBalance(obtainer.getNoLeadZeroesData(), - balance.value()); + this.result.getRepository().addBalance(obtainer.getNoLeadZeroesData(), balance.value()); // 2) mark the account as for delete result.addDeleteAccount(getOwnerAddress()); diff --git a/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/JSONTestSuiteTest.java b/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/JSONTestSuiteTest.java index 45da05f5..474e930c 100644 --- a/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/JSONTestSuiteTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/JSONTestSuiteTest.java @@ -339,4 +339,26 @@ public class JSONTestSuiteTest { } } + @Test // testing full suite + public void testRandomFromGitHub() throws ParseException { + + String json = Utils.getFromUrl("https://raw.githubusercontent.com/ethereum/tests/develop/random.json"); + Assume.assumeFalse("Online test suite is no available", json.equals("")); + + JSONParser parser = new JSONParser(); + JSONObject testSuiteObj = (JSONObject)parser.parse(json); + + TestSuite testSuite = new TestSuite(testSuiteObj); + Iterator testIterator = testSuite.iterator(); + + while (testIterator.hasNext()){ + + TestCase testCase = testIterator.next(); + + System.out.println("Running: " + testCase.getName()); + TestRunner runner = new TestRunner(); + List result = runner.runTestCase(testCase); + Assert.assertTrue(result.isEmpty()); + } + } }