Search in sources :

Example 1 with TransactionProcessingResult

use of org.hyperledger.besu.ethereum.processing.TransactionProcessingResult in project besu by hyperledger.

the class MultiTenancyPrivacyControllerOnchainTest method simulatePrivateTransactionSucceedsForPresentEnclaveKey.

@Test
public void simulatePrivateTransactionSucceedsForPresentEnclaveKey() {
    when(privacyController.simulatePrivateTransaction(any(), any(), any(), any(long.class))).thenReturn(Optional.of(TransactionProcessingResult.successful(LOGS, 0, 0, Bytes.EMPTY, ValidationResult.valid())));
    final Optional<TransactionProcessingResult> result = multiTenancyPrivacyController.simulatePrivateTransaction(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY1, new CallParameter(Address.ZERO, Address.ZERO, 0, Wei.ZERO, Wei.ZERO, Bytes.EMPTY), 1);
    assertThat(result.isPresent()).isTrue();
    assertThat(result.get().getValidationResult().isValid()).isTrue();
}
Also used : CallParameter(org.hyperledger.besu.ethereum.transaction.CallParameter) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) Test(org.junit.Test)

Example 2 with TransactionProcessingResult

use of org.hyperledger.besu.ethereum.processing.TransactionProcessingResult in project besu by hyperledger.

the class MultiTenancyPrivacyControllerTest method simulatePrivateTransactionWorksForValidEnclaveKey.

@Test
public void simulatePrivateTransactionWorksForValidEnclaveKey() {
    when(privacyController.simulatePrivateTransaction(any(), any(), any(), any(long.class))).thenReturn(Optional.of(TransactionProcessingResult.successful(LOGS, 0, 0, Bytes.EMPTY, ValidationResult.valid())));
    final Optional<TransactionProcessingResult> result = multiTenancyPrivacyController.simulatePrivateTransaction(PRIVACY_GROUP_ID, ENCLAVE_PUBLIC_KEY1, new CallParameter(Address.ZERO, Address.ZERO, 0, Wei.ZERO, Wei.ZERO, Bytes.EMPTY), 1);
    assertThat(result).isPresent();
    assertThat(result.get().getValidationResult().isValid()).isTrue();
}
Also used : CallParameter(org.hyperledger.besu.ethereum.transaction.CallParameter) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) Test(org.junit.Test)

Example 3 with TransactionProcessingResult

use of org.hyperledger.besu.ethereum.processing.TransactionProcessingResult in project besu by hyperledger.

the class DebugTraceBlockByHashTest method shouldReturnCorrectResponse.

@Test
public void shouldReturnCorrectResponse() {
    final Object[] params = new Object[] { blockHash };
    final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_traceBlockByHash", params));
    final TraceFrame traceFrame = new TraceFrame(12, Optional.of("NONE"), 45L, OptionalLong.of(56L), 0L, 2, Optional.empty(), null, Wei.ZERO, Bytes.EMPTY, Bytes.EMPTY, Optional.empty(), Optional.empty(), Optional.empty(), null, Optional.empty(), Optional.empty(), Optional.empty(), 0, Optional.empty(), false, Optional.empty(), Optional.empty());
    final TransactionProcessingResult transaction1Result = mock(TransactionProcessingResult.class);
    final TransactionProcessingResult transaction2Result = mock(TransactionProcessingResult.class);
    final TransactionTrace transaction1Trace = mock(TransactionTrace.class);
    final TransactionTrace transaction2Trace = mock(TransactionTrace.class);
    BlockTrace blockTrace = new BlockTrace(Arrays.asList(transaction1Trace, transaction2Trace));
    when(transaction1Trace.getTraceFrames()).thenReturn(Arrays.asList(traceFrame));
    when(transaction2Trace.getTraceFrames()).thenReturn(Arrays.asList(traceFrame));
    when(transaction1Trace.getResult()).thenReturn(transaction1Result);
    when(transaction2Trace.getResult()).thenReturn(transaction2Result);
    when(transaction1Result.getOutput()).thenReturn(Bytes.fromHexString("1234"));
    when(transaction2Result.getOutput()).thenReturn(Bytes.fromHexString("1234"));
    when(blockTracer.trace(eq(blockHash), any())).thenReturn(Optional.of(blockTrace));
    final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) debugTraceBlockByHash.response(request);
    final Collection<?> result = (Collection<?>) response.getResult();
    assertThat(result).hasSize(2);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) Collection(java.util.Collection) BlockTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) TraceFrame(org.hyperledger.besu.ethereum.debug.TraceFrame) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) Test(org.junit.Test)

Example 4 with TransactionProcessingResult

use of org.hyperledger.besu.ethereum.processing.TransactionProcessingResult in project besu by hyperledger.

the class DebugTraceBlockByNumberTest method shouldReturnCorrectResponse.

@Test
public void shouldReturnCorrectResponse() {
    final long blockNumber = 1L;
    final Object[] params = new Object[] { Long.toHexString(blockNumber) };
    final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_traceBlockByNumber", params));
    final TraceFrame traceFrame = new TraceFrame(12, Optional.of("NONE"), 45L, OptionalLong.of(56L), 0L, 2, Optional.empty(), null, Wei.ZERO, Bytes.EMPTY, Bytes.EMPTY, Optional.empty(), Optional.empty(), Optional.empty(), null, Optional.empty(), Optional.empty(), Optional.empty(), 0, Optional.empty(), false, Optional.empty(), Optional.empty());
    final TransactionProcessingResult transaction1Result = mock(TransactionProcessingResult.class);
    final TransactionProcessingResult transaction2Result = mock(TransactionProcessingResult.class);
    final TransactionTrace transaction1Trace = mock(TransactionTrace.class);
    final TransactionTrace transaction2Trace = mock(TransactionTrace.class);
    final BlockTrace blockTrace = new BlockTrace(asList(transaction1Trace, transaction2Trace));
    when(transaction1Trace.getTraceFrames()).thenReturn(singletonList(traceFrame));
    when(transaction2Trace.getTraceFrames()).thenReturn(singletonList(traceFrame));
    when(transaction1Trace.getResult()).thenReturn(transaction1Result);
    when(transaction2Trace.getResult()).thenReturn(transaction2Result);
    when(transaction1Result.getOutput()).thenReturn(Bytes.fromHexString("1234"));
    when(transaction2Result.getOutput()).thenReturn(Bytes.fromHexString("1234"));
    when(blockchain.getBlockHashByNumber(blockNumber)).thenReturn(Optional.of(blockHash));
    when(blockTracer.trace(eq(blockHash), any())).thenReturn(Optional.of(blockTrace));
    final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) debugTraceBlockByNumber.response(request);
    final Collection<DebugTraceTransactionResult> result = getResult(response);
    assertThat(result).usingFieldByFieldElementComparator().isEqualTo(DebugTraceTransactionResult.of(blockTrace.getTransactionTraces()));
}
Also used : DebugTraceTransactionResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) JsonRpcRequest(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) BlockTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) TraceFrame(org.hyperledger.besu.ethereum.debug.TraceFrame) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) Test(org.junit.Test)

Example 5 with TransactionProcessingResult

use of org.hyperledger.besu.ethereum.processing.TransactionProcessingResult in project besu by hyperledger.

the class TransactionTracer method traceTransactionToFile.

public List<String> traceTransactionToFile(final Hash blockHash, final Optional<TransactionTraceParams> transactionTraceParams, final Path traceDir) {
    final Optional<Hash> selectedHash = transactionTraceParams.map(TransactionTraceParams::getTransactionHash).map(Hash::fromHexString);
    final boolean showMemory = transactionTraceParams.map(TransactionTraceParams::traceOptions).map(TraceOptions::isMemoryEnabled).orElse(true);
    if (!Files.isDirectory(traceDir) && !traceDir.toFile().mkdirs()) {
        throw new RuntimeException(String.format("Trace directory '%s' does not exist and could not be made.", traceDir));
    }
    return blockReplay.performActionWithBlock(blockHash, (body, header, blockchain, worldState, transactionProcessor) -> {
        WorldUpdater stackedUpdater = worldState.updater().updater();
        final List<String> traces = new ArrayList<>();
        for (int i = 0; i < body.getTransactions().size(); i++) {
            ((StackedUpdater<?, ?>) stackedUpdater).markTransactionBoundary();
            final Transaction transaction = body.getTransactions().get(i);
            if (selectedHash.isEmpty() || selectedHash.filter(isEqual(transaction.getHash())).isPresent()) {
                final File traceFile = generateTraceFile(traceDir, blockHash, i, transaction);
                try (PrintStream out = new PrintStream(new FileOutputStream(traceFile))) {
                    final Stopwatch timer = Stopwatch.createStarted();
                    final TransactionProcessingResult result = processTransaction(header, blockchain, stackedUpdater, transaction, transactionProcessor, new StandardJsonTracer(out, showMemory));
                    out.println(summaryTrace(transaction, timer.stop().elapsed(TimeUnit.NANOSECONDS), result));
                    traces.add(traceFile.getPath());
                } catch (FileNotFoundException e) {
                    throw new RuntimeException("Unable to create transaction trace : " + e.getMessage());
                }
            } else {
                processTransaction(header, blockchain, stackedUpdater, transaction, transactionProcessor, OperationTracer.NO_TRACING);
            }
        }
        return Optional.of(traces);
    }).orElse(new ArrayList<>());
}
Also used : TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) StackedUpdater(org.hyperledger.besu.evm.worldstate.StackedUpdater) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) Stopwatch(com.google.common.base.Stopwatch) OperationTracer(org.hyperledger.besu.evm.tracing.OperationTracer) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) TransactionTraceParams(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams) UInt256(org.apache.tuweni.units.bigints.UInt256) Path(java.nio.file.Path) PrintStream(java.io.PrintStream) Files(java.nio.file.Files) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Predicate.isEqual(java.util.function.Predicate.isEqual) FileOutputStream(java.io.FileOutputStream) MainnetTransactionProcessor(org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor) BlockHashLookup(org.hyperledger.besu.ethereum.vm.BlockHashLookup) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ImmutableTransactionValidationParams(org.hyperledger.besu.ethereum.mainnet.ImmutableTransactionValidationParams) Optional(java.util.Optional) Transaction(org.hyperledger.besu.ethereum.core.Transaction) StandardJsonTracer(org.hyperledger.besu.evm.tracing.StandardJsonTracer) Hash(org.hyperledger.besu.datatypes.Hash) PrintStream(java.io.PrintStream) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) Stopwatch(com.google.common.base.Stopwatch) FileNotFoundException(java.io.FileNotFoundException) TransactionTraceParams(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TransactionTraceParams) Hash(org.hyperledger.besu.datatypes.Hash) StandardJsonTracer(org.hyperledger.besu.evm.tracing.StandardJsonTracer) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) Transaction(org.hyperledger.besu.ethereum.core.Transaction) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Aggregations

TransactionProcessingResult (org.hyperledger.besu.ethereum.processing.TransactionProcessingResult)35 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)17 Transaction (org.hyperledger.besu.ethereum.core.Transaction)12 BlockHashLookup (org.hyperledger.besu.ethereum.vm.BlockHashLookup)11 Test (org.junit.Test)11 Address (org.hyperledger.besu.datatypes.Address)10 Hash (org.hyperledger.besu.datatypes.Hash)9 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)9 Bytes (org.apache.tuweni.bytes.Bytes)8 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)8 ArrayList (java.util.ArrayList)7 Bytes32 (org.apache.tuweni.bytes.Bytes32)7 OperationTracer (org.hyperledger.besu.evm.tracing.OperationTracer)7 TraceFrame (org.hyperledger.besu.ethereum.debug.TraceFrame)6 TransactionInvalidReason (org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason)6 Account (org.hyperledger.besu.evm.account.Account)6 Wei (org.hyperledger.besu.datatypes.Wei)5 JsonRpcRequest (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest)5 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)5 TransactionTrace (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace)5