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 8f31aca2..edeaf433 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.*; import org.ethereum.facade.Repository; @@ -82,6 +83,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(1, testCase.getEnv().getCurrentNumber()).longValue(), + new BigInteger(1, testCase.getEnv().getCurrentGasLimit()).longValue(), + 0L, + new BigInteger(1, 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..b444fcb0 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); } @@ -44,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); } @@ -98,10 +95,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"); String json = JSONReader.loadJSON("StateTests/stSystemOperationsTest.json"); @@ -114,8 +107,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); }