Search in sources :

Example 1 with PrivacyGroup

use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.

the class PrivacyPrecompiledContractTest method testPayloadFoundInEnclave.

@Test
public void testPayloadFoundInEnclave() {
    final Enclave enclave = mock(Enclave.class);
    when(enclave.retrievePrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID)).thenReturn(new PrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", Arrays.asList(VALID_BASE64_ENCLAVE_KEY.toBase64String())));
    final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
    final List<Log> logs = new ArrayList<>();
    contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.successful(logs, 0, 0, Bytes.fromHexString(DEFAULT_OUTPUT), null)));
    final PrivateTransaction privateTransaction = privateTransactionBesu();
    final byte[] payload = convertPrivateTransactionToBytes(privateTransaction);
    final String privateFrom = privateTransaction.getPrivateFrom().toBase64String();
    final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
    when(enclave.receive(any(String.class))).thenReturn(response);
    final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId, messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Log(org.hyperledger.besu.evm.log.Log) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) ArrayList(java.util.ArrayList) PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Bytes(org.apache.tuweni.bytes.Bytes) Enclave(org.hyperledger.besu.enclave.Enclave) Test(org.junit.Test)

Example 2 with PrivacyGroup

use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.

the class PrivacyPrecompiledContractTest method testPrivateFromNotMemberOfGroup.

@Test
public void testPrivateFromNotMemberOfGroup() {
    final Enclave enclave = mock(Enclave.class);
    when(enclave.retrievePrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID)).thenReturn(new PrivacyGroup(PAYLOAD_TEST_PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", Arrays.asList(VALID_BASE64_ENCLAVE_KEY.toBase64String())));
    final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
    contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.successful(new ArrayList<>(), 0, 0, Bytes.fromHexString(DEFAULT_OUTPUT), null)));
    final PrivateTransaction privateTransaction = privateTransactionBesu();
    final byte[] payload = convertPrivateTransactionToBytes(privateTransaction);
    final String privateFrom = privateTransaction.getPrivateFrom().toBase64String();
    final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
    when(enclave.receive(any(String.class))).thenReturn(response);
    final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId, messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) Bytes(org.apache.tuweni.bytes.Bytes) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Enclave(org.hyperledger.besu.enclave.Enclave) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Test(org.junit.Test)

Example 3 with PrivacyGroup

use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.

the class FlexiblePrivacyControllerTest method findsPrivacyGroupById.

@Test
public void findsPrivacyGroupById() {
    final PrivacyGroup privacyGroup = new PrivacyGroup(PRIVACY_GROUP_ID, PrivacyGroup.Type.FLEXIBLE, "", "", PRIVACY_GROUP_ADDRESSES);
    mockingForFindPrivacyGroupById();
    final Optional<PrivacyGroup> privacyGroupFound = privacyController.findPrivacyGroupByGroupId(PRIVACY_GROUP_ID, ADDRESS1);
    assertThat(privacyGroupFound).isPresent();
    assertThat(privacyGroupFound.get()).usingRecursiveComparison().isEqualTo(privacyGroup);
}
Also used : PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Test(org.junit.Test)

Example 4 with PrivacyGroup

use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.

the class MultiTenancyPrivacyControllerTest method createPrivacyGroupDelegatesToPrivacyController.

@Test
public void createPrivacyGroupDelegatesToPrivacyController() {
    final List<String> addresses = List.of(ENCLAVE_PUBLIC_KEY1, ENCLAVE_PUBLIC_KEY2);
    final PrivacyGroup delegatePrivacyGroup = new PrivacyGroup(PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "name", "description", addresses);
    when(privacyController.createPrivacyGroup(addresses, "name", "description", ENCLAVE_PUBLIC_KEY1)).thenReturn(delegatePrivacyGroup);
    final PrivacyGroup privacyGroup = multiTenancyPrivacyController.createPrivacyGroup(addresses, "name", "description", ENCLAVE_PUBLIC_KEY1);
    assertThat(privacyGroup).usingRecursiveComparison().isEqualTo(delegatePrivacyGroup);
    verify(privacyController).createPrivacyGroup(addresses, "name", "description", ENCLAVE_PUBLIC_KEY1);
}
Also used : PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Test(org.junit.Test)

Example 5 with PrivacyGroup

use of org.hyperledger.besu.enclave.types.PrivacyGroup in project besu by hyperledger.

the class MultiTenancyPrivacyControllerTest method sendBesuTransactionFailsWithValidationExceptionWhenPrivacyGroupDoesNotContainPrivacyUserId.

@Test
public void sendBesuTransactionFailsWithValidationExceptionWhenPrivacyGroupDoesNotContainPrivacyUserId() {
    final PrivateTransaction transaction = PrivateTransaction.builder().privateFrom(Bytes.fromBase64String(ENCLAVE_PUBLIC_KEY1)).privacyGroupId(Bytes.fromBase64String(PRIVACY_GROUP_ID)).build();
    final PrivacyGroup privacyGroupWithoutPrivacyUserId = new PrivacyGroup(PRIVACY_GROUP_ID, PrivacyGroup.Type.PANTHEON, "", "", List.of(ENCLAVE_PUBLIC_KEY2));
    doThrow(new MultiTenancyValidationException("Privacy group must contain the enclave public key")).when(privacyController).verifyPrivacyGroupContainsPrivacyUserId(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY1);
    assertThatThrownBy(() -> multiTenancyPrivacyController.createPrivateMarkerTransactionPayload(transaction, ENCLAVE_PUBLIC_KEY1, Optional.of(privacyGroupWithoutPrivacyUserId))).isInstanceOf(MultiTenancyValidationException.class).hasMessage("Privacy group must contain the enclave public key");
    verify(privacyController, never()).createPrivateMarkerTransactionPayload(transaction, ENCLAVE_PUBLIC_KEY1, Optional.of(privacyGroupWithoutPrivacyUserId));
}
Also used : PrivacyGroup(org.hyperledger.besu.enclave.types.PrivacyGroup) Test(org.junit.Test)

Aggregations

PrivacyGroup (org.hyperledger.besu.enclave.types.PrivacyGroup)35 Test (org.junit.Test)19 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)13 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)8 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)7 JsonObject (io.vertx.core.json.JsonObject)5 Bytes (org.apache.tuweni.bytes.Bytes)5 ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)5 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)5 Enclave (org.hyperledger.besu.enclave.Enclave)4 MultiTenancyValidationException (org.hyperledger.besu.ethereum.privacy.MultiTenancyValidationException)4 PrivateTransaction (org.hyperledger.besu.ethereum.privacy.PrivateTransaction)4 Test (org.junit.jupiter.api.Test)4 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)3 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)3 PrecompiledContract (org.hyperledger.besu.evm.precompile.PrecompiledContract)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CreatePrivacyGroupParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter)2