Search in sources :

Example 1 with ReceiveResponse

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

the class FlexiblePrivacyPrecompiledContractTest method testPayloadFoundInEnclave.

@Test
public void testPayloadFoundInEnclave() {
    final Enclave enclave = mock(Enclave.class);
    final FlexiblePrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
    final List<Log> logs = new ArrayList<>();
    contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.successful(logs, 0, 0, Bytes.fromHexString(DEFAULT_OUTPUT), null)));
    final VersionedPrivateTransaction versionedPrivateTransaction = versionedPrivateTransactionBesu();
    final byte[] payload = convertVersionedPrivateTransactionToBytes(versionedPrivateTransaction);
    final String privateFrom = versionedPrivateTransaction.getPrivateTransaction().getPrivateFrom().toBase64String();
    final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
    when(enclave.receive(any())).thenReturn(response);
    final FlexiblePrivacyPrecompiledContract contractSpy = spy(contract);
    Mockito.doReturn(true).when(contractSpy).canExecute(any(), any(), any(), any(), any(), any(), any(), any());
    final PrecompiledContract.PrecompileContractResult result = contractSpy.computePrecompile(privateTransactionLookupId, messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Log(org.hyperledger.besu.evm.log.Log) Enclave(org.hyperledger.besu.enclave.Enclave) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) ArrayList(java.util.ArrayList) VersionedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.VersionedPrivateTransaction) Test(org.junit.Test)

Example 2 with ReceiveResponse

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

the class FlexiblePrivacyPrecompiledContractTest method testEnclaveBelowRequiredVersion.

@Test
public void testEnclaveBelowRequiredVersion() {
    final Enclave enclave = mock(Enclave.class);
    final FlexiblePrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
    final VersionedPrivateTransaction versionedPrivateTransaction = versionedPrivateTransactionBesu();
    final byte[] payload = convertVersionedPrivateTransactionToBytes(versionedPrivateTransaction);
    final ReceiveResponse responseWithoutSenderKey = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, null);
    when(enclave.receive(eq(privateTransactionLookupId.toBase64String()))).thenReturn(responseWithoutSenderKey);
    assertThatThrownBy(() -> contract.computePrecompile(privateTransactionLookupId, messageFrame)).isInstanceOf(EnclaveConfigurationException.class).hasMessage("Incompatible Orion version. Orion version must be 1.6.0 or greater.");
}
Also used : EnclaveConfigurationException(org.hyperledger.besu.enclave.EnclaveConfigurationException) Enclave(org.hyperledger.besu.enclave.Enclave) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) VersionedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.VersionedPrivateTransaction) Test(org.junit.Test)

Example 3 with ReceiveResponse

use of org.hyperledger.besu.enclave.types.ReceiveResponse 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 4 with ReceiveResponse

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

the class PrivacyPrecompiledContractTest method testPayloadNotMatchingPrivateFrom.

@Test
public void testPayloadNotMatchingPrivateFrom() {
    final Enclave enclave = mock(Enclave.class);
    final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
    final PrivateTransaction privateTransaction = privateTransactionBesu();
    final byte[] payload = convertPrivateTransactionToBytes(privateTransaction);
    final String wrongSenderKey = Bytes.random(32).toBase64String();
    final ReceiveResponse responseWithWrongSenderKey = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, wrongSenderKey);
    when(enclave.receive(eq(privateTransactionLookupId.toBase64String()))).thenReturn(responseWithWrongSenderKey);
    final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId, messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.EMPTY);
}
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) Test(org.junit.Test)

Example 5 with ReceiveResponse

use of org.hyperledger.besu.enclave.types.ReceiveResponse 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)

Aggregations

ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)31 Enclave (org.hyperledger.besu.enclave.Enclave)15 Bytes (org.apache.tuweni.bytes.Bytes)14 Test (org.junit.Test)14 PrecompiledContract (org.hyperledger.besu.evm.precompile.PrecompiledContract)10 VersionedPrivateTransaction (org.hyperledger.besu.ethereum.privacy.VersionedPrivateTransaction)9 PrivateTransaction (org.hyperledger.besu.ethereum.privacy.PrivateTransaction)8 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)7 ArrayList (java.util.ArrayList)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)5 PrivacyGroup (org.hyperledger.besu.enclave.types.PrivacyGroup)5 Log (org.hyperledger.besu.evm.log.Log)5 EnclaveClientException (org.hyperledger.besu.enclave.EnclaveClientException)3 SendResponse (org.hyperledger.besu.enclave.types.SendResponse)3 PrivateTransactionMetadata (org.hyperledger.besu.ethereum.privacy.storage.PrivateTransactionMetadata)3 BytesValueRLPInput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput)3 Nonnull (javax.annotation.Nonnull)2 Hash (org.hyperledger.besu.datatypes.Hash)2 EnclaveConfigurationException (org.hyperledger.besu.enclave.EnclaveConfigurationException)2 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)2