Search in sources :

Example 1 with GeneralStateTestCaseSpec

use of org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseSpec in project besu by hyperledger.

the class StateTestSubCommand method run.

@Override
public void run() {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.disable(Feature.AUTO_CLOSE_SOURCE);
    final JavaType javaType = objectMapper.getTypeFactory().constructParametricType(Map.class, String.class, GeneralStateTestCaseSpec.class);
    try {
        if (stateTestFiles.isEmpty()) {
            // if no state tests were specified use standard input to get filenames
            final BufferedReader in = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
            while (true) {
                final String fileName = in.readLine();
                if (fileName == null) {
                    // reached end of file.  Stop the loop.
                    break;
                }
                final File file = new File(fileName);
                if (file.isFile()) {
                    try {
                        final Map<String, GeneralStateTestCaseSpec> generalStateTests = objectMapper.readValue(file, javaType);
                        executeStateTest(generalStateTests);
                    } catch (final JsonProcessingException jpe) {
                        output.println("File content error: " + jpe);
                    }
                } else {
                    output.println("File not found: " + fileName);
                }
            }
        } else {
            for (final File stateTestFile : stateTestFiles) {
                final Map<String, GeneralStateTestCaseSpec> generalStateTests = objectMapper.readValue(stateTestFile, javaType);
                executeStateTest(generalStateTests);
            }
        }
    } catch (final IOException e) {
        LOG.error("Unable to read state file", e);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) GeneralStateTestCaseSpec(org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseSpec) IOException(java.io.IOException) File(java.io.File) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 GeneralStateTestCaseSpec (org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseSpec)1