Search in sources :

Example 1 with PrivateTransactionLegacyResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionLegacyResult 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)

Example 2 with PrivateTransactionLegacyResult

use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionLegacyResult in project besu by hyperledger.

the class PrivGetPrivateTransactionTest method returnsPrivateTransactionLegacy.

@Test
public void returnsPrivateTransactionLegacy() {
    final PrivateTransaction legacyPrivateTransaction = PrivateTransactionDataFixture.privateTransactionLegacy();
    final ExecutedPrivateTransaction executedPrivateTransaction = createExecutedPrivateTransaction(legacyPrivateTransaction);
    when(privacyController.findPrivateTransactionByPmtHash(any(), any())).thenReturn(Optional.of(executedPrivateTransaction));
    final PrivateTransactionLegacyResult expectedResult = new PrivateTransactionLegacyResult(legacyPrivateTransaction);
    final JsonRpcRequestContext request = createRequestContext();
    final PrivateTransactionResult result = makeRequest(request);
    assertThat(result).usingRecursiveComparison().isEqualTo(expectedResult);
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) PrivateTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionResult) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) PrivateTransactionLegacyResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionLegacyResult) ExecutedPrivateTransaction(org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction) Test(org.junit.Test)

Aggregations

JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)2 PrivateTransactionLegacyResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionLegacyResult)2 PrivateTransaction (org.hyperledger.besu.ethereum.privacy.PrivateTransaction)2 Bytes (org.apache.tuweni.bytes.Bytes)1 Hash (org.hyperledger.besu.datatypes.Hash)1 SendResponse (org.hyperledger.besu.enclave.types.SendResponse)1 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)1 PrivGetPrivateTransaction (org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.priv.PrivGetPrivateTransaction)1 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)1 PrivateTransactionResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.privacy.PrivateTransactionResult)1 TransactionLocation (org.hyperledger.besu.ethereum.chain.TransactionLocation)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 PrivateTransactionDataFixture.privateMarkerTransaction (org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.privateMarkerTransaction)1 Transaction (org.hyperledger.besu.ethereum.core.Transaction)1 ExecutedPrivateTransaction (org.hyperledger.besu.ethereum.privacy.ExecutedPrivateTransaction)1 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1