Search in sources :

Example 1 with Enclave

use of org.hyperledger.besu.enclave.Enclave 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 Enclave

use of org.hyperledger.besu.enclave.Enclave 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 Enclave

use of org.hyperledger.besu.enclave.Enclave in project besu by hyperledger.

the class FlexiblePrivacyPrecompiledContractTest method testPayloadNull.

@Test
public void testPayloadNull() {
    final Enclave enclave = mock(Enclave.class);
    final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
    final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(null, messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.EMPTY);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Enclave(org.hyperledger.besu.enclave.Enclave) Test(org.junit.Test)

Example 4 with Enclave

use of org.hyperledger.besu.enclave.Enclave in project besu by hyperledger.

the class FlexiblePrivacyPrecompiledContractTest method testPayloadLessThan32Bytes.

@Test
public void testPayloadLessThan32Bytes() {
    final Enclave enclave = mock(Enclave.class);
    final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
    final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId.slice(10), messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.EMPTY);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Enclave(org.hyperledger.besu.enclave.Enclave) Test(org.junit.Test)

Example 5 with Enclave

use of org.hyperledger.besu.enclave.Enclave in project besu by hyperledger.

the class FlexiblePrivacyPrecompiledContractTest method testPayloadMoreThan32LessThan64Bytes.

@Test
public void testPayloadMoreThan32LessThan64Bytes() {
    final Enclave enclave = mock(Enclave.class);
    final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
    final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId64.slice(40), messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.EMPTY);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Enclave(org.hyperledger.besu.enclave.Enclave) Test(org.junit.Test)

Aggregations

Enclave (org.hyperledger.besu.enclave.Enclave)26 Test (org.junit.Test)20 Bytes (org.apache.tuweni.bytes.Bytes)17 PrecompiledContract (org.hyperledger.besu.evm.precompile.PrecompiledContract)16 ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)14 PrivateTransaction (org.hyperledger.besu.ethereum.privacy.PrivateTransaction)7 VersionedPrivateTransaction (org.hyperledger.besu.ethereum.privacy.VersionedPrivateTransaction)7 ArrayList (java.util.ArrayList)5 Log (org.hyperledger.besu.evm.log.Log)5 Collections (java.util.Collections)3 PrivacyGroup (org.hyperledger.besu.enclave.types.PrivacyGroup)3 Vertx (io.vertx.core.Vertx)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 List (java.util.List)2 Optional (java.util.Optional)2 Address (org.hyperledger.besu.datatypes.Address)2 EnclaveConfigurationException (org.hyperledger.besu.enclave.EnclaveConfigurationException)2 EnclaveFactory (org.hyperledger.besu.enclave.EnclaveFactory)2 PrivateStateGenesisAllocator (org.hyperledger.besu.ethereum.privacy.PrivateStateGenesisAllocator)2