From 3bf6e52d1aa45d0ddb45a73f7dae536839171223 Mon Sep 17 00:00:00 2001 From: Mark Terry Date: Mon, 4 Feb 2019 13:30:06 +1000 Subject: [PATCH] [FIX] PR fixes and acceptance test refactoring. --- .../pantheon/tests/acceptance/dsl/node/PantheonNode.java | 6 +++--- .../acceptance/dsl/node/ThreadPantheonNodeRunner.java | 7 ++++--- .../dsl/node/factory/PantheonFactoryConfiguration.java | 8 +++++--- .../node/factory/PantheonFactoryConfigurationBuilder.java | 6 +++--- .../jsonrpc/perm/PermGetNodesWhitelistAcceptanceTest.java | 1 - .../ethereum/jsonrpc/JsonRpcHttpServiceLoginTest.java | 3 +-- .../main/java/tech/pegasys/pantheon/RunnerBuilder.java | 7 ++++--- .../java/tech/pegasys/pantheon/cli/PantheonCommand.java | 5 +++-- .../src/test/java/tech/pegasys/pantheon/RunnerTest.java | 4 +--- .../tech/pegasys/pantheon/cli/CommandTestAbstract.java | 5 +---- .../tech/pegasys/pantheon/cli/PantheonCommandTest.java | 2 +- 11 files changed, 26 insertions(+), 28 deletions(-) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java index 05c0097638..477c6f75c2 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java @@ -78,7 +78,7 @@ public class PantheonNode implements Node, NodeConfiguration, RunnableNode, Auto private final JsonRpcConfiguration jsonRpcConfiguration; private final WebSocketConfiguration webSocketConfiguration; private final MetricsConfiguration metricsConfiguration; - private final PermissioningConfiguration permissioningConfiguration; + private final Optional permissioningConfiguration; private final GenesisConfigProvider genesisConfigProvider; private final boolean devMode; private final boolean discoveryEnabled; @@ -93,7 +93,7 @@ public PantheonNode( final JsonRpcConfiguration jsonRpcConfiguration, final WebSocketConfiguration webSocketConfiguration, final MetricsConfiguration metricsConfiguration, - final PermissioningConfiguration permissioningConfiguration, + final Optional permissioningConfiguration, final boolean devMode, final GenesisConfigProvider genesisConfigProvider, final int p2pPort, @@ -348,7 +348,7 @@ public boolean isDiscoveryEnabled() { return discoveryEnabled; } - PermissioningConfiguration getPermissioningConfiguration() { + Optional getPermissioningConfiguration() { return permissioningConfiguration; } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java index c78db1c140..b5c0496f6b 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java @@ -30,7 +30,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -79,8 +78,11 @@ public void startNode(final PantheonNode node) { throw new RuntimeException("Error building PantheonController", e); } + RunnerBuilder runnerBuilder = new RunnerBuilder(); + node.getPermissioningConfiguration().ifPresent(runnerBuilder::permissioningConfiguration); + final Runner runner = - new RunnerBuilder() + runnerBuilder .vertx(Vertx.vertx()) .pantheonController(pantheonController) .discovery(node.isDiscoveryEnabled()) @@ -94,7 +96,6 @@ public void startNode(final PantheonNode node) { .bannedNodeIds(Collections.emptySet()) .metricsSystem(noOpMetricsSystem) .metricsConfiguration(node.metricsConfiguration()) - .permissioningConfiguration(Optional.of(node.getPermissioningConfiguration())) .p2pEnabled(node.p2pEnabled()) .build(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfiguration.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfiguration.java index 5daccc423b..97e33b2240 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfiguration.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfiguration.java @@ -19,6 +19,8 @@ import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider; +import java.util.Optional; + class PantheonFactoryConfiguration { private final String name; @@ -26,7 +28,7 @@ class PantheonFactoryConfiguration { private final JsonRpcConfiguration jsonRpcConfiguration; private final WebSocketConfiguration webSocketConfiguration; private final MetricsConfiguration metricsConfiguration; - private final PermissioningConfiguration permissioningConfiguration; + private final Optional permissioningConfiguration; private final boolean devMode; private final GenesisConfigProvider genesisConfigProvider; private final Boolean p2pEnabled; @@ -38,7 +40,7 @@ class PantheonFactoryConfiguration { final JsonRpcConfiguration jsonRpcConfiguration, final WebSocketConfiguration webSocketConfiguration, final MetricsConfiguration metricsConfiguration, - final PermissioningConfiguration permissioningConfiguration, + final Optional permissioningConfiguration, final boolean devMode, final GenesisConfigProvider genesisConfigProvider, final Boolean p2pEnabled, @@ -75,7 +77,7 @@ public MetricsConfiguration getMetricsConfiguration() { return metricsConfiguration; } - public PermissioningConfiguration getPermissioningConfiguration() { + public Optional getPermissioningConfiguration() { return permissioningConfiguration; } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfigurationBuilder.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfigurationBuilder.java index 8fae0fb16b..c25ac52902 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfigurationBuilder.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonFactoryConfigurationBuilder.java @@ -32,8 +32,8 @@ public class PantheonFactoryConfigurationBuilder { private JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault(); private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault(); private MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); - private PermissioningConfiguration permissioningConfiguration = - PermissioningConfiguration.createDefault(); + private Optional permissioningConfiguration = + PermissioningConfiguration.disabled(); private boolean devMode = true; private GenesisConfigProvider genesisConfigProvider = ignore -> Optional.empty(); private Boolean p2pEnabled = true; @@ -94,7 +94,7 @@ public PantheonFactoryConfigurationBuilder webSocketEnabled() { public PantheonFactoryConfigurationBuilder setPermissioningConfiguration( final PermissioningConfiguration permissioningConfiguration) { - this.permissioningConfiguration = permissioningConfiguration; + this.permissioningConfiguration = Optional.of(permissioningConfiguration); return this; } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermGetNodesWhitelistAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermGetNodesWhitelistAcceptanceTest.java index c0b05ae705..061263d729 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermGetNodesWhitelistAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermGetNodesWhitelistAcceptanceTest.java @@ -36,7 +36,6 @@ public class PermGetNodesWhitelistAcceptanceTest extends AcceptanceTestBase { @Before public void setUp() throws Exception { - node = pantheon.createNodeWithNodesWhitelist("node1", nodesWhitelist); cluster.start(node); } diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceLoginTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceLoginTest.java index 49ab60172d..2fafe09c9d 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceLoginTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcHttpServiceLoginTest.java @@ -29,7 +29,6 @@ import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; -import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController; import tech.pegasys.pantheon.ethereum.privacy.PrivateTransactionHandler; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; @@ -148,7 +147,7 @@ public static void initServerAndClient() throws Exception { mock(EthHashMiningCoordinator.class), new NoOpMetricsSystem(), supportedCapabilities, - mock(AccountWhitelistController.class), + Optional.empty(), JSON_RPC_APIS, mock(PrivateTransactionHandler.class))); service = createJsonRpcHttpService(); diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index b42d07b909..c5feb5a0ce 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -88,7 +88,8 @@ public class RunnerBuilder { private Collection bannedNodeIds; private MetricsConfiguration metricsConfiguration; private MetricsSystem metricsSystem; - private Optional permissioningConfiguration; + private Optional permissioningConfiguration = + PermissioningConfiguration.disabled(); public RunnerBuilder vertx(final Vertx vertx) { this.vertx = vertx; @@ -141,8 +142,8 @@ public RunnerBuilder webSocketConfiguration(final WebSocketConfiguration webSock } public RunnerBuilder permissioningConfiguration( - final Optional permissioningConfiguration) { - this.permissioningConfiguration = permissioningConfiguration; + final PermissioningConfiguration permissioningConfiguration) { + this.permissioningConfiguration = Optional.of(permissioningConfiguration); return this; } 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 6511f364cd..9ba4e81258 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -737,7 +737,7 @@ MetricsConfiguration metricsConfiguration() { private Optional permissioningConfiguration() { if (!permissionsAccountsEnabled && !permissionsNodesEnabled) { - return Optional.empty(); + return PermissioningConfiguration.disabled(); } final PermissioningConfiguration permissioningConfiguration = @@ -792,6 +792,8 @@ private void synchronize( checkNotNull(runnerBuilder); + permissioningConfiguration.ifPresent(runnerBuilder::permissioningConfiguration); + final Runner runner = runnerBuilder .vertx(Vertx.vertx()) @@ -808,7 +810,6 @@ private void synchronize( .bannedNodeIds(bannedNodeIds) .metricsSystem(metricsSystem) .metricsConfiguration(metricsConfiguration) - .permissioningConfiguration(permissioningConfiguration) .build(); addShutdownHook(runner); diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java index e340eac37d..f66e272520 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java @@ -48,7 +48,6 @@ import java.nio.file.Path; import java.util.Collections; import java.util.List; -import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -132,8 +131,7 @@ private void syncFromGenesis(final SyncMode mode) throws Exception { final JsonRpcConfiguration aheadJsonRpcConfiguration = jsonRpcConfiguration(); final WebSocketConfiguration aheadWebSocketConfiguration = wsRpcConfiguration(); final MetricsConfiguration aheadMetricsConfiguration = metricsConfiguration(); - final Optional aheadPermissioningConfiguration = - Optional.of(permissioningConfiguration()); + final PermissioningConfiguration aheadPermissioningConfiguration = permissioningConfiguration(); final RunnerBuilder runnerBuilder = new RunnerBuilder() .vertx(Vertx.vertx()) diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java index cc556bbd37..1dfc474415 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/CommandTestAbstract.java @@ -35,7 +35,6 @@ import java.nio.file.Path; import java.util.Collection; import java.util.List; -import java.util.Optional; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -83,8 +82,7 @@ public abstract class CommandTestAbstract { @Captor ArgumentCaptor wsRpcConfigArgumentCaptor; @Captor ArgumentCaptor metricsConfigArgumentCaptor; - @Captor - ArgumentCaptor> permissioningConfigurationArgumentCaptor; + @Captor ArgumentCaptor permissioningConfigurationArgumentCaptor; @Captor ArgumentCaptor> uriListArgumentCaptor; @@ -122,7 +120,6 @@ public void initMocks() throws Exception { when(mockRunnerBuilder.p2pEnabled(anyBoolean())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.jsonRpcConfiguration(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.webSocketConfiguration(any())).thenReturn(mockRunnerBuilder); - when(mockRunnerBuilder.permissioningConfiguration(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.dataDir(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.bannedNodeIds(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.metricsSystem(any())).thenReturn(mockRunnerBuilder); 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 bde125cd16..bf1f77e87b 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -339,7 +339,7 @@ public void permissionsTomlPathMustUseOption() throws IOException { .permissioningConfiguration(permissioningConfigurationArgumentCaptor.capture()); verify(mockRunnerBuilder).build(); - assertThat(permissioningConfigurationArgumentCaptor.getValue().get()) + assertThat(permissioningConfigurationArgumentCaptor.getValue()) .isEqualToComparingFieldByField(permissioningConfiguration); assertThat(commandErrorOutput.toString()).isEmpty();