Skip to content

Commit

Permalink
warning invalid sync mode option [hyperledger#3884] (hyperledger#4017)
Browse files Browse the repository at this point in the history
Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
  • Loading branch information
gfukushima authored and macfarla committed Jun 28, 2022
1 parent 78717ad commit bf81dd7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,6 @@ private void registerConverters() {
commandLine.registerConverter(Address.class, Address::fromHexStringStrict);
commandLine.registerConverter(Bytes.class, Bytes::fromHexString);
commandLine.registerConverter(Level.class, Level::valueOf);
commandLine.registerConverter(SyncMode.class, SyncMode::fromString);
commandLine.registerConverter(MetricsProtocol.class, MetricsProtocol::fromString);
commandLine.registerConverter(UInt256.class, (arg) -> UInt256.valueOf(new BigInteger(arg)));
commandLine.registerConverter(Wei.class, (arg) -> Wei.of(Long.parseUnsignedLong(arg)));
Expand Down
11 changes: 11 additions & 0 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,17 @@ public void syncMode_full() {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void syncMode_invalid() {
parseCommand("--sync-mode", "bogus");
Mockito.verifyNoInteractions(mockRunnerBuilder);

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8))
.contains(
"Invalid value for option '--sync-mode': expected one of [FULL, FAST, X_SNAP, X_CHECKPOINT] (case-insensitive) but was 'bogus'");
}

@Test
public void syncMode_full_by_default_for_dev() {
parseCommand("--network", "dev");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ public enum SyncMode {
// Perform snapsync but starting from a checkpoint instead of starting from genesis
X_CHECKPOINT;

public static SyncMode fromString(final String str) {
for (final SyncMode mode : SyncMode.values()) {
if (mode.name().equalsIgnoreCase(str)) {
return mode;
}
}
return null;
}

public static boolean isFullSync(final SyncMode syncMode) {
return !EnumSet.of(SyncMode.FAST, SyncMode.X_SNAP, SyncMode.X_CHECKPOINT).contains(syncMode);
}
Expand Down

0 comments on commit bf81dd7

Please sign in to comment.