From 6013c8fdd9b6cbb762dc89d25af7769817fde4b7 Mon Sep 17 00:00:00 2001 From: Edward Date: Tue, 24 Sep 2019 12:36:25 +1000 Subject: [PATCH 1/2] Update version to 1.2.5-SNAPSHOT (#42) Signed-off-by: Edward Evans Signed-off-by: Abdelhamid Bakhta --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 34e8b022918..2bdb210324b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ org.gradle.jvmargs=-Xmx1g -version=1.2.4 +version=1.2.5-SNAPSHOT From 256ce70bf278aabee3942a522f5f3f74783bbc6f Mon Sep 17 00:00:00 2001 From: Abdelhamid Bakhta Date: Wed, 25 Sep 2019 09:29:03 +0200 Subject: [PATCH 2/2] Disallow comments in Genesis JSON file Signed-off-by: Abdelhamid Bakhta --- .../besu/config/GenesisConfigFile.java | 19 +------------------ .../besu/config/GenesisConfigFileTest.java | 16 ++++++++-------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java index 159734d6acb..04abc8f2dd9 100644 --- a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java +++ b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java @@ -23,7 +23,6 @@ import java.util.Optional; import java.util.stream.Stream; -import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.Streams; import com.google.common.io.Resources; @@ -72,23 +71,7 @@ public static GenesisConfigFile development() { } public static GenesisConfigFile fromConfig(final String jsonString) { - try { - final ObjectNode rootNode = JsonUtil.objectNodeFromString(jsonString, false); - return fromConfig(rootNode); - } catch (final RuntimeException re) { - if (re.getCause() instanceof JsonParseException) { - // we had a runtime exception cause by a jsom parse exception. - // try again with comments enabled - final ObjectNode rootNode = JsonUtil.objectNodeFromString(jsonString, true); - // if we get here comments is what broke things, warn and move on. - LOG.warn( - "The provided genesis file contains comments. " - + "In a future release of Besu this will not be supported."); - return fromConfig(rootNode); - } else { - throw re; - } - } + return fromConfig(JsonUtil.objectNodeFromString(jsonString, false)); } public static GenesisConfigFile fromConfig(final ObjectNode config) { diff --git a/config/src/test/java/org/hyperledger/besu/config/GenesisConfigFileTest.java b/config/src/test/java/org/hyperledger/besu/config/GenesisConfigFileTest.java index aa089c3a51d..28fce6b02e1 100644 --- a/config/src/test/java/org/hyperledger/besu/config/GenesisConfigFileTest.java +++ b/config/src/test/java/org/hyperledger/besu/config/GenesisConfigFileTest.java @@ -24,6 +24,7 @@ import java.util.function.Function; import java.util.stream.Collectors; +import com.fasterxml.jackson.core.JsonParseException; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.Test; @@ -208,14 +209,13 @@ public void shouldGetLargeChainId() { } @Test - public void acceptComments() { - // this test will change in the future to reject comments. - final GenesisConfigFile config = - GenesisConfigFile.fromConfig( - "{\"config\": { \"chainId\": 2017 }\n/* C comment }*/\n//C++ comment }\n}"); - - assertThat(config.getConfigOptions().getChainId()).contains(new BigInteger("2017")); - // Unfortunately there is no good (non-flakey) way to assert logs. + public void mustNotAcceptComments() { + assertThatThrownBy( + () -> + GenesisConfigFile.fromConfig( + "{\"config\": { \"chainId\": 2017 }\n/* C comment }*/\n//C++ comment }\n}")) + .hasCauseInstanceOf(JsonParseException.class) + .hasMessageContaining("Unexpected character ('/'"); } @Test