[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;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
public class RpcApi {
@ -41,4 +42,9 @@ public class RpcApi {
public int hashCode() {
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 Optional<RpcApi> valueOf(final String name) {
public static Optional<RpcApi> valueOf(final String name) {
if (name.equals(ETH.getCliValue())) {
return Optional.of(ETH);
} 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();
}
}

@ -44,7 +44,6 @@ import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
@ -276,10 +275,10 @@ public class PantheonCommand implements Runnable {
split = ",",
arity = "1..*",
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 =
Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3, CliqueRpcApis.CLIQUE, IbftRpcApis.IBFT);
private final Collection<RpcApi> rpcApis = null;
@Option(
names = {"--ws-enabled"},
@ -303,10 +302,10 @@ public class PantheonCommand implements Runnable {
split = ",",
arity = "1..*",
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 =
Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3, CliqueRpcApis.CLIQUE, IbftRpcApis.IBFT);
private final Collection<RpcApi> wsApis = null;
@Option(
names = {"--dev-mode"},
@ -453,7 +452,7 @@ public class PantheonCommand implements Runnable {
webSocketConfiguration.setEnabled(isWsRpcEnabled);
webSocketConfiguration.setHost(wsHostAndPort.getHost());
webSocketConfiguration.setPort(wsHostAndPort.getPort());
webSocketConfiguration.setRpcApis(rpcApis);
webSocketConfiguration.setRpcApis(wsApis);
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.eth.sync.SyncMode;
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.util.bytes.BytesValue;
@ -105,6 +106,13 @@ public class PantheonCommandTest extends CommandTestAbstract {
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
public void callingVersionDisplayPantheonInfoVersion() {
parseCommand("--version");
@ -521,6 +529,30 @@ public class PantheonCommandTest extends CommandTestAbstract {
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
public void jsonRpcHostAndPortOptionMustBeUsed() {
@ -741,6 +773,30 @@ public class PantheonCommandTest extends CommandTestAbstract {
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
public void wsRpcHostAndPortOptionMustBeUsed() {
final String host = "1.2.3.4";

Loading…
Cancel
Save