diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java index c7c5d8889b..6021afe0f5 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java @@ -25,6 +25,7 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Web3; import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.Cluster; import tech.pegasys.pantheon.tests.acceptance.dsl.node.factory.PantheonNodeFactory; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.factory.PermissionedNodeBuilder; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.clique.CliqueTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions; @@ -54,6 +55,7 @@ public class AcceptanceTestBase { protected final PantheonNodeFactory pantheon; protected final ContractVerifier contractVerifier; protected final WaitConditions wait; + protected final PermissionedNodeBuilder permissionedNodeBuilder; protected AcceptanceTestBase() { final EthTransactions ethTransactions = new EthTransactions(); @@ -75,6 +77,7 @@ protected AcceptanceTestBase() { pantheon = new PantheonNodeFactory(); contractVerifier = new ContractVerifier(accounts.getPrimaryBenefactor()); wait = new WaitConditions(ethTransactions, cliqueTransactions, ibftTransactions); + permissionedNodeBuilder = new PermissionedNodeBuilder(); } @After diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonNodeFactory.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonNodeFactory.java index f9b598e6e6..8d0e915c8e 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonNodeFactory.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PantheonNodeFactory.java @@ -26,21 +26,15 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; -import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; -import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; -import tech.pegasys.pantheon.ethereum.permissioning.WhitelistPersistor; -import tech.pegasys.pantheon.ethereum.permissioning.WhitelistPersistor.WHITELIST_TYPE; import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode; -import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -52,7 +46,7 @@ public class PantheonNodeFactory { - private PantheonNode create(final PantheonFactoryConfiguration config) throws IOException { + PantheonNode create(final PantheonFactoryConfiguration config) throws IOException { return new PantheonNode( config.getName(), config.getMiningParameters(), @@ -149,7 +143,7 @@ public PantheonNode createNodeWithP2pDisabled(final String name) throws IOExcept new PantheonFactoryConfigurationBuilder() .setName(name) .setP2pEnabled(false) - .setJsonRpcConfiguration(jsonRpcConfigWithPermissioning()) + .setJsonRpcConfiguration(createJsonRpcEnabledConfig()) .build()); } @@ -158,7 +152,7 @@ public PantheonNode createNodeWithP2pDisabledAndAdmin(final String name) throws new PantheonFactoryConfigurationBuilder() .setName(name) .setP2pEnabled(false) - .setJsonRpcConfiguration(jsonRpcConfigWithPermissioningAndAdmin()) + .setJsonRpcConfiguration(jsonRpcConfigWithAdmin()) .build()); } @@ -181,110 +175,6 @@ public PantheonNode createArchiveNodeWithRpcApis( .build()); } - public PantheonNode createNodeWithWhitelistsEnabled( - final String name, - final List nodesWhitelist, - final List accountsWhitelist, - final String tempFilePath) - throws IOException { - final LocalPermissioningConfiguration localPermissioningConfiguration = - LocalPermissioningConfiguration.createDefault(); - localPermissioningConfiguration.setNodeWhitelist(nodesWhitelist); - localPermissioningConfiguration.setNodePermissioningConfigFilePath(tempFilePath); - localPermissioningConfiguration.setAccountWhitelist(accountsWhitelist); - localPermissioningConfiguration.setAccountPermissioningConfigFilePath(tempFilePath); - - final PermissioningConfiguration permissioningConfiguration = - new PermissioningConfiguration( - Optional.of(localPermissioningConfiguration), Optional.empty()); - - return create( - new PantheonFactoryConfigurationBuilder() - .setName(name) - .setJsonRpcConfiguration(jsonRpcConfigWithPermissioning()) - .setPermissioningConfiguration(permissioningConfiguration) - .build()); - } - - public PantheonNode createNodeWithNodesWhitelist( - final String name, final Node... whitelistedNodes) throws IOException { - return createNodeWithNodesWhitelist(name, convertToEnodes(asList(whitelistedNodes))); - } - - public PantheonNode createNodeWithNodesWhitelist( - final String name, final List nodesWhitelist) throws IOException { - final LocalPermissioningConfiguration localPermissioningConfiguration = - LocalPermissioningConfiguration.createDefault(); - localPermissioningConfiguration.setNodeWhitelist(nodesWhitelist); - - final List whitelistAsStrings = - nodesWhitelist.parallelStream().map(URI::toString).collect(toList()); - final File tempFile = createTempPermissioningConfigurationFile(); - tempFile.deleteOnExit(); - localPermissioningConfiguration.setNodePermissioningConfigFilePath(tempFile.getPath()); - initPermissioningConfigurationFile( - WhitelistPersistor.WHITELIST_TYPE.NODES, whitelistAsStrings, tempFile.toPath()); - - final PermissioningConfiguration permissioningConfiguration = - new PermissioningConfiguration( - Optional.of(localPermissioningConfiguration), Optional.empty()); - - return create( - new PantheonFactoryConfigurationBuilder() - .setName(name) - .setJsonRpcConfiguration(jsonRpcConfigWithPermissioning()) - .setPermissioningConfiguration(permissioningConfiguration) - .build()); - } - - private List convertToEnodes(final List nodes) { - return nodes.stream() - .map(node -> (RunnableNode) node) - .map(RunnableNode::enodeUrl) - .collect(toList()); - } - - private void initPermissioningConfigurationFile( - final WhitelistPersistor.WHITELIST_TYPE listType, - final Collection whitelistVal, - final Path configFilePath) - throws IOException { - WhitelistPersistor.addNewConfigItem(listType, whitelistVal, configFilePath); - } - - public PantheonNode createNodeWithAccountsWhitelist( - final String name, final List accountsWhitelist) throws IOException { - final LocalPermissioningConfiguration localPermissioningConfiguration = - LocalPermissioningConfiguration.createDefault(); - localPermissioningConfiguration.setAccountWhitelist(accountsWhitelist); - localPermissioningConfiguration.setAccountPermissioningConfigFilePath( - createTempPermissioningConfigurationFile().getPath()); - - final File tempFile = createTempPermissioningConfigurationFile(); - tempFile.deleteOnExit(); - localPermissioningConfiguration.setAccountPermissioningConfigFilePath(tempFile.getPath()); - initPermissioningConfigurationFile( - WHITELIST_TYPE.ACCOUNTS, accountsWhitelist, tempFile.toPath()); - - final PermissioningConfiguration permissioningConfiguration = - new PermissioningConfiguration( - Optional.of(localPermissioningConfiguration), Optional.empty()); - - return create( - new PantheonFactoryConfigurationBuilder() - .setName(name) - .miningEnabled() - .setJsonRpcConfiguration(jsonRpcConfigWithPermissioning()) - .setPermissioningConfiguration(permissioningConfiguration) - .build()); - } - - private File createTempPermissioningConfigurationFile() throws IOException { - final File tempFile = File.createTempFile("temp", "temp"); - tempFile.deleteOnExit(); - return tempFile; - } - public PantheonNode createNodeWithNoDiscovery(final String name) throws IOException { return create( new PantheonFactoryConfigurationBuilder().setName(name).setDiscoveryEnabled(false).build()); @@ -414,18 +304,10 @@ private WebSocketConfiguration createWebSocketEnabledConfig() { return config; } - private JsonRpcConfiguration jsonRpcConfigWithPermissioning() { - return createJsonRpcConfigWithRpcApiEnabled(RpcApis.PERM); - } - private JsonRpcConfiguration jsonRpcConfigWithAdmin() { return createJsonRpcConfigWithRpcApiEnabled(RpcApis.ADMIN); } - private JsonRpcConfiguration jsonRpcConfigWithPermissioningAndAdmin() { - return createJsonRpcConfigWithRpcApiEnabled(RpcApis.PERM, RpcApis.ADMIN); - } - private JsonRpcConfiguration createJsonRpcConfigWithRpcApiEnabled(final RpcApi... rpcApi) { final JsonRpcConfiguration jsonRpcConfig = createJsonRpcEnabledConfig(); final List rpcApis = new ArrayList<>(jsonRpcConfig.getRpcApis()); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PermissionedNodeBuilder.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PermissionedNodeBuilder.java new file mode 100644 index 0000000000..81c4531934 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/factory/PermissionedNodeBuilder.java @@ -0,0 +1,243 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.tests.acceptance.dsl.node.factory; + +import static java.util.Collections.singletonList; +import static java.util.stream.Collectors.toList; + +import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; +import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; +import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; +import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; +import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningConfiguration; +import tech.pegasys.pantheon.ethereum.permissioning.WhitelistPersistor; +import tech.pegasys.pantheon.ethereum.permissioning.WhitelistPersistor.WHITELIST_TYPE; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + +import com.google.common.base.Charsets; +import org.assertj.core.util.Lists; + +public class PermissionedNodeBuilder { + + private String name; + + private boolean localConfigNodesPermissioningEnabled = false; + private Path localConfigNodesPermissioningFile = null; + private Collection localConfigPermittedNodes = null; + + private boolean localConfigAccountsPermissioningEnabled = false; + private Path localConfigAccountsPermissioningFile = null; + private Collection localConfigPermittedAccounts = null; + + private boolean smartContractPermissioningEnabled = false; + private String permissioningSmartContractAddress = null; + + public PermissionedNodeBuilder name(final String name) { + this.name = name; + return this; + } + + public PermissionedNodeBuilder nodesConfigFileEnabled() { + this.localConfigNodesPermissioningEnabled = true; + if (this.localConfigPermittedNodes == null) { + this.localConfigPermittedNodes = new ArrayList<>(); + } + return this; + } + + public PermissionedNodeBuilder nodesConfigFile(final Path file) { + this.localConfigNodesPermissioningFile = file; + return this; + } + + public PermissionedNodeBuilder nodesPermittedInConfig(final List nodes) { + this.localConfigNodesPermissioningEnabled = true; + this.localConfigPermittedNodes = new ArrayList<>(nodes); + return this; + } + + public PermissionedNodeBuilder nodesPermittedInConfig(final Node... nodes) { + this.localConfigNodesPermissioningEnabled = true; + this.localConfigPermittedNodes = new ArrayList<>(convertToEnodes(Lists.newArrayList(nodes))); + return this; + } + + public PermissionedNodeBuilder accountsConfigFileEnabled() { + this.localConfigAccountsPermissioningEnabled = true; + if (this.localConfigPermittedAccounts == null) { + this.localConfigPermittedAccounts = new ArrayList<>(); + } + return this; + } + + public PermissionedNodeBuilder accountsConfigFile(final Path file) { + this.localConfigAccountsPermissioningFile = file; + return this; + } + + public PermissionedNodeBuilder accountsPermittedInConfig(final List accounts) { + this.localConfigAccountsPermissioningEnabled = true; + this.localConfigPermittedAccounts = new ArrayList<>(accounts); + return this; + } + + public PermissionedNodeBuilder nodesContractEnabled(final String address) { + this.smartContractPermissioningEnabled = true; + this.permissioningSmartContractAddress = address; + throw new UnsupportedOperationException( + "Support for smart contract based permissioning ATs is coming soon..."); + } + + public PantheonNode build() { + if (name == null) { + name = "perm_node_" + UUID.randomUUID().toString().substring(0, 8); + } + + Optional localPermConfig = Optional.empty(); + if (localConfigNodesPermissioningEnabled || localConfigAccountsPermissioningEnabled) { + localPermConfig = Optional.of(localConfigPermissioningConfiguration()); + } + + Optional smartContractPermConfig = Optional.empty(); + if (smartContractPermissioningEnabled) { + smartContractPermConfig = Optional.of(smartContractPermissioningConfiguration()); + } + + final PermissioningConfiguration permissioningConfiguration = + new PermissioningConfiguration(localPermConfig, smartContractPermConfig); + + PantheonFactoryConfiguration config = + new PantheonFactoryConfigurationBuilder() + .setName(name) + .setJsonRpcConfiguration(jsonRpcConfigWithPermApiEnabled()) + .setPermissioningConfiguration(permissioningConfiguration) + .miningEnabled() + .build(); + + try { + return new PantheonNodeFactory().create(config); + } catch (IOException e) { + throw new RuntimeException("Error creating PantheonNode", e); + } + } + + private LocalPermissioningConfiguration localConfigPermissioningConfiguration() { + LocalPermissioningConfiguration localPermissioningConfiguration = + LocalPermissioningConfiguration.createDefault(); + + if (localConfigPermittedNodes != null) { + if (localConfigNodesPermissioningFile == null) { + localConfigNodesPermissioningFile = createTemporaryPermissionsFile(); + } + + List nodesAsListOfStrings = + localConfigPermittedNodes.stream().map(URI::toASCIIString).collect(Collectors.toList()); + initPermissioningConfigurationFile( + WHITELIST_TYPE.NODES, nodesAsListOfStrings, localConfigNodesPermissioningFile); + + localPermissioningConfiguration.setNodeWhitelist(localConfigPermittedNodes); + localPermissioningConfiguration.setNodePermissioningConfigFilePath( + localConfigNodesPermissioningFile.toAbsolutePath().toString()); + } + + if (localConfigPermittedAccounts != null) { + if (localConfigAccountsPermissioningFile == null) { + localConfigAccountsPermissioningFile = createTemporaryPermissionsFile(); + } + + initPermissioningConfigurationFile( + WHITELIST_TYPE.ACCOUNTS, + localConfigPermittedAccounts, + localConfigAccountsPermissioningFile); + + localPermissioningConfiguration.setAccountWhitelist(localConfigPermittedAccounts); + localPermissioningConfiguration.setAccountPermissioningConfigFilePath( + localConfigAccountsPermissioningFile.toAbsolutePath().toString()); + } + + return localPermissioningConfiguration; + } + + private SmartContractPermissioningConfiguration smartContractPermissioningConfiguration() { + SmartContractPermissioningConfiguration config = + SmartContractPermissioningConfiguration.createDefault(); + if (permissioningSmartContractAddress != null) { + config.setSmartContractAddress(Address.fromHexString(permissioningSmartContractAddress)); + config.setSmartContractNodeWhitelistEnabled(true); + } + return config; + } + + private Path createTemporaryPermissionsFile() { + final File tempFile; + try { + tempFile = File.createTempFile("temp", "temp"); + tempFile.deleteOnExit(); + } catch (IOException e) { + throw new RuntimeException("Error creating temporary permissioning file", e); + } + return tempFile.toPath(); + } + + private JsonRpcConfiguration jsonRpcConfigWithPermApiEnabled() { + final JsonRpcConfiguration jsonRpcConfig = JsonRpcConfiguration.createDefault(); + jsonRpcConfig.setEnabled(true); + jsonRpcConfig.setPort(0); + jsonRpcConfig.setHostsWhitelist(singletonList("*")); + final List rpcApis = new ArrayList<>(jsonRpcConfig.getRpcApis()); + rpcApis.add(RpcApis.PERM); + jsonRpcConfig.setRpcApis(rpcApis); + return jsonRpcConfig; + } + + private void initPermissioningConfigurationFile( + final WhitelistPersistor.WHITELIST_TYPE listType, + final Collection whitelistVal, + final Path configFilePath) { + try { + WhitelistPersistor.addNewConfigItem(listType, whitelistVal, configFilePath); + + Files.write( + configFilePath, + System.lineSeparator().getBytes(Charsets.UTF_8), + StandardOpenOption.WRITE, + StandardOpenOption.APPEND); + } catch (IOException e) { + throw new RuntimeException("Error populating permissioning file", e); + } + } + + private List convertToEnodes(final List nodes) { + return nodes.stream() + .map(node -> (RunnableNode) node) + .map(RunnableNode::enodeUrl) + .collect(toList()); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermAddNodesToWhitelistAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermAddNodesToWhitelistAcceptanceTest.java index 69d6774e4a..ffbfe49385 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermAddNodesToWhitelistAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermAddNodesToWhitelistAcceptanceTest.java @@ -15,7 +15,7 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; -import java.util.ArrayList; +import java.util.Collections; import org.junit.Before; import org.junit.Test; @@ -33,7 +33,11 @@ public class PermAddNodesToWhitelistAcceptanceTest extends AcceptanceTestBase { @Before public void setUp() throws Exception { - node = pantheon.createNodeWithNodesWhitelist("node1", new ArrayList<>()); + node = + permissionedNodeBuilder + .name("node1") + .nodesPermittedInConfig(Collections.emptyList()) + .build(); cluster.start(node); } 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 061263d729..d875b428cc 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,7 @@ public class PermGetNodesWhitelistAcceptanceTest extends AcceptanceTestBase { @Before public void setUp() throws Exception { - node = pantheon.createNodeWithNodesWhitelist("node1", nodesWhitelist); + node = permissionedNodeBuilder.name("node1").nodesPermittedInConfig(nodesWhitelist).build(); cluster.start(node); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermRemoveNodesFromWhitelistAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermRemoveNodesFromWhitelistAcceptanceTest.java index b2b3843fef..2303d13e51 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermRemoveNodesFromWhitelistAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/perm/PermRemoveNodesFromWhitelistAcceptanceTest.java @@ -37,7 +37,7 @@ public class PermRemoveNodesFromWhitelistAcceptanceTest extends AcceptanceTestBa @Before public void setUp() throws Exception { - node = pantheon.createNodeWithNodesWhitelist("node1", nodesWhitelist); + node = permissionedNodeBuilder.name("node1").nodesPermittedInConfig(nodesWhitelist).build(); cluster.start(node); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/AccountsWhitelistAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/AccountsWhitelistAcceptanceTest.java index 1dabcd365a..80bfd7c675 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/AccountsWhitelistAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/AccountsWhitelistAcceptanceTest.java @@ -36,7 +36,12 @@ public void setUp() throws Exception { senderA = accounts.getPrimaryBenefactor(); senderB = accounts.getSecondaryBenefactor(); - node = pantheon.createNodeWithAccountsWhitelist("node", Arrays.asList(senderA.getAddress())); + node = + permissionedNodeBuilder + .name("node") + .accountsPermittedInConfig(Arrays.asList(senderA.getAddress())) + .build(); + cluster.start(node); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/NodesWhitelistAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/NodesWhitelistAcceptanceTest.java index e3b173e8ce..6dc3d146da 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/NodesWhitelistAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/NodesWhitelistAcceptanceTest.java @@ -42,7 +42,8 @@ public void setUp() throws Exception { permissionedCluster.start(bootnode, allowedNode, forbiddenNode); permissionedNode = - pantheon.createNodeWithNodesWhitelist("permissioned-node", bootnode, allowedNode); + permissionedNodeBuilder.nodesPermittedInConfig(bootnode, allowedNode).build(); + permissionedCluster.addNode(permissionedNode); } diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/WhitelistPersistorAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/WhitelistPersistorAcceptanceTest.java index 59ff311871..d907d7c3fc 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/WhitelistPersistorAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/permissioning/WhitelistPersistorAcceptanceTest.java @@ -18,7 +18,6 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -46,17 +45,17 @@ public void setUp() throws Exception { senderA = accounts.getPrimaryBenefactor(); senderB = accounts.getSecondaryBenefactor(); tempFile = Files.createTempFile("test", "test"); - Files.write( - tempFile, - ("accounts-whitelist=[\"" + senderA.getAddress() + "\"]\nnodes-whitelist=[]") - .getBytes(StandardCharsets.UTF_8)); - node = - pantheon.createNodeWithWhitelistsEnabled( - "node", - new ArrayList<>(), - Collections.singletonList(senderA.getAddress()), - tempFile.toAbsolutePath().toString()); - cluster.start(node); + + this.node = + permissionedNodeBuilder + .name("node") + .nodesConfigFile(tempFile) + .nodesPermittedInConfig(new ArrayList<>()) + .accountsConfigFile(tempFile) + .accountsPermittedInConfig(Collections.singletonList(senderA.getAddress())) + .build(); + + cluster.start(this.node); } @Test diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/SmartContractPermissioningConfiguration.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/SmartContractPermissioningConfiguration.java index b21561a8ab..e05c819397 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/SmartContractPermissioningConfiguration.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/SmartContractPermissioningConfiguration.java @@ -18,10 +18,8 @@ public class SmartContractPermissioningConfiguration { private boolean smartContractNodeWhitelistEnabled; private Address smartContractAddress; - public SmartContractPermissioningConfiguration createDefault() { - final SmartContractPermissioningConfiguration smartContractPermissioningConfiguration = - new SmartContractPermissioningConfiguration(); - return smartContractPermissioningConfiguration; + public static SmartContractPermissioningConfiguration createDefault() { + return new SmartContractPermissioningConfiguration(); } public boolean isSmartContractNodeWhitelistEnabled() { diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index 7e9aa2a6be..87a84652ff 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -71,6 +71,7 @@ import java.net.URI; import java.nio.file.Path; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -97,7 +98,7 @@ public class RunnerBuilder { private MetricsConfiguration metricsConfiguration; private MetricsSystem metricsSystem; private Optional permissioningConfiguration = Optional.empty(); - private Collection staticNodes; + private Collection staticNodes = Collections.emptyList(); private EnodeURL getSelfEnode() { String nodeId = pantheonController.getLocalNodeKeyPair().getPublicKey().toString();