Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning invalid sync mode option [#3884] #4017

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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