From 1f88e1ad544dcd047dc85b3e3ab7904ff1b8e838 Mon Sep 17 00:00:00 2001 From: Puneetha Date: Mon, 8 Jul 2019 12:07:39 +0100 Subject: [PATCH 1/3] Rename privacyGroupId to createPrivacyGroupId Also add test for eea_createPrivacyGroup --- .../privacy/EeaCreatePrivacyGroupTest.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaCreatePrivacyGroupTest.java diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaCreatePrivacyGroupTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaCreatePrivacyGroupTest.java new file mode 100644 index 0000000000..1cd83715d7 --- /dev/null +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaCreatePrivacyGroupTest.java @@ -0,0 +1,63 @@ +/* + * 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.ethereum.jsonrpc.internal.methods.privacy; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import tech.pegasys.pantheon.enclave.Enclave; +import tech.pegasys.pantheon.enclave.types.PrivacyGroup; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; + +import org.junit.Test; + +public class EeaCreatePrivacyGroupTest { + + private final Enclave enclave = mock(Enclave.class); + private final JsonRpcParameter parameters = new JsonRpcParameter(); + + private final String from = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; + private final String name = "testName"; + private final String description = "testDesc"; + private final String[] addresses = + new String[] { + "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=", + "Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs=" + }; + private final String privacyGroupId = + "68/Cq0mVjB8FbXDLE1tbDRAvD/srluIok137uFOaClPU/dLFW34ovZebW+PTzy9wUawTXw=="; + + @Test + public void verifyCreatePrivacyGroup() throws Exception { + PrivacyGroup privacyGroup = + new PrivacyGroup(privacyGroupId, PrivacyGroup.Type.PANTHEON, name, description); + when(enclave.createPrivacyGroup(any())).thenReturn(privacyGroup); + + final EeaCreatePrivacyGroup eeaCreatePrivacyGroup = + new EeaCreatePrivacyGroup(enclave, parameters); + + Object[] params = new Object[] {from, name, description, addresses}; + final JsonRpcRequest request = new JsonRpcRequest("1", "eea_createPrivacyGroup", params); + + final JsonRpcSuccessResponse response = + (JsonRpcSuccessResponse) eeaCreatePrivacyGroup.response(request); + + final String result = (String) response.getResult(); + + assertEquals(privacyGroupId, result); + } +} From 06e5ca27100890c24d24a47f2a00dd213ca544e5 Mon Sep 17 00:00:00 2001 From: Puneetha Date: Mon, 8 Jul 2019 12:21:56 +0100 Subject: [PATCH 2/3] Update the JsonRpcError list --- .../ethereum/jsonrpc/internal/response/JsonRpcError.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/response/JsonRpcError.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/response/JsonRpcError.java index 2c1fd806bc..fc7adfe0c7 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/response/JsonRpcError.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/response/JsonRpcError.java @@ -130,7 +130,8 @@ public enum JsonRpcError { ENCLAVE_NOT_PAYLOAD_OWNER(-50200, "EnclaveNotPayloadOwner"), ENCLAVE_UNSUPPORTED_PRIVATE_KEY_TYPE(-50200, "EnclaveUnsupportedPrivateKeyType"), ENCLAVE_STORAGE_DECRYPT(-50200, "EnclaveStorageDecrypt"), - ENCLAVE_PRIVACY_GROUP_CREATION(-50200, "EnclavePrivacyGroupIdCreation"); + ENCLAVE_PRIVACY_GROUP_CREATION(-50200, "EnclavePrivacyGroupIdCreation"), + CREATE_GROUP_INCLUDE_SELF(-50200, "CreatePrivacyGroupShouldIncludeSelf"); private final int code; private final String message; From ea1398ea3729144e99174b45b04579f6115e02b9 Mon Sep 17 00:00:00 2001 From: Puneetha Date: Tue, 9 Jul 2019 09:42:37 +0100 Subject: [PATCH 3/3] Update orion version --- .../src/main/java/tech/pegasys/pantheon/enclave/Enclave.java | 4 ++-- gradle/versions.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java b/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java index 4279705b6c..3b9592a11f 100644 --- a/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java +++ b/enclave/src/main/java/tech/pegasys/pantheon/enclave/Enclave.java @@ -68,11 +68,11 @@ public ReceiveResponse receive(final ReceiveRequest content) throws Exception { } public PrivacyGroup createPrivacyGroup(final CreatePrivacyGroupRequest content) throws Exception { - return executePost(buildPostRequest(JSON, content, "/privacyGroupId"), PrivacyGroup.class); + return executePost(buildPostRequest(JSON, content, "/createPrivacyGroup"), PrivacyGroup.class); } public String deletePrivacyGroup(final DeletePrivacyGroupRequest content) throws Exception { - return executePost(buildPostRequest(JSON, content, "/deletePrivacyGroupId"), String.class); + return executePost(buildPostRequest(JSON, content, "/deletePrivacyGroup"), String.class); } private Request buildPostRequest( diff --git a/gradle/versions.gradle b/gradle/versions.gradle index 5ddcbfebe2..1787dad6d5 100644 --- a/gradle/versions.gradle +++ b/gradle/versions.gradle @@ -53,7 +53,7 @@ dependencyManagement { dependency 'net.consensys.cava:cava-toml:0.5.0' - dependency 'net.consensys:orion:1.1.0' + dependency 'net.consensys:orion:1.2.0' dependency 'org.apache.commons:commons-text:1.6'