[MINOR] Fix --rpc-api and --ws-api help output (#147)

* Fix default values for rpc-api and ws-api in --help output. Use ws-api values from the command line instead of always using the rpc apis.
Adrian Sutton 6 years ago committed by GitHub
parent 79b343fef9
commit 1849460e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java
  2. 4
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApis.java
  3. 15
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
  4. 56
      pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java

@ -12,6 +12,7 @@
*/ */
package tech.pegasys.pantheon.ethereum.jsonrpc; package tech.pegasys.pantheon.ethereum.jsonrpc;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects; import com.google.common.base.Objects;
public class RpcApi { public class RpcApi {
@ -41,4 +42,9 @@ public class RpcApi {
public int hashCode() { public int hashCode() {
return Objects.hashCode(cliValue); return Objects.hashCode(cliValue);
} }
@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("cliValue", cliValue).toString();
}
} }

@ -25,7 +25,7 @@ public class RpcApis {
public static final Collection<RpcApi> DEFAULT_JSON_RPC_APIS = Arrays.asList(ETH, NET, WEB3); public static final Collection<RpcApi> DEFAULT_JSON_RPC_APIS = Arrays.asList(ETH, NET, WEB3);
public static final Optional<RpcApi> valueOf(final String name) { public static Optional<RpcApi> valueOf(final String name) {
if (name.equals(ETH.getCliValue())) { if (name.equals(ETH.getCliValue())) {
return Optional.of(ETH); return Optional.of(ETH);
} else if (name.equals(DEBUG.getCliValue())) { } else if (name.equals(DEBUG.getCliValue())) {
@ -41,7 +41,7 @@ public class RpcApis {
} }
} }
public static final String getValue(final RpcApi rpcapi) { public static String getValue(final RpcApi rpcapi) {
return rpcapi.getCliValue(); return rpcapi.getCliValue();
} }
} }

@ -44,7 +44,6 @@ import java.nio.file.Files;
import java.nio.file.InvalidPathException; import java.nio.file.InvalidPathException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -276,10 +275,10 @@ public class PantheonCommand implements Runnable {
split = ",", split = ",",
arity = "1..*", arity = "1..*",
converter = RpcApisConverter.class, converter = RpcApisConverter.class,
description = "Comma separated APIs to enable on JSON-RPC channel. default: ${DEFAULT-VALUE}" description = "Comma separated APIs to enable on JSON-RPC channel. default: ${DEFAULT-VALUE}",
defaultValue = "ETH,NET,WEB3,CLIQUE,IBFT"
) )
private final Collection<RpcApi> rpcApis = private final Collection<RpcApi> rpcApis = null;
Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3, CliqueRpcApis.CLIQUE, IbftRpcApis.IBFT);
@Option( @Option(
names = {"--ws-enabled"}, names = {"--ws-enabled"},
@ -303,10 +302,10 @@ public class PantheonCommand implements Runnable {
split = ",", split = ",",
arity = "1..*", arity = "1..*",
converter = RpcApisConverter.class, converter = RpcApisConverter.class,
description = "Comma separated APIs to enable on WebSocket channel. default: ${DEFAULT-VALUE}" description = "Comma separated APIs to enable on WebSocket channel. default: ${DEFAULT-VALUE}",
defaultValue = "ETH,NET,WEB3,CLIQUE,IBFT"
) )
private final Collection<RpcApi> wsApis = private final Collection<RpcApi> wsApis = null;
Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3, CliqueRpcApis.CLIQUE, IbftRpcApis.IBFT);
@Option( @Option(
names = {"--dev-mode"}, names = {"--dev-mode"},
@ -453,7 +452,7 @@ public class PantheonCommand implements Runnable {
webSocketConfiguration.setEnabled(isWsRpcEnabled); webSocketConfiguration.setEnabled(isWsRpcEnabled);
webSocketConfiguration.setHost(wsHostAndPort.getHost()); webSocketConfiguration.setHost(wsHostAndPort.getHost());
webSocketConfiguration.setPort(wsHostAndPort.getPort()); webSocketConfiguration.setPort(wsHostAndPort.getPort());
webSocketConfiguration.setRpcApis(rpcApis); webSocketConfiguration.setRpcApis(wsApis);
return webSocketConfiguration; return webSocketConfiguration;
} }

@ -35,6 +35,7 @@ import tech.pegasys.pantheon.ethereum.core.MiningParameters;
import tech.pegasys.pantheon.ethereum.core.Wei; import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode; import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
@ -105,6 +106,13 @@ public class PantheonCommandTest extends CommandTestAbstract {
assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty();
} }
@Test
public void callingHelpDisplaysDefaultRpcApisCorrectly() {
parseCommand("--help");
assertThat(commandOutput.toString()).contains("default: ETH,NET,WEB3,CLIQUE,IBFT");
assertThat(commandErrorOutput.toString()).isEmpty();
}
@Test @Test
public void callingVersionDisplayPantheonInfoVersion() { public void callingVersionDisplayPantheonInfoVersion() {
parseCommand("--version"); parseCommand("--version");
@ -521,6 +529,30 @@ public class PantheonCommandTest extends CommandTestAbstract {
assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty();
} }
@Test
public void rpcApisPropertyMustBeUsed() {
parseCommand("--rpc-api", "ETH,NET");
verify(mockRunnerBuilder)
.build(
any(),
any(),
anyBoolean(),
any(),
anyString(),
anyInt(),
anyInt(),
jsonRpcConfigArgumentCaptor.capture(),
any(),
any());
assertThat(jsonRpcConfigArgumentCaptor.getValue().getRpcApis())
.containsExactlyInAnyOrder(RpcApis.ETH, RpcApis.NET);
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
}
@Test @Test
public void jsonRpcHostAndPortOptionMustBeUsed() { public void jsonRpcHostAndPortOptionMustBeUsed() {
@ -741,6 +773,30 @@ public class PantheonCommandTest extends CommandTestAbstract {
assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(commandErrorOutput.toString()).isEmpty();
} }
@Test
public void wsApiPropertyMustBeUsed() {
parseCommand("--ws-api", "ETH, NET");
verify(mockRunnerBuilder)
.build(
any(),
any(),
anyBoolean(),
any(),
anyString(),
anyInt(),
anyInt(),
any(),
wsRpcConfigArgumentCaptor.capture(),
any());
assertThat(wsRpcConfigArgumentCaptor.getValue().getRpcApis())
.containsExactlyInAnyOrder(RpcApis.ETH, RpcApis.NET);
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
}
@Test @Test
public void wsRpcHostAndPortOptionMustBeUsed() { public void wsRpcHostAndPortOptionMustBeUsed() {
final String host = "1.2.3.4"; final String host = "1.2.3.4";

Loading…
Cancel
Save