Enclave retrieve privacy group enclave method (#267)

Signed-off-by: Jason Frame <jasonwframe@gmail.com>
pull/269/head
Jason Frame 5 years ago committed by GitHub
parent a0e87148e9
commit 991dcf9237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      enclave/src/integration-test/java/org/hyperledger/besu/enclave/EnclaveTest.java
  2. 10
      enclave/src/main/java/org/hyperledger/besu/enclave/Enclave.java
  3. 32
      enclave/src/main/java/org/hyperledger/besu/enclave/types/RetrievePrivacyGroupRequest.java

@ -134,11 +134,11 @@ public class EnclaveTest {
@Test @Test
public void testCreateFindDeleteFindPrivacyGroup() { public void testCreateFindDeleteFindPrivacyGroup() {
List<String> publicKeys = testHarness.getPublicKeys(); final List<String> publicKeys = testHarness.getPublicKeys();
String name = "name"; final String name = "name";
String description = "desc"; final String description = "desc";
PrivacyGroup privacyGroupResponse = final PrivacyGroup privacyGroupResponse =
enclave.createPrivacyGroup(publicKeys, publicKeys.get(0), name, description); enclave.createPrivacyGroup(publicKeys, publicKeys.get(0), name, description);
assertThat(privacyGroupResponse.getPrivacyGroupId()).isNotNull(); assertThat(privacyGroupResponse.getPrivacyGroupId()).isNotNull();
@ -152,7 +152,7 @@ public class EnclaveTest {
assertThat(findPrivacyGroupResponse[0].getPrivacyGroupId()) assertThat(findPrivacyGroupResponse[0].getPrivacyGroupId())
.isEqualTo(privacyGroupResponse.getPrivacyGroupId()); .isEqualTo(privacyGroupResponse.getPrivacyGroupId());
String response = final String response =
enclave.deletePrivacyGroup(privacyGroupResponse.getPrivacyGroupId(), publicKeys.get(0)); enclave.deletePrivacyGroup(privacyGroupResponse.getPrivacyGroupId(), publicKeys.get(0));
assertThat(privacyGroupResponse.getPrivacyGroupId()).isEqualTo(response); assertThat(privacyGroupResponse.getPrivacyGroupId()).isEqualTo(response);
@ -162,6 +162,31 @@ public class EnclaveTest {
assertThat(findPrivacyGroupResponse.length).isEqualTo(0); assertThat(findPrivacyGroupResponse.length).isEqualTo(0);
} }
@Test
public void testCreateDeleteRetrievePrivacyGroup() {
final List<String> 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 @Test
public void upcheckReturnsFalseIfNoResposneReceived() throws URISyntaxException { public void upcheckReturnsFalseIfNoResposneReceived() throws URISyntaxException {
assertThat(factory.createVertxEnclave(new URI("http://8.8.8.8:65535")).upCheck()).isFalse(); assertThat(factory.createVertxEnclave(new URI("http://8.8.8.8:65535")).upCheck()).isFalse();

@ -22,6 +22,7 @@ import org.hyperledger.besu.enclave.types.FindPrivacyGroupRequest;
import org.hyperledger.besu.enclave.types.PrivacyGroup; import org.hyperledger.besu.enclave.types.PrivacyGroup;
import org.hyperledger.besu.enclave.types.ReceiveRequest; import org.hyperledger.besu.enclave.types.ReceiveRequest;
import org.hyperledger.besu.enclave.types.ReceiveResponse; 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.SendRequestBesu;
import org.hyperledger.besu.enclave.types.SendRequestLegacy; import org.hyperledger.besu.enclave.types.SendRequestLegacy;
import org.hyperledger.besu.enclave.types.SendResponse; import org.hyperledger.besu.enclave.types.SendResponse;
@ -126,6 +127,15 @@ public class Enclave {
(statusCode, body) -> handleJsonResponse(statusCode, body, PrivacyGroup[].class)); (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> T post( private <T> T post(
final String mediaType, final String mediaType,
final Object content, final Object content,

@ -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;
}
}
Loading…
Cancel
Save