diff --git a/enclave/src/integration-test/java/org/hyperledger/besu/enclave/EnclaveTest.java b/enclave/src/integration-test/java/org/hyperledger/besu/enclave/EnclaveTest.java index b173449f95..373cf089c6 100644 --- a/enclave/src/integration-test/java/org/hyperledger/besu/enclave/EnclaveTest.java +++ b/enclave/src/integration-test/java/org/hyperledger/besu/enclave/EnclaveTest.java @@ -134,11 +134,11 @@ public class EnclaveTest { @Test public void testCreateFindDeleteFindPrivacyGroup() { - List publicKeys = testHarness.getPublicKeys(); - String name = "name"; - String description = "desc"; + final List publicKeys = testHarness.getPublicKeys(); + final String name = "name"; + final String description = "desc"; - PrivacyGroup privacyGroupResponse = + final PrivacyGroup privacyGroupResponse = enclave.createPrivacyGroup(publicKeys, publicKeys.get(0), name, description); assertThat(privacyGroupResponse.getPrivacyGroupId()).isNotNull(); @@ -152,7 +152,7 @@ public class EnclaveTest { assertThat(findPrivacyGroupResponse[0].getPrivacyGroupId()) .isEqualTo(privacyGroupResponse.getPrivacyGroupId()); - String response = + final String response = enclave.deletePrivacyGroup(privacyGroupResponse.getPrivacyGroupId(), publicKeys.get(0)); assertThat(privacyGroupResponse.getPrivacyGroupId()).isEqualTo(response); @@ -162,6 +162,31 @@ public class EnclaveTest { assertThat(findPrivacyGroupResponse.length).isEqualTo(0); } + @Test + public void testCreateDeleteRetrievePrivacyGroup() { + final List publicKeys = testHarness.getPublicKeys(); + final String name = "name"; + final String description = "desc"; + + final PrivacyGroup privacyGroupResponse = + enclave.createPrivacyGroup(publicKeys, publicKeys.get(0), name, description); + + assertThat(privacyGroupResponse.getPrivacyGroupId()).isNotNull(); + assertThat(privacyGroupResponse.getName()).isEqualTo(name); + assertThat(privacyGroupResponse.getDescription()).isEqualTo(description); + assertThat(privacyGroupResponse.getType()).isEqualTo(PrivacyGroup.Type.PANTHEON); + + final PrivacyGroup retrievePrivacyGroup = + enclave.retrievePrivacyGroup(privacyGroupResponse.getPrivacyGroupId()); + + assertThat(retrievePrivacyGroup).isEqualToComparingFieldByField(privacyGroupResponse); + + final String response = + enclave.deletePrivacyGroup(privacyGroupResponse.getPrivacyGroupId(), publicKeys.get(0)); + + assertThat(privacyGroupResponse.getPrivacyGroupId()).isEqualTo(response); + } + @Test public void upcheckReturnsFalseIfNoResposneReceived() throws URISyntaxException { assertThat(factory.createVertxEnclave(new URI("http://8.8.8.8:65535")).upCheck()).isFalse(); diff --git a/enclave/src/main/java/org/hyperledger/besu/enclave/Enclave.java b/enclave/src/main/java/org/hyperledger/besu/enclave/Enclave.java index 121dd58c17..fcf930d646 100644 --- a/enclave/src/main/java/org/hyperledger/besu/enclave/Enclave.java +++ b/enclave/src/main/java/org/hyperledger/besu/enclave/Enclave.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.enclave.types.FindPrivacyGroupRequest; import org.hyperledger.besu.enclave.types.PrivacyGroup; import org.hyperledger.besu.enclave.types.ReceiveRequest; import org.hyperledger.besu.enclave.types.ReceiveResponse; +import org.hyperledger.besu.enclave.types.RetrievePrivacyGroupRequest; import org.hyperledger.besu.enclave.types.SendRequestBesu; import org.hyperledger.besu.enclave.types.SendRequestLegacy; import org.hyperledger.besu.enclave.types.SendResponse; @@ -126,6 +127,15 @@ public class Enclave { (statusCode, body) -> handleJsonResponse(statusCode, body, PrivacyGroup[].class)); } + public PrivacyGroup retrievePrivacyGroup(final String privacyGroupId) { + final RetrievePrivacyGroupRequest request = new RetrievePrivacyGroupRequest(privacyGroupId); + return post( + JSON, + request, + "/retrievePrivacyGroup", + (statusCode, body) -> handleJsonResponse(statusCode, body, PrivacyGroup.class)); + } + private T post( final String mediaType, final Object content, diff --git a/enclave/src/main/java/org/hyperledger/besu/enclave/types/RetrievePrivacyGroupRequest.java b/enclave/src/main/java/org/hyperledger/besu/enclave/types/RetrievePrivacyGroupRequest.java new file mode 100644 index 0000000000..1f49577093 --- /dev/null +++ b/enclave/src/main/java/org/hyperledger/besu/enclave/types/RetrievePrivacyGroupRequest.java @@ -0,0 +1,32 @@ +/* + * Copyright 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. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.enclave.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class RetrievePrivacyGroupRequest { + private final String privacyGroupId; + + @JsonCreator + public RetrievePrivacyGroupRequest(@JsonProperty("privacyGroupId") final String privacyGroupId) { + this.privacyGroupId = privacyGroupId; + } + + @JsonProperty("privacyGroupId") + public String privacyGroupId() { + return privacyGroupId; + } +}