use of org.hyperledger.besu.enclave.Enclave in project besu by hyperledger.
the class FlexiblePrivacyPrecompiledContractTest method testPayloadFoundInEnclaveWith64ByteResult.
@Test
public void testPayloadFoundInEnclaveWith64ByteResult() {
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(privateTransactionLookupId64, messageFrame);
final Bytes actual = result.getOutput();
assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
use of org.hyperledger.besu.enclave.Enclave in project besu by hyperledger.
the class FlexiblePrivacyPrecompiledContractTest method testPayloadNotFoundInEnclave.
@Test
public void testPayloadNotFoundInEnclave() {
final Enclave enclave = mock(Enclave.class);
final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
when(enclave.receive(any(String.class))).thenThrow(EnclaveClientException.class);
final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId, messageFrame);
final Bytes actual = result.getOutput();
assertThat(actual).isEqualTo(Bytes.EMPTY);
}
use of org.hyperledger.besu.enclave.Enclave in project besu by hyperledger.
the class PrivacyPrecompiledContractTest method testEnclaveBelowRequiredVersion.
@Test
public void testEnclaveBelowRequiredVersion() {
final Enclave enclave = mock(Enclave.class);
final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
final PrivateTransaction privateTransaction = privateTransactionBesu();
final byte[] payload = convertPrivateTransactionToBytes(privateTransaction);
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.");
}
use of org.hyperledger.besu.enclave.Enclave in project besu by hyperledger.
the class PrivacyPrecompiledContractTest method testPayloadNotFoundInEnclave.
@Test
public void testPayloadNotFoundInEnclave() {
final Enclave enclave = mock(Enclave.class);
final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
when(enclave.receive(any(String.class))).thenThrow(EnclaveClientException.class);
final PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(privateTransactionLookupId, messageFrame);
final Bytes actual = result.getOutput();
assertThat(actual).isEqualTo(Bytes.EMPTY);
}
use of org.hyperledger.besu.enclave.Enclave in project besu by hyperledger.
the class PrivacyPrecompiledContractTest method testPrivateTransactionWithoutPrivateFrom.
@Test
public void testPrivateTransactionWithoutPrivateFrom() {
final Enclave enclave = mock(Enclave.class);
final PrivacyPrecompiledContract contract = buildPrivacyPrecompiledContract(enclave);
final PrivateTransaction privateTransaction = spy(privateTransactionBesu());
when(privateTransaction.getPrivateFrom()).thenReturn(Bytes.EMPTY);
final byte[] payload = convertPrivateTransactionToBytes(privateTransaction);
final String senderKey = privateTransaction.getPrivateFrom().toBase64String();
final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, senderKey);
when(enclave.receive(eq(privateTransactionLookupId.toBase64String()))).thenReturn(response);
final Bytes expected = contract.compute(privateTransactionLookupId, messageFrame);
assertThat(expected).isEqualTo(Bytes.EMPTY);
}
Aggregations