use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter in project besu by hyperledger.
the class PrivCreatePrivacyGroup method response.
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
LOG.trace("Executing {}", RpcMethod.PRIV_CREATE_PRIVACY_GROUP.getMethodName());
final CreatePrivacyGroupParameter parameter = requestContext.getRequiredParameter(0, CreatePrivacyGroupParameter.class);
LOG.trace("Creating a privacy group with name {} and description {}", parameter.getName(), parameter.getDescription());
final PrivacyGroup response;
try {
response = privacyController.createPrivacyGroup(parameter.getAddresses(), parameter.getName(), parameter.getDescription(), privacyIdProvider.getPrivacyUserId(requestContext.getUser()));
} catch (Exception e) {
LOG.error("Failed to create privacy group", e);
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcEnclaveErrorConverter.convertEnclaveInvalidReason(e.getMessage()));
}
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), response.getPrivacyGroupId());
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter in project besu by hyperledger.
the class PrivCreatePrivacyGroupTest method verifyCreatePrivacyGroup.
@Test
public void verifyCreatePrivacyGroup() {
final String expected = "a wonderful group";
final PrivacyGroup privacyGroup = new PrivacyGroup(expected, PrivacyGroup.Type.PANTHEON, NAME, DESCRIPTION, ADDRESSES);
when(privacyController.createPrivacyGroup(ADDRESSES, NAME, DESCRIPTION, ENCLAVE_PUBLIC_KEY)).thenReturn(privacyGroup);
when(privacyParameters.getPrivacyUserId()).thenReturn(FROM);
final PrivCreatePrivacyGroup privCreatePrivacyGroup = new PrivCreatePrivacyGroup(privacyController, privacyIdProvider);
final CreatePrivacyGroupParameter param = new CreatePrivacyGroupParameter(ADDRESSES, NAME, DESCRIPTION);
final Object[] params = new Object[] { param };
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("1", "priv_createPrivacyGroup", params), user);
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privCreatePrivacyGroup.response(request);
final String result = (String) response.getResult();
assertThat(result).isEqualTo(expected);
verify(privacyController).createPrivacyGroup(ADDRESSES, NAME, DESCRIPTION, ENCLAVE_PUBLIC_KEY);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter in project besu by hyperledger.
the class PrivCreatePrivacyGroupTest method returnsCorrectErrorEnclaveError.
@Test
public void returnsCorrectErrorEnclaveError() {
when(privacyController.createPrivacyGroup(ADDRESSES, NAME, DESCRIPTION, ENCLAVE_PUBLIC_KEY)).thenThrow(new EnclaveClientException(400, "Enclave error"));
final PrivCreatePrivacyGroup privCreatePrivacyGroup = new PrivCreatePrivacyGroup(privacyController, privacyIdProvider);
final CreatePrivacyGroupParameter param = new CreatePrivacyGroupParameter(ADDRESSES, NAME, DESCRIPTION);
final Object[] params = new Object[] { param };
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("1", "priv_createPrivacyGroup", params));
final JsonRpcErrorResponse response = (JsonRpcErrorResponse) privCreatePrivacyGroup.response(request);
final JsonRpcError result = response.getError();
assertThat(result).isEqualTo(JsonRpcError.ENCLAVE_ERROR);
}
Aggregations