Search in sources :

Example 1 with SendResponse

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

the class FlexiblePrivacyControllerTest method createsPayload.

@Test
public void createsPayload() {
    final PrivateTransaction privateTransaction = buildPrivateTransaction(1).signAndBuild(KEY_PAIR);
    final SendResponse key = new SendResponse(KEY);
    when(enclave.send(any(), any(), anyList())).thenReturn(key);
    final String payload = privacyController.createPrivateMarkerTransactionPayload(privateTransaction, ADDRESS1, Optional.of(EXPECTED_PRIVACY_GROUP));
    assertThat(payload).isNotNull().isEqualTo(KEY);
}
Also used : SendResponse(org.hyperledger.besu.enclave.types.SendResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with SendResponse

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

the class EnclaveTest method testSendAndReceive.

@Test
public void testSendAndReceive() {
    final List<String> publicKeys = testHarness.getPublicKeys();
    final SendResponse sr = enclave.send(PAYLOAD, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
    final ReceiveResponse rr = enclave.receive(sr.getKey(), publicKeys.get(0));
    assertThat(rr).isNotNull();
    assertThat(new String(rr.getPayload(), UTF_8)).isEqualTo(PAYLOAD);
    assertThat(rr.getPrivacyGroupId()).isNotNull();
}
Also used : SendResponse(org.hyperledger.besu.enclave.types.SendResponse) ReceiveResponse(org.hyperledger.besu.enclave.types.ReceiveResponse) Test(org.junit.jupiter.api.Test)

Example 3 with SendResponse

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

the class PrivacyPrecompiledContractIntegrationTest method testSendAndReceive.

@Test
public void testSendAndReceive() {
    final List<String> publicKeys = testHarness.getPublicKeys();
    final PrivateTransaction privateTransaction = PrivateTransactionDataFixture.privateContractDeploymentTransactionBesu(publicKeys.get(0));
    final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput();
    privateTransaction.writeTo(bytesValueRLPOutput);
    final String s = bytesValueRLPOutput.encoded().toBase64String();
    final SendResponse sr = enclave.send(s, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
    final PrivacyPrecompiledContract privacyPrecompiledContract = new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), enclave, worldStateArchive, new PrivateStateRootResolver(privateStateStorage), new PrivateStateGenesisAllocator(false, (privacyGroupId, blockNumber) -> Collections::emptyList), "IntegrationTest");
    privacyPrecompiledContract.setPrivateTransactionProcessor(mockPrivateTxProcessor());
    final PrecompiledContract.PrecompileContractResult result = privacyPrecompiledContract.computePrecompile(Bytes.fromBase64String(sr.getKey()), messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) EnclaveKeyConfiguration(org.hyperledger.enclave.testutil.EnclaveKeyConfiguration) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) OperationTracer(org.hyperledger.besu.evm.tracing.OperationTracer) AfterAll(org.junit.jupiter.api.AfterAll) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) BeforeAll(org.junit.jupiter.api.BeforeAll) Enclave(org.hyperledger.besu.enclave.Enclave) Block(org.hyperledger.besu.ethereum.core.Block) Path(java.nio.file.Path) Bytes32(org.apache.tuweni.bytes.Bytes32) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) TesseraTestHarness(org.hyperledger.enclave.testutil.TesseraTestHarness) Test(org.junit.jupiter.api.Test) List(java.util.List) PrivateStateGenesisAllocator(org.hyperledger.besu.ethereum.privacy.PrivateStateGenesisAllocator) TempDir(org.junit.jupiter.api.io.TempDir) PrivateTransactionDataFixture(org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Bytes(org.apache.tuweni.bytes.Bytes) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Address(org.hyperledger.besu.datatypes.Address) SendResponse(org.hyperledger.besu.enclave.types.SendResponse) EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) Lists(com.google.common.collect.Lists) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) TesseraTestHarnessFactory(org.hyperledger.enclave.testutil.TesseraTestHarnessFactory) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) Files(java.nio.file.Files) Vertx(io.vertx.core.Vertx) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Mockito.when(org.mockito.Mockito.when) BlockHashLookup(org.hyperledger.besu.ethereum.vm.BlockHashLookup) PrivateTransactionProcessor(org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) PrivateStateUtils(org.hyperledger.besu.ethereum.mainnet.PrivateStateUtils) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Collections(java.util.Collections) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) SendResponse(org.hyperledger.besu.enclave.types.SendResponse) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Bytes(org.apache.tuweni.bytes.Bytes) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) PrivateStateGenesisAllocator(org.hyperledger.besu.ethereum.privacy.PrivateStateGenesisAllocator) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) Test(org.junit.jupiter.api.Test)

Example 4 with SendResponse

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

the class FlexiblePrivacyController method createPrivateMarkerTransactionPayload.

@Override
public String createPrivateMarkerTransactionPayload(final PrivateTransaction privateTransaction, final String privacyUserId, final Optional<PrivacyGroup> privacyGroup) {
    LOG.trace("Storing private transaction in enclave");
    final SendResponse sendResponse = sendRequest(privateTransaction, privacyGroup);
    final String firstPart = sendResponse.getKey();
    final Optional<String> optionalSecondPart = buildAndSendAddPayload(privateTransaction, Bytes32.wrap(privateTransaction.getPrivacyGroupId().orElseThrow()), privacyUserId);
    return buildCompoundLookupId(firstPart, optionalSecondPart);
}
Also used : SendResponse(org.hyperledger.besu.enclave.types.SendResponse)

Example 5 with SendResponse

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

the class PrivGetPrivateTransactionIntegrationTest method returnsStoredPrivateTransaction.

@Test
public void returnsStoredPrivateTransaction() {
    final PrivGetPrivateTransaction privGetPrivateTransaction = new PrivGetPrivateTransaction(privacyController, privacyIdProvider);
    final Hash blockHash = Hash.ZERO;
    final Transaction pmt = spy(privateMarkerTransaction());
    when(blockchain.getTransactionByHash(eq(pmt.getHash()))).thenReturn(Optional.of(pmt));
    when(blockchain.getTransactionLocation(eq(pmt.getHash()))).thenReturn(Optional.of(new TransactionLocation(blockHash, 0)));
    final BlockHeader blockHeader = mock(BlockHeader.class);
    when(blockHeader.getHash()).thenReturn(blockHash);
    when(blockchain.getBlockHeader(eq(blockHash))).thenReturn(Optional.of(blockHeader));
    final BytesValueRLPOutput bvrlp = new BytesValueRLPOutput();
    privateTransaction.writeTo(bvrlp);
    final String payload = Base64.getEncoder().encodeToString(bvrlp.encoded().toArrayUnsafe());
    final ArrayList<String> to = Lists.newArrayList("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=");
    final SendResponse sendResponse = enclave.send(payload, ENCLAVE_PUBLIC_KEY, to);
    final Bytes hexKey = Bytes.fromBase64String(sendResponse.getKey());
    when(pmt.getPayload()).thenReturn(hexKey);
    final Object[] params = new Object[] { pmt.getHash() };
    final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("1", "priv_getPrivateTransaction", params));
    final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privGetPrivateTransaction.response(request);
    final PrivateTransactionLegacyResult result = (PrivateTransactionLegacyResult) response.getResult();
    assertThat(new PrivateTransactionLegacyResult(this.privateTransaction)).usingRecursiveComparison().isEqualTo(result);
}
Also used : JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) SendResponse(org.hyperledger.besu.enclave.types.SendResponse) PrivateTransactionLegacyResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionLegacyResult) Hash(org.hyperledger.besu.datatypes.Hash) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Bytes(org.apache.tuweni.bytes.Bytes) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) PrivGetPrivateTransaction(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction) PrivateTransactionDataFixture.privateMarkerTransaction(org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.privateMarkerTransaction) Transaction(org.hyperledger.besu.ethereum.core.Transaction) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) TransactionLocation(org.hyperledger.besu.ethereum.chain.TransactionLocation) PrivGetPrivateTransaction(org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.jupiter.api.Test)

Aggregations

SendResponse (org.hyperledger.besu.enclave.types.SendResponse)11 Test (org.junit.jupiter.api.Test)6 Hash (org.hyperledger.besu.datatypes.Hash)3 ReceiveResponse (org.hyperledger.besu.enclave.types.ReceiveResponse)3 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)3 Bytes (org.apache.tuweni.bytes.Bytes)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)2 Transaction (org.hyperledger.besu.ethereum.core.Transaction)2 PrivateTransaction (org.hyperledger.besu.ethereum.privacy.PrivateTransaction)2 PrivacyGroupHeadBlockMap (org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap)2 Lists (com.google.common.collect.Lists)1 Vertx (io.vertx.core.Vertx)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1