Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Refactoring permissioning ATs #1148

Merged
merged 3 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -75,6 +77,7 @@ protected AcceptanceTestBase() {
pantheon = new PantheonNodeFactory();
contractVerifier = new ContractVerifier(accounts.getPrimaryBenefactor());
wait = new WaitConditions(ethTransactions, cliqueTransactions, ibftTransactions);
permissionedNodeBuilder = new PermissionedNodeBuilder();
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand Down Expand Up @@ -149,7 +143,7 @@ public PantheonNode createNodeWithP2pDisabled(final String name) throws IOExcept
new PantheonFactoryConfigurationBuilder()
.setName(name)
.setP2pEnabled(false)
.setJsonRpcConfiguration(jsonRpcConfigWithPermissioning())
.setJsonRpcConfiguration(createJsonRpcEnabledConfig())
.build());
}

Expand All @@ -158,7 +152,7 @@ public PantheonNode createNodeWithP2pDisabledAndAdmin(final String name) throws
new PantheonFactoryConfigurationBuilder()
.setName(name)
.setP2pEnabled(false)
.setJsonRpcConfiguration(jsonRpcConfigWithPermissioningAndAdmin())
.setJsonRpcConfiguration(jsonRpcConfigWithAdmin())
.build());
}

Expand All @@ -181,110 +175,6 @@ public PantheonNode createArchiveNodeWithRpcApis(
.build());
}

public PantheonNode createNodeWithWhitelistsEnabled(
final String name,
final List<URI> nodesWhitelist,
final List<String> 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<URI> nodesWhitelist) throws IOException {
final LocalPermissioningConfiguration localPermissioningConfiguration =
LocalPermissioningConfiguration.createDefault();
localPermissioningConfiguration.setNodeWhitelist(nodesWhitelist);

final List<String> 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<URI> convertToEnodes(final List<Node> nodes) {
return nodes.stream()
.map(node -> (RunnableNode) node)
.map(RunnableNode::enodeUrl)
.collect(toList());
}

private void initPermissioningConfigurationFile(
final WhitelistPersistor.WHITELIST_TYPE listType,
final Collection<String> whitelistVal,
final Path configFilePath)
throws IOException {
WhitelistPersistor.addNewConfigItem(listType, whitelistVal, configFilePath);
}

public PantheonNode createNodeWithAccountsWhitelist(
final String name, final List<String> 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());
Expand Down Expand Up @@ -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<RpcApi> rpcApis = new ArrayList<>(jsonRpcConfig.getRpcApis());
Expand Down
Loading