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

renamed AccountWhitelistController #1424

Merged
merged 6 commits into from
May 9, 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 @@ -36,7 +36,7 @@
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule;
import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec;
import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive;
import tech.pegasys.pantheon.metrics.MetricsSystem;
Expand Down Expand Up @@ -85,8 +85,8 @@ public Map<String, JsonRpcMethod> methods() {
blockchainQueries, transactionPool, new FilterIdGenerator(), new FilterRepository());
final EthHashMiningCoordinator miningCoordinator = mock(EthHashMiningCoordinator.class);
final MetricsSystem metricsSystem = new NoOpMetricsSystem();
final Optional<AccountWhitelistController> accountWhitelistController =
Optional.of(mock(AccountWhitelistController.class));
final Optional<AccountLocalConfigPermissioningController> accountWhitelistController =
Optional.of(mock(AccountLocalConfigPermissioningController.class));
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController =
Optional.of(mock(NodeLocalConfigPermissioningController.class));
final PrivacyParameters privacyParameters = mock(PrivacyParameters.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
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.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.privacy.PrivateTransactionHandler;
import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator;
Expand Down Expand Up @@ -136,7 +136,7 @@ public Map<String, JsonRpcMethod> methods(
final Set<Capability> supportedCapabilities,
final Collection<RpcApi> rpcApis,
final FilterManager filterManager,
final Optional<AccountWhitelistController> accountsWhitelistController,
final Optional<AccountLocalConfigPermissioningController> accountsWhitelistController,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
final PrivacyParameters privacyParameters,
final JsonRpcConfiguration jsonRpcConfiguration,
Expand Down Expand Up @@ -179,7 +179,7 @@ public Map<String, JsonRpcMethod> methods(
final MiningCoordinator miningCoordinator,
final MetricsSystem metricsSystem,
final Set<Capability> supportedCapabilities,
final Optional<AccountWhitelistController> accountsWhitelistController,
final Optional<AccountLocalConfigPermissioningController> accountsWhitelistController,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
final Collection<RpcApi> rpcApis,
final PrivacyParameters privacyParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistOperationResult;

import java.util.List;
Expand All @@ -29,10 +29,10 @@
public class PermAddAccountsToWhitelist implements JsonRpcMethod {

private final JsonRpcParameter parameters;
private final Optional<AccountWhitelistController> whitelistController;
private final Optional<AccountLocalConfigPermissioningController> whitelistController;

public PermAddAccountsToWhitelist(
final Optional<AccountWhitelistController> whitelistController,
final Optional<AccountLocalConfigPermissioningController> whitelistController,
final JsonRpcParameter parameters) {
this.whitelistController = whitelistController;
this.parameters = parameters;
Expand Down Expand Up @@ -72,7 +72,8 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
case SUCCESS:
return new JsonRpcSuccessResponse(request.getId());
default:
throw new IllegalStateException("Unmapped result from AccountWhitelistController");
throw new IllegalStateException(
"Unmapped result from AccountLocalConfigPermissioningController");
}
} else {
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.ACCOUNT_WHITELIST_NOT_ENABLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.AccountLocalConfigPermissioningController;

import java.util.Optional;

public class PermGetAccountsWhitelist implements JsonRpcMethod {

private final Optional<AccountWhitelistController> whitelistController;
private final Optional<AccountLocalConfigPermissioningController> whitelistController;

public PermGetAccountsWhitelist(final Optional<AccountWhitelistController> whitelistController) {
public PermGetAccountsWhitelist(
final Optional<AccountLocalConfigPermissioningController> whitelistController) {
this.whitelistController = whitelistController;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;

import java.util.Optional;

public class PermReloadPermissionsFromFile implements JsonRpcMethod {

private final Optional<AccountWhitelistController> accountWhitelistController;
private final Optional<AccountLocalConfigPermissioningController> accountWhitelistController;
private final Optional<NodeLocalConfigPermissioningController> nodesWhitelistController;

public PermReloadPermissionsFromFile(
final Optional<AccountWhitelistController> accountWhitelistController,
final Optional<AccountLocalConfigPermissioningController> accountWhitelistController,
final Optional<NodeLocalConfigPermissioningController> nodesWhitelistController) {
this.accountWhitelistController = accountWhitelistController;
this.nodesWhitelistController = nodesWhitelistController;
Expand All @@ -48,7 +48,7 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
}

try {
accountWhitelistController.ifPresent(AccountWhitelistController::reload);
accountWhitelistController.ifPresent(AccountLocalConfigPermissioningController::reload);
nodesWhitelistController.ifPresent(NodeLocalConfigPermissioningController::reload);
return new JsonRpcSuccessResponse(request.getId());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistOperationResult;

import java.util.List;
Expand All @@ -29,10 +29,10 @@
public class PermRemoveAccountsFromWhitelist implements JsonRpcMethod {

private final JsonRpcParameter parameters;
private final Optional<AccountWhitelistController> whitelistController;
private final Optional<AccountLocalConfigPermissioningController> whitelistController;

public PermRemoveAccountsFromWhitelist(
final Optional<AccountWhitelistController> whitelistController,
final Optional<AccountLocalConfigPermissioningController> whitelistController,
final JsonRpcParameter parameters) {
this.whitelistController = whitelistController;
this.parameters = parameters;
Expand Down Expand Up @@ -71,7 +71,8 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
case SUCCESS:
return new JsonRpcSuccessResponse(request.getId());
default:
throw new IllegalStateException("Unmapped result from AccountWhitelistController");
throw new IllegalStateException(
"Unmapped result from AccountLocalConfigPermissioningController");
}
} else {
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.ACCOUNT_WHITELIST_NOT_ENABLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
Expand Down Expand Up @@ -104,7 +104,7 @@ public void initServerAndClient() throws Exception {
mock(EthHashMiningCoordinator.class),
new NoOpMetricsSystem(),
supportedCapabilities,
Optional.of(mock(AccountWhitelistController.class)),
Optional.of(mock(AccountLocalConfigPermissioningController.class)),
Optional.of(mock(NodeLocalConfigPermissioningController.class)),
JSON_RPC_APIS,
mock(PrivacyParameters.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import tech.pegasys.pantheon.ethereum.p2p.network.DefaultP2PNetwork;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.p2p.wire.Capability;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
Expand Down Expand Up @@ -199,7 +199,7 @@ private JsonRpcHttpService createJsonRpcHttpServiceWithRpcApis(final JsonRpcConf
mock(EthHashMiningCoordinator.class),
new NoOpMetricsSystem(),
supportedCapabilities,
Optional.of(mock(AccountWhitelistController.class)),
Optional.of(mock(AccountLocalConfigPermissioningController.class)),
Optional.of(mock(NodeLocalConfigPermissioningController.class)),
config.getRpcApis(),
mock(PrivacyParameters.class),
Expand Down Expand Up @@ -285,7 +285,7 @@ private JsonRpcHttpService createJsonRpcHttpService(
mock(EthHashMiningCoordinator.class),
new NoOpMetricsSystem(),
supportedCapabilities,
Optional.of(mock(AccountWhitelistController.class)),
Optional.of(mock(AccountLocalConfigPermissioningController.class)),
Optional.of(mock(NodeLocalConfigPermissioningController.class)),
jsonRpcConfiguration.getRpcApis(),
mock(PrivacyParameters.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
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.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
Expand Down Expand Up @@ -131,7 +131,7 @@ public static void initServerAndClient() throws Exception {
mock(EthHashMiningCoordinator.class),
new NoOpMetricsSystem(),
supportedCapabilities,
Optional.of(mock(AccountWhitelistController.class)),
Optional.of(mock(AccountLocalConfigPermissioningController.class)),
Optional.of(mock(NodeLocalConfigPermissioningController.class)),
JSON_RPC_APIS,
mock(PrivacyParameters.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistOperationResult;

import java.util.ArrayList;
Expand All @@ -41,7 +41,7 @@
@RunWith(MockitoJUnitRunner.class)
public class PermAddAccountsToWhitelistTest {

@Mock private AccountWhitelistController accountWhitelist;
@Mock private AccountLocalConfigPermissioningController accountWhitelist;
private PermAddAccountsToWhitelist method;

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.AccountLocalConfigPermissioningController;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -36,7 +36,7 @@ public class PermGetAccountsWhitelistTest {
private static final JsonRpcRequest request =
new JsonRpcRequest("2.0", "perm_getAccountsWhitelist", null);

@Mock private AccountWhitelistController accountWhitelist;
@Mock private AccountLocalConfigPermissioningController accountWhitelist;
private PermGetAccountsWhitelist method;

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;

import java.util.Optional;
Expand All @@ -35,15 +35,15 @@
@RunWith(MockitoJUnitRunner.class)
public class PermReloadPermissionsFromFileTest {

@Mock private AccountWhitelistController accountWhitelistController;
@Mock private AccountLocalConfigPermissioningController accountLocalConfigPermissioningController;
@Mock private NodeLocalConfigPermissioningController nodeLocalConfigPermissioningController;
private PermReloadPermissionsFromFile method;

@Before
public void before() {
method =
new PermReloadPermissionsFromFile(
Optional.of(accountWhitelistController),
Optional.of(accountLocalConfigPermissioningController),
Optional.of(nodeLocalConfigPermissioningController));
}

Expand All @@ -68,15 +68,15 @@ public void whenBothControllersAreNotPresentMethodShouldReturnPermissioningDisab
public void whenControllersReloadSucceedsMethodShouldReturnSuccess() {
JsonRpcResponse response = method.response(reloadRequest());

verify(accountWhitelistController).reload();
verify(accountLocalConfigPermissioningController).reload();
verify(nodeLocalConfigPermissioningController).reload();

assertThat(response).isEqualToComparingFieldByField(successResponse());
}

@Test
public void whenControllerReloadFailsMethodShouldReturnError() {
doThrow(new RuntimeException()).when(accountWhitelistController).reload();
doThrow(new RuntimeException()).when(accountLocalConfigPermissioningController).reload();
JsonRpcResponse expectedErrorResponse =
new JsonRpcErrorResponse(null, JsonRpcError.WHITELIST_RELOAD_ERROR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.AccountLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistOperationResult;

import java.util.ArrayList;
Expand All @@ -41,7 +41,7 @@
@RunWith(MockitoJUnitRunner.class)
public class PermRemoveAccountsFromWhitelistTest {

@Mock private AccountWhitelistController accountWhitelist;
@Mock private AccountLocalConfigPermissioningController accountWhitelist;
private PermRemoveAccountsFromWhitelist method;

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AccountWhitelistController {
public class AccountLocalConfigPermissioningController {

private static final Logger LOG = LogManager.getLogger();

Expand All @@ -34,13 +34,14 @@ public class AccountWhitelistController {
private List<String> accountWhitelist = new ArrayList<>();
private final WhitelistPersistor whitelistPersistor;

public AccountWhitelistController(final LocalPermissioningConfiguration configuration) {
public AccountLocalConfigPermissioningController(
final LocalPermissioningConfiguration configuration) {
this(
configuration,
new WhitelistPersistor(configuration.getAccountPermissioningConfigFilePath()));
}

public AccountWhitelistController(
public AccountLocalConfigPermissioningController(
final LocalPermissioningConfiguration configuration,
final WhitelistPersistor whitelistPersistor) {
this.configuration = configuration;
Expand Down Expand Up @@ -154,7 +155,8 @@ public List<String> getAccountWhitelist() {
}

private boolean containsInvalidAccount(final List<String> accounts) {
return !accounts.stream().allMatch(AccountWhitelistController::isValidAccountString);
return !accounts.stream()
.allMatch(AccountLocalConfigPermissioningController::isValidAccountString);
}

static boolean isValidAccountString(final String account) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static LocalPermissioningConfiguration loadAccountPermissioning(
.collect(Collectors.toList());

accountsWhitelistToml.stream()
.filter(s -> !AccountWhitelistController.isValidAccountString(s))
.filter(s -> !AccountLocalConfigPermissioningController.isValidAccountString(s))
.findFirst()
.ifPresent(
s -> {
Expand Down
Loading