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();
}
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();
}
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);
}
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()));
}
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<>());
}
Aggregations