[PAN-2996] Remove enclave public key from parameter (#1789)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Ivaylo Kirilov 5 years ago committed by Lucas Saldanha
parent 24bfd2e44a
commit a6cb8ad985
  1. 2
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java
  2. 19
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/privacy/PrivateTransactions.java
  3. 8
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/NodeRequests.java
  4. 10
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eea/EeaRequestFactory.java
  5. 48
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/priv/PrivCreatePrivacyGroupTransaction.java
  6. 43
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/priv/PrivCreatePrivacyGroupWithoutOptionalParamsTransaction.java
  7. 44
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/priv/PrivFindPrivacyGroupTransaction.java
  8. 2
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/priv/PrivGetTransactionCountTransaction.java
  9. 73
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/priv/PrivRequestFactory.java
  10. 134
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivacyGroupAcceptanceTest.java
  11. 71
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/PrivacyGroupIdAcceptanceTest.java
  12. 3
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/JsonRpcMethodsFactory.java
  13. 27
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/priv/PrivCreatePrivacyGroup.java
  14. 11
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/eea/PrivCreatePrivacyGroupTest.java

@ -40,6 +40,7 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.login.LoginRequest
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.miner.MinerRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.CustomRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm.PermissioningJsonRpcRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivRequestFactory;
import java.io.File;
import java.io.FileInputStream;
@ -293,6 +294,7 @@ public class PantheonNode implements NodeConfiguration, RunnableNode, AutoClosea
new PermissioningJsonRpcRequestFactory(web3jService),
new AdminRequestFactory(web3jService),
new EeaRequestFactory(web3jService),
new PrivRequestFactory(web3jService),
new CustomRequestFactory(web3jService),
new MinerRequestFactory(web3jService),
websocketService,

@ -13,8 +13,13 @@
package tech.pegasys.pantheon.tests.acceptance.dsl.privacy;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaSendRawTransactionTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivCreatePrivacyGroupTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivCreatePrivacyGroupWithoutOptionalParamsTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivFindPrivacyGroupTransaction;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivGetTransactionCountTransaction;
import java.util.List;
public class PrivateTransactions {
public PrivateTransactions() {}
@ -33,4 +38,18 @@ public class PrivateTransactions {
final String address, final String privacyGroupId) {
return new PrivGetTransactionCountTransaction(address, privacyGroupId);
}
public PrivCreatePrivacyGroupTransaction createPrivacyGroup(
final List<String> addresses, final String name, final String description) {
return new PrivCreatePrivacyGroupTransaction(addresses, name, description);
}
public PrivCreatePrivacyGroupWithoutOptionalParamsTransaction
createPrivacyGroupWithoutOptionalParams(final List<String> addresses) {
return new PrivCreatePrivacyGroupWithoutOptionalParamsTransaction(addresses);
}
public PrivFindPrivacyGroupTransaction findPrivacyGroup(final List<String> addresses) {
return new PrivFindPrivacyGroupTransaction(addresses);
}
}

@ -20,6 +20,7 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.login.LoginRequest
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.miner.MinerRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.CustomRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm.PermissioningJsonRpcRequestFactory;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.priv.PrivRequestFactory;
import java.util.Optional;
@ -34,6 +35,7 @@ public class NodeRequests {
private final PermissioningJsonRpcRequestFactory perm;
private final AdminRequestFactory admin;
private final EeaRequestFactory eea;
private final PrivRequestFactory priv;
private final CustomRequestFactory custom;
private final Optional<WebSocketService> websocketService;
private final LoginRequestFactory login;
@ -46,6 +48,7 @@ public class NodeRequests {
final PermissioningJsonRpcRequestFactory perm,
final AdminRequestFactory admin,
final EeaRequestFactory eea,
final PrivRequestFactory priv,
final CustomRequestFactory custom,
final MinerRequestFactory miner,
final Optional<WebSocketService> websocketService,
@ -56,6 +59,7 @@ public class NodeRequests {
this.perm = perm;
this.admin = admin;
this.eea = eea;
this.priv = priv;
this.custom = custom;
this.miner = miner;
this.websocketService = websocketService;
@ -94,6 +98,10 @@ public class NodeRequests {
return eea;
}
public PrivRequestFactory priv() {
return priv;
}
public LoginRequestFactory login() {
return login;
}

@ -19,7 +19,6 @@ import org.assertj.core.util.Lists;
import org.web3j.protocol.Web3jService;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.Response;
import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
import org.web3j.protocol.core.methods.response.Log;
public class EeaRequestFactory {
@ -99,13 +98,4 @@ public class EeaRequestFactory {
web3jService,
PrivateTransactionReceiptResponse.class);
}
public Request<?, EthGetTransactionCount> privGetTransactionCount(
final String accountAddress, final String privacyGroupId) {
return new Request<>(
"priv_getTransactionCount",
Lists.newArrayList(accountAddress, privacyGroupId),
web3jService,
EthGetTransactionCount.class);
}
}

@ -0,0 +1,48 @@
/*
* 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.transaction.priv;
import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
import java.io.IOException;
import java.util.List;
public class PrivCreatePrivacyGroupTransaction implements Transaction<String> {
private final List<String> addresses;
private final String name;
private final String description;
public PrivCreatePrivacyGroupTransaction(
final List<String> addresses, final String name, final String description) {
this.addresses = addresses;
this.name = name;
this.description = description;
}
@Override
public String execute(final NodeRequests node) {
try {
PrivRequestFactory.PrivCreatePrivacyGroupResponse result =
node.priv().privCreatePrivacyGroup(addresses, name, description).send();
assertThat(result).isNotNull();
return result.getResult();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}

@ -0,0 +1,43 @@
/*
* 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.transaction.priv;
import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
import java.io.IOException;
import java.util.List;
public class PrivCreatePrivacyGroupWithoutOptionalParamsTransaction implements Transaction<String> {
private final List<String> addresses;
public PrivCreatePrivacyGroupWithoutOptionalParamsTransaction(final List<String> addresses) {
this.addresses = addresses;
}
@Override
public String execute(final NodeRequests node) {
try {
PrivRequestFactory.PrivCreatePrivacyGroupResponse result =
node.priv().privCreatePrivacyGroupWithoutOptionalParams(addresses).send();
assertThat(result).isNotNull();
return result.getResult();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}

@ -0,0 +1,44 @@
/*
* 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.transaction.priv;
import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.enclave.types.PrivacyGroup;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
import java.io.IOException;
import java.util.List;
public class PrivFindPrivacyGroupTransaction implements Transaction<List<PrivacyGroup>> {
private final List<String> addresses;
public PrivFindPrivacyGroupTransaction(final List<String> addresses) {
this.addresses = addresses;
}
@Override
public List<PrivacyGroup> execute(final NodeRequests node) {
try {
PrivRequestFactory.PrivFindPrivacyGroupResponse result =
node.priv().privFindPrivacyGroup(addresses).send();
assertThat(result).isNotNull();
return result.getResult();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}

@ -37,7 +37,7 @@ public class PrivGetTransactionCountTransaction implements Transaction<BigIntege
public BigInteger execute(final NodeRequests node) {
try {
EthGetTransactionCount result =
node.eea().privGetTransactionCount(accountAddress, privacyGroupId).send();
node.priv().privGetTransactionCount(accountAddress, privacyGroupId).send();
assertThat(result).isNotNull();
return result.getTransactionCount();
} catch (final IOException e) {

@ -0,0 +1,73 @@
/*
* 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.transaction.priv;
import tech.pegasys.pantheon.enclave.types.PrivacyGroup;
import java.util.Collections;
import java.util.List;
import org.assertj.core.util.Lists;
import org.web3j.protocol.Web3jService;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.Response;
import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
public class PrivRequestFactory {
public static class PrivCreatePrivacyGroupResponse extends Response<String> {}
public static class PrivFindPrivacyGroupResponse extends Response<List<PrivacyGroup>> {}
private final Web3jService web3jService;
public PrivRequestFactory(final Web3jService web3jService) {
this.web3jService = web3jService;
}
public Request<?, EthGetTransactionCount> privGetTransactionCount(
final String accountAddress, final String privacyGroupId) {
return new Request<>(
"priv_getTransactionCount",
Lists.newArrayList(accountAddress, privacyGroupId),
web3jService,
EthGetTransactionCount.class);
}
public Request<?, PrivCreatePrivacyGroupResponse> privCreatePrivacyGroup(
final List<String> addresses, final String name, final String description) {
return new Request<>(
"priv_createPrivacyGroup",
Lists.newArrayList(addresses, name, description),
web3jService,
PrivCreatePrivacyGroupResponse.class);
}
public Request<?, PrivCreatePrivacyGroupResponse> privCreatePrivacyGroupWithoutOptionalParams(
final List<String> addresses) {
return new Request<>(
"priv_createPrivacyGroup",
Collections.singletonList(addresses),
web3jService,
PrivCreatePrivacyGroupResponse.class);
}
public Request<?, PrivFindPrivacyGroupResponse> privFindPrivacyGroup(
final List<String> addresses) {
return new Request<>(
"priv_findPrivacyGroup",
Collections.singletonList(addresses),
web3jService,
PrivFindPrivacyGroupResponse.class);
}
}

@ -0,0 +1,134 @@
/*
* 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.web3j.privacy;
import static org.assertj.core.api.Assertions.assertThat;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.CreatePrivacyGroupRequest;
import tech.pegasys.pantheon.enclave.types.PrivacyGroup;
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNet;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
public class PrivacyGroupAcceptanceTest extends PrivacyAcceptanceTestBase {
private static final String CONTRACT_NAME = "Event Emmiter";
private EventEmitterHarness eventEmitterHarness;
private PrivacyGroup privacyGroup;
private PrivacyNet privacyNet;
@Before
public void setUp() throws Exception {
privacyNet =
PrivacyNet.builder(privacy, privacyPantheon, cluster, false)
.addMinerNode("Alice")
.addMinerNode("Bob")
.addMinerNode("Charlie")
.build();
privacyNet.startPrivacyNet();
final Enclave enclave =
new Enclave(privacyNet.getNode("Alice").getPrivacyParameters().getEnclaveUri());
final String[] addresses =
privacyNet.getNodes().values().stream()
.map(privacyNode -> privacyNode.orion.getPublicKeys())
.flatMap(List::stream)
.toArray(String[]::new);
this.privacyGroup =
enclave.createPrivacyGroup(
new CreatePrivacyGroupRequest(
addresses,
privacyNet.getNode("Alice").orion.getPublicKeys().get(0),
"testName",
"testDesc"));
eventEmitterHarness =
new EventEmitterHarness(
privateTransactionBuilder,
privacyNet,
privateTransactions,
privateTransactionVerifier,
eea);
}
@Test
public void nodeCanDeployWithPrivacyGroupId() {
eventEmitterHarness.deployWithPrivacyGroup(
CONTRACT_NAME, "Alice", privacyGroup.getPrivacyGroupId(), "Alice", "Bob", "Charlie");
}
@Test
public void nodeCanCreatePrivacyGroup() {
final String privacyGroupId =
privacyNet
.getNode("Alice")
.execute(
privateTransactions.createPrivacyGroup(
List.of(
privacyNet.getEnclave("Alice").getPublicKeys().get(0),
privacyNet.getEnclave("Bob").getPublicKeys().get(0)),
"myGroupName",
"my group description"));
assertThat(privacyGroupId).isNotNull();
final List<PrivacyGroup> privacyGroups =
privacyNet
.getNode("Alice")
.execute(
privateTransactions.findPrivacyGroup(
List.of(
privacyNet.getEnclave("Alice").getPublicKeys().get(0),
privacyNet.getEnclave("Bob").getPublicKeys().get(0))));
assertThat(privacyGroups.size()).isEqualTo(1);
assertThat(privacyGroups.get(0).getPrivacyGroupId()).isEqualTo(privacyGroupId);
assertThat(privacyGroups.get(0).getName()).isEqualTo("myGroupName");
assertThat(privacyGroups.get(0).getDescription()).isEqualTo("my group description");
assertThat(privacyGroups.get(0).getMembers().length).isEqualTo(2);
}
@Test
public void nodeCanCreatePrivacyGroupWithoutOptionalParams() {
final String privacyGroupId =
privacyNet
.getNode("Alice")
.execute(
privateTransactions.createPrivacyGroupWithoutOptionalParams(
List.of(
privacyNet.getEnclave("Alice").getPublicKeys().get(0),
privacyNet.getEnclave("Bob").getPublicKeys().get(0))));
assertThat(privacyGroupId).isNotNull();
final List<PrivacyGroup> privacyGroups =
privacyNet
.getNode("Alice")
.execute(
privateTransactions.findPrivacyGroup(
List.of(
privacyNet.getEnclave("Alice").getPublicKeys().get(0),
privacyNet.getEnclave("Bob").getPublicKeys().get(0))));
assertThat(privacyGroups.size()).isEqualTo(1);
assertThat(privacyGroups.get(0).getPrivacyGroupId()).isEqualTo(privacyGroupId);
assertThat(privacyGroups.get(0).getName()).isEqualTo(null);
assertThat(privacyGroups.get(0).getDescription()).isEqualTo(null);
assertThat(privacyGroups.get(0).getMembers().length).isEqualTo(2);
}
}

@ -1,71 +0,0 @@
/*
* 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.web3j.privacy;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.CreatePrivacyGroupRequest;
import tech.pegasys.pantheon.enclave.types.PrivacyGroup;
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyAcceptanceTestBase;
import tech.pegasys.pantheon.tests.acceptance.dsl.privacy.PrivacyNet;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
public class PrivacyGroupIdAcceptanceTest extends PrivacyAcceptanceTestBase {
private static final String CONTRACT_NAME = "Event Emmiter";
private EventEmitterHarness eventEmitterHarness;
private PrivacyGroup privacyGroup;
@Before
public void setUp() throws Exception {
PrivacyNet privacyNet =
PrivacyNet.builder(privacy, privacyPantheon, cluster, false)
.addMinerNode("Alice")
.addMinerNode("Bob")
.addMinerNode("Charlie")
.build();
privacyNet.startPrivacyNet();
Enclave enclave =
new Enclave(privacyNet.getNode("Alice").getPrivacyParameters().getEnclaveUri());
String[] addresses =
privacyNet.getNodes().values().stream()
.map(privacyNode -> privacyNode.orion.getPublicKeys())
.flatMap(List::stream)
.toArray(String[]::new);
this.privacyGroup =
enclave.createPrivacyGroup(
new CreatePrivacyGroupRequest(
addresses,
privacyNet.getNode("Alice").orion.getPublicKeys().get(0),
"testName",
"testDesc"));
eventEmitterHarness =
new EventEmitterHarness(
privateTransactionBuilder,
privacyNet,
privateTransactions,
privateTransactionVerifier,
eea);
}
@Test
public void nodeCanDeployWithPrivacyGroupId() {
eventEmitterHarness.deployWithPrivacyGroup(
CONTRACT_NAME, "Alice", privacyGroup.getPrivacyGroupId(), "Alice", "Bob", "Charlie");
}
}

@ -337,7 +337,8 @@ public class JsonRpcMethodsFactory {
if (priv) {
addMethods(
enabledMethods,
new PrivCreatePrivacyGroup(new Enclave(privacyParameters.getEnclaveUri()), parameter),
new PrivCreatePrivacyGroup(
new Enclave(privacyParameters.getEnclaveUri()), privacyParameters, parameter),
new PrivDeletePrivacyGroup(
new Enclave(privacyParameters.getEnclaveUri()), privacyParameters, parameter),
new PrivFindPrivacyGroup(new Enclave(privacyParameters.getEnclaveUri()), parameter),

@ -17,6 +17,7 @@ import static org.apache.logging.log4j.LogManager.getLogger;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.CreatePrivacyGroupRequest;
import tech.pegasys.pantheon.enclave.types.PrivacyGroup;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
@ -25,16 +26,23 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import java.util.Optional;
import org.apache.logging.log4j.Logger;
public class PrivCreatePrivacyGroup implements JsonRpcMethod {
private static final Logger LOG = getLogger();
private final Enclave enclave;
private PrivacyParameters privacyParameters;
private final JsonRpcParameter parameters;
public PrivCreatePrivacyGroup(final Enclave enclave, final JsonRpcParameter parameters) {
public PrivCreatePrivacyGroup(
final Enclave enclave,
final PrivacyParameters privacyParameters,
final JsonRpcParameter parameters) {
this.enclave = enclave;
this.privacyParameters = privacyParameters;
this.parameters = parameters;
}
@ -47,16 +55,19 @@ public class PrivCreatePrivacyGroup implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequest request) {
LOG.trace("Executing {}", RpcMethod.PRIV_CREATE_PRIVACY_GROUP.getMethodName());
final String from = parameters.required(request.getParams(), 0, String.class);
final String name = parameters.required(request.getParams(), 1, String.class);
final String description = parameters.required(request.getParams(), 2, String.class);
final String[] addresses = parameters.required(request.getParams(), 3, String[].class);
final String[] addresses = parameters.required(request.getParams(), 0, String[].class);
final Optional<String> name = parameters.optional(request.getParams(), 1, String.class);
final Optional<String> description = parameters.optional(request.getParams(), 2, String.class);
LOG.trace("Creating a privacy group with name {} and description {}", name, description);
CreatePrivacyGroupRequest createPrivacyGroupRequest =
new CreatePrivacyGroupRequest(addresses, from, name, description);
PrivacyGroup response;
final CreatePrivacyGroupRequest createPrivacyGroupRequest =
new CreatePrivacyGroupRequest(
addresses,
privacyParameters.getEnclavePublicKey(),
name.orElse(null),
description.orElse(null));
final PrivacyGroup response;
try {
response = enclave.createPrivacyGroup(createPrivacyGroupRequest);
} catch (Exception e) {

@ -19,6 +19,7 @@ import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.enclave.Enclave;
import tech.pegasys.pantheon.enclave.types.PrivacyGroup;
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.privacy.priv.PrivCreatePrivacyGroup;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter;
@ -26,9 +27,10 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessRe
import org.junit.Test;
public class EeaCreatePrivacyGroupTest {
public class PrivCreatePrivacyGroupTest {
private final Enclave enclave = mock(Enclave.class);
private final PrivacyParameters privacyParameters = mock(PrivacyParameters.class);
private final JsonRpcParameter parameters = new JsonRpcParameter();
private final String from = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=";
@ -44,14 +46,15 @@ public class EeaCreatePrivacyGroupTest {
@Test
public void verifyCreatePrivacyGroup() throws Exception {
PrivacyGroup privacyGroup =
final PrivacyGroup privacyGroup =
new PrivacyGroup(privacyGroupId, PrivacyGroup.Type.PANTHEON, name, description, addresses);
when(enclave.createPrivacyGroup(any())).thenReturn(privacyGroup);
when(privacyParameters.getEnclavePublicKey()).thenReturn(from);
final PrivCreatePrivacyGroup eeaCreatePrivacyGroup =
new PrivCreatePrivacyGroup(enclave, parameters);
new PrivCreatePrivacyGroup(enclave, privacyParameters, parameters);
Object[] params = new Object[] {from, name, description, addresses};
final Object[] params = new Object[] {addresses, name, description};
final JsonRpcRequest request = new JsonRpcRequest("1", "priv_createPrivacyGroup", params);
final JsonRpcSuccessResponse response =
Loading…
Cancel
Save