diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java index 6d45bfdd0a..036d278908 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java @@ -66,6 +66,7 @@ import picocli.CommandLine.Option; abbreviateSynopsis = true, name = "evm", mixinStandardHelpOptions = true, + versionProvider = VersionProvider.class, sortOptions = false, header = "Usage:", synopsisHeading = "%n", diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java index 4848d7f66c..24e110c69c 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java @@ -40,14 +40,18 @@ import org.hyperledger.besu.ethereum.vm.OperationTracer; import org.hyperledger.besu.ethereum.vm.StandardJsonTracer; import org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import com.fasterxml.jackson.core.JsonParser.Feature; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -65,7 +69,8 @@ import picocli.CommandLine.ParentCommand; @Command( name = COMMAND_NAME, description = "Execute an Ethereum State Test.", - mixinStandardHelpOptions = true) + mixinStandardHelpOptions = true, + versionProvider = VersionProvider.class) public class StateTestSubCommand implements Runnable { private static final Logger LOG = LogManager.getLogger(); @@ -95,14 +100,27 @@ public class StateTestSubCommand implements Runnable { .constructParametricType(Map.class, String.class, GeneralStateTestCaseSpec.class); try { if (stateTestFiles.isEmpty()) { - // if no state tests were specified use standard input + // if no state tests were specified use standard input to get filenames + final BufferedReader in = + new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); while (true) { - final Map generalStateTests = - objectMapper.readValue(System.in, javaType); - if (generalStateTests == null || generalStateTests.isEmpty()) { + final String fileName = in.readLine(); + if (fileName == null) { + // reached end of file. Stop the loop. break; } - executeStateTest(generalStateTests); + final File file = new File(fileName); + if (file.isFile()) { + try { + final Map generalStateTests = + objectMapper.readValue(file, javaType); + executeStateTest(generalStateTests); + } catch (final JsonProcessingException jpe) { + System.out.println("File content error :" + jpe.toString()); + } + } else { + System.out.println("File not found:" + fileName); + } } } else { for (final File stateTestFile : stateTestFiles) { @@ -128,7 +146,7 @@ public class StateTestSubCommand implements Runnable { private void traceTestSpecs(final String test, final List specs) { Configurator.setLevel( "org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder", Level.OFF); - var referenceTestProtocolSchedules = ReferenceTestProtocolSchedules.create(); + final var referenceTestProtocolSchedules = ReferenceTestProtocolSchedules.create(); Configurator.setLevel("org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder", null); final OperationTracer tracer = // You should have picked Mercy. diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/VersionProvider.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/VersionProvider.java new file mode 100644 index 0000000000..cfe743fecb --- /dev/null +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/VersionProvider.java @@ -0,0 +1,30 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * + */ +package org.hyperledger.besu.evmtool; + +import org.hyperledger.besu.BesuInfo; + +import picocli.CommandLine; + +public class VersionProvider implements CommandLine.IVersionProvider { + + public VersionProvider() {} + + @Override + public String[] getVersion() { + return new String[] {"Hyperledger Besu EvmTool", BesuInfo.version()}; + } +}