[PAN-2932] create privacy group return correct error if not include self (#1923)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Ivaylo Kirilov 5 years ago committed by Usman Saleem
parent 07fd4c1327
commit 53c7d6c2eb
  1. 8
      acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/EnclaveErrorAcceptanceTest.java
  2. 6
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java
  3. 2
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroupTest.java

@ -153,4 +153,12 @@ public class EnclaveErrorAcceptanceTest extends PrivacyAcceptanceTestBase {
assertThat(throwable).hasMessageContaining("NodePushingToPeer");
}
@Test
public void createPrivacyGroupReturnsCorrectError() {
final Throwable throwable =
catchThrowable(() -> alice.execute(privacyTransactions.createPrivacyGroup(null, null)));
assertThat(throwable).hasMessageContaining(JsonRpcError.CREATE_GROUP_INCLUDE_SELF.getMessage());
}
}

@ -18,12 +18,12 @@ 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.JsonRpcEnclaveErrorConverter;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
@ -74,7 +74,9 @@ public class PrivCreatePrivacyGroup implements JsonRpcMethod {
response = enclave.createPrivacyGroup(createPrivacyGroupRequest);
} catch (Exception e) {
LOG.error("Failed to create privacy group", e);
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.CREATE_PRIVACY_GROUP_ERROR);
return new JsonRpcErrorResponse(
request.getId(),
JsonRpcEnclaveErrorConverter.convertEnclaveInvalidReason(e.getMessage()));
}
return new JsonRpcSuccessResponse(request.getId(), response.getPrivacyGroupId());
}

@ -244,6 +244,6 @@ public class PrivCreatePrivacyGroupTest {
final JsonRpcError result = response.getError();
assertThat(result).isEqualTo(JsonRpcError.CREATE_PRIVACY_GROUP_ERROR);
assertThat(result).isEqualTo(JsonRpcError.ENCLAVE_ERROR);
}
}

Loading…
Cancel
Save