From ba3b1c34b3e21eab731a3f0faa353383ecba8bdc Mon Sep 17 00:00:00 2001 From: Faiz Khan Date: Sun, 8 Feb 2015 20:55:52 -0600 Subject: [PATCH 1/5] Fixing transaction tests --- .../org/ethereum/core/TransactionExecutor.java | 12 ++++++++++++ .../org/ethereum/jsontestsuite/TestRunner.java | 16 ++++++++++++++++ .../ethereum/jsontestsuite/GitHubStateTest.java | 2 -- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java b/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java index 51f12ff6..d851b740 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/TransactionExecutor.java @@ -18,6 +18,8 @@ import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; +import java.lang.Long; + import java.util.List; import static org.ethereum.config.SystemProperties.CONFIG; @@ -100,6 +102,16 @@ public class TransactionExecutor { return; } + BigInteger startGasUsed = new BigInteger( Long.toString( this.currentBlock.getGasUsed() ) ); + BigInteger startGasLimit = new BigInteger( Long.toString( this.currentBlock.getGasLimit() ) ); + if( startGasUsed.add(gasLimit).compareTo( startGasLimit ) == 1) { + logger.debug("Too much gas used in this block: require={}", startGasLimit.toString()); + + receipt.setCumulativeGas(0); + this.receipt = receipt; + return; + } + // GET TOTAL ETHER VALUE AVAILABLE FOR TX FEE BigInteger gasPrice = new BigInteger(1, tx.getGasPrice()); BigInteger gasDebit = new BigInteger(1, tx.getGasLimit()).multiply(gasPrice); 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 bedfdf89..4cd46276 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java @@ -1,6 +1,7 @@ package org.ethereum.jsontestsuite; import org.ethereum.core.BlockchainImpl; +import org.ethereum.core.Block; import org.ethereum.core.TransactionExecutor; import org.ethereum.db.BlockStoreDummy; import org.ethereum.db.ByteArrayWrapper; @@ -84,6 +85,21 @@ public class TestRunner { byte[] coinbase = testCase.getEnv().getCurrentCoinbase(); ProgramInvokeFactory invokeFactory = new TestProgramInvokeFactory(testCase.getEnv()); + Block block = new Block( + ByteUtil.EMPTY_BYTE_ARRAY, + ByteUtil.EMPTY_BYTE_ARRAY, + coinbase, + ByteUtil.EMPTY_BYTE_ARRAY, + testCase.getEnv().getCurrentDifficulty(), + new BigInteger(testCase.getEnv().getCurrentNumber()).longValue(), + new BigInteger(testCase.getEnv().getCurrentGasLimit()).longValue(), + 0L, + new BigInteger(testCase.getEnv().getCurrentTimestamp()).longValue(), + ByteUtil.ZERO_BYTE_ARRAY, + ByteUtil.ZERO_BYTE_ARRAY, + null, null); + + blockchain.setBestBlock(block); blockchain.setProgramInvokeFactory(invokeFactory); blockchain.startTracking(); diff --git a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java index b4320900..864daa70 100644 --- a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java +++ b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java @@ -114,8 +114,6 @@ public class GitHubStateTest { Set excluded = new HashSet<>(); //todo: it goes OOG, because no gasLimit is given. So it does not change the state. - excluded.add("TransactionFromCoinbaseHittingBlockGasLimit1"); - String json = JSONReader.loadJSON("StateTests/stTransactionTest.json"); GitHubJSONTestSuite.runGitHubJsonStateTest(json, excluded); } From 43b89fe161d73ad9c7c00e89acec5622b148bd9d Mon Sep 17 00:00:00 2001 From: Faiz Khan Date: Tue, 10 Feb 2015 14:47:14 -0600 Subject: [PATCH 2/5] Remove passing tests --- .../test/java/test/ethereum/jsontestsuite/GitHubStateTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java index 864daa70..edae3fff 100644 --- a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java +++ b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java @@ -98,8 +98,6 @@ public class GitHubStateTest { public void stSystemOperationsTest() throws ParseException { Set excluded = new HashSet<>(); - excluded.add("createNameRegistratorZeroMem2"); - excluded.add("testVMtest"); excluded.add("createWithInvalidOpcode"); excluded.add("testRandomTest"); From 8d8b734859eaf905b4595b0b07d12104329cecb6 Mon Sep 17 00:00:00 2001 From: Faiz Khan Date: Tue, 10 Feb 2015 15:35:06 -0600 Subject: [PATCH 3/5] Fix regressions, use signum constructor for BigInteger --- .../main/java/org/ethereum/jsontestsuite/TestRunner.java | 6 +++--- .../java/test/ethereum/jsontestsuite/GitHubStateTest.java | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) 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 b65dfc55..edeaf433 100644 --- a/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java +++ b/ethereumj-core/src/main/java/org/ethereum/jsontestsuite/TestRunner.java @@ -89,10 +89,10 @@ public class TestRunner { coinbase, ByteUtil.EMPTY_BYTE_ARRAY, testCase.getEnv().getCurrentDifficulty(), - new BigInteger(testCase.getEnv().getCurrentNumber()).longValue(), - new BigInteger(testCase.getEnv().getCurrentGasLimit()).longValue(), + new BigInteger(1, testCase.getEnv().getCurrentNumber()).longValue(), + new BigInteger(1, testCase.getEnv().getCurrentGasLimit()).longValue(), 0L, - new BigInteger(testCase.getEnv().getCurrentTimestamp()).longValue(), + new BigInteger(1, testCase.getEnv().getCurrentTimestamp()).longValue(), ByteUtil.ZERO_BYTE_ARRAY, ByteUtil.ZERO_BYTE_ARRAY, null, null); diff --git a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java index edae3fff..09d10765 100644 --- a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java +++ b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java @@ -26,8 +26,6 @@ public class GitHubStateTest { public void runWithExcludedTest() throws ParseException { Set excluded = new HashSet<>(); - - String json = JSONReader.loadJSON("StateTests/stPreCompiledContracts.json"); GitHubJSONTestSuite.runGitHubJsonStateTest(json, excluded); } From 5e8c79518742a5de70f11a2a98f4c71137f5aede Mon Sep 17 00:00:00 2001 From: Faiz Khan Date: Tue, 10 Feb 2015 15:36:28 -0600 Subject: [PATCH 4/5] Trigger buildbot --- .../test/java/test/ethereum/jsontestsuite/GitHubStateTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java index 09d10765..5f7491e9 100644 --- a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java +++ b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java @@ -42,7 +42,6 @@ public class GitHubStateTest { public void stInitCodeTest() throws ParseException { // [V] Set excluded = new HashSet<>(); - String json = JSONReader.loadJSON("StateTests/stInitCodeTest.json"); GitHubJSONTestSuite.runGitHubJsonStateTest(json, excluded); } From 6198be355abfa0b7ed7ad2d1a84dfd1ef18aa036 Mon Sep 17 00:00:00 2001 From: Faiz Khan Date: Tue, 10 Feb 2015 15:58:46 -0600 Subject: [PATCH 5/5] Remove passing tests --- .../test/java/test/ethereum/jsontestsuite/GitHubStateTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java index 5f7491e9..b444fcb0 100644 --- a/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java +++ b/ethereumj-core/src/test/java/test/ethereum/jsontestsuite/GitHubStateTest.java @@ -95,8 +95,6 @@ public class GitHubStateTest { public void stSystemOperationsTest() throws ParseException { Set excluded = new HashSet<>(); - excluded.add("createWithInvalidOpcode"); - excluded.add("testRandomTest"); String json = JSONReader.loadJSON("StateTests/stSystemOperationsTest.json");