diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java index 9605b4b2e1..c5de2c7924 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApi.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(); + } } diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApis.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApis.java index c2c31be7da..38c7bee0e4 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApis.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/RpcApis.java @@ -25,7 +25,7 @@ public class RpcApis { public static final Collection DEFAULT_JSON_RPC_APIS = Arrays.asList(ETH, NET, WEB3); - public static final Optional valueOf(final String name) { + public static Optional 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(); } } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index f735a1d3a0..2eaa8b569f 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -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 rpcApis = - Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3, CliqueRpcApis.CLIQUE, IbftRpcApis.IBFT); + private final Collection 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 wsApis = - Arrays.asList(RpcApis.ETH, RpcApis.NET, RpcApis.WEB3, CliqueRpcApis.CLIQUE, IbftRpcApis.IBFT); + private final Collection 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; } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index 81f3d2fc2e..35002bbff2 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -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";