Search in sources :

Example 26 with Enclave

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

the class PrivacyPrecompiledContractTest method testInvalidPrivateTransaction.

@Test
public void testInvalidPrivateTransaction() {
    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 = new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), enclave, worldStateArchive, privateStateRootResolver, privateStateGenesisAllocator, "RestrictedPrivacyTest");
    contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.invalid(ValidationResult.invalid(TransactionInvalidReason.INCORRECT_NONCE))));
    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.EMPTY);
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) Bytes(org.apache.tuweni.bytes.Bytes) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) 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

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