fix toml parsing of Long option types (#3055)

Signed-off-by: garyschulte <garyschulte@gmail.com>

Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/3059/head
garyschulte 3 years ago committed by GitHub
parent 7952452aa0
commit 5c0763847d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      besu/src/main/java/org/hyperledger/besu/cli/options/unstable/DataStorageOptions.java
  2. 2
      besu/src/main/java/org/hyperledger/besu/cli/util/TomlConfigFileDefaultProvider.java
  3. 12
      besu/src/test/java/org/hyperledger/besu/cli/TomlConfigFileDefaultProviderTest.java

@ -46,6 +46,7 @@ public class DataStorageOptions implements CLIOptions<DataStorageConfiguration>
@Option( @Option(
names = {BONSAI_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD}, names = {BONSAI_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD},
hidden = true, hidden = true,
paramLabel = "<LONG>",
description = description =
"Limit of back layers that can be loaded with BONSAI (default: ${DEFAULT-VALUE}).", "Limit of back layers that can be loaded with BONSAI (default: ${DEFAULT-VALUE}).",
arity = "1") arity = "1")

@ -70,6 +70,8 @@ public class TomlConfigFileDefaultProvider implements IDefaultValueProvider {
defaultValue = getListEntryAsString(optionSpec); defaultValue = getListEntryAsString(optionSpec);
} else if (optionSpec.type().equals(Integer.class) || optionSpec.type().equals(int.class)) { } else if (optionSpec.type().equals(Integer.class) || optionSpec.type().equals(int.class)) {
defaultValue = getIntegerEntryAsString(optionSpec); defaultValue = getIntegerEntryAsString(optionSpec);
} else if (optionSpec.type().equals(Long.class) || optionSpec.type().equals(long.class)) {
defaultValue = getIntegerEntryAsString(optionSpec);
} else if (optionSpec.type().equals(Wei.class)) { } else if (optionSpec.type().equals(Wei.class)) {
defaultValue = getIntegerEntryAsString(optionSpec); defaultValue = getIntegerEntryAsString(optionSpec);
} else if (optionSpec.type().equals(BigInteger.class)) { } else if (optionSpec.type().equals(BigInteger.class)) {

@ -56,6 +56,7 @@ public class TomlConfigFileDefaultProviderTest {
when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec); when(mockCommandLine.getCommandSpec()).thenReturn(mockCommandSpec);
Map<String, OptionSpec> validOptionsMap = new HashMap<>(); Map<String, OptionSpec> validOptionsMap = new HashMap<>();
validOptionsMap.put("--a-short-option", null); validOptionsMap.put("--a-short-option", null);
validOptionsMap.put("--an-actual-long-option", null);
validOptionsMap.put("--a-longer-option", null); validOptionsMap.put("--a-longer-option", null);
when(mockCommandSpec.optionsMap()).thenReturn(validOptionsMap); when(mockCommandSpec.optionsMap()).thenReturn(validOptionsMap);
@ -65,6 +66,8 @@ public class TomlConfigFileDefaultProviderTest {
fileWriter.write("a-short-option='123'"); fileWriter.write("a-short-option='123'");
fileWriter.newLine(); fileWriter.newLine();
fileWriter.write("an-actual-long-option=" + Long.MAX_VALUE);
fileWriter.newLine();
fileWriter.write("a-longer-option='1234'"); fileWriter.write("a-longer-option='1234'");
fileWriter.flush(); fileWriter.flush();
@ -86,6 +89,15 @@ public class TomlConfigFileDefaultProviderTest {
.build())) .build()))
.isEqualTo("123"); .isEqualTo("123");
// this option must be found in config as one of its names is present in the file.
// also this is a long.
assertThat(
providerUnderTest.defaultValue(
OptionSpec.builder("an-actual-long-option", "another-name-for-the-option")
.type(Long.class)
.build()))
.isEqualTo(String.valueOf(Long.MAX_VALUE));
// this option must be found in config as one of its names is present in the file. // this option must be found in config as one of its names is present in the file.
// also this is the longest one. // also this is the longest one.
assertThat( assertThat(

Loading…
Cancel
Save