use of org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult in project besu by hyperledger.
the class NodeSmartContractV2PermissioningControllerTest method nonExpectedCallOutputThrowsIllegalState.
@Test
public void nonExpectedCallOutputThrowsIllegalState() {
final TransactionSimulatorResult txSimulatorResult = transactionSimulatorResult(Bytes.random(10), ValidationResult.valid());
when(transactionSimulator.processAtHead(eq(callParams(SOURCE_ENODE_EXPECTED_PAYLOAD_IP)))).thenReturn(Optional.of(txSimulatorResult));
assertThatIllegalStateException().isThrownBy(() -> permissioningController.checkSmartContractRules(SOURCE_ENODE_IPV4, DESTINATION_ENODE_IPV4));
}
use of org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult in project besu by hyperledger.
the class NodeSmartContractV2PermissioningControllerTest method expectedPayloadWhenCheckingPermissioningWithIPV4.
@Test
public void expectedPayloadWhenCheckingPermissioningWithIPV4() {
final TransactionSimulatorResult txSimulatorResult = transactionSimulatorResult(NodeSmartContractV2PermissioningController.TRUE_RESPONSE, ValidationResult.valid());
when(transactionSimulator.processAtHead(eq(callParams(SOURCE_ENODE_EXPECTED_PAYLOAD_IP)))).thenReturn(Optional.of(txSimulatorResult));
when(transactionSimulator.processAtHead(eq(callParams(DESTINATION_ENODE_EXPECTED_PAYLOAD_IP)))).thenReturn(Optional.of(txSimulatorResult));
boolean isPermitted = permissioningController.checkSmartContractRules(SOURCE_ENODE_IPV4, DESTINATION_ENODE_IPV4);
assertThat(isPermitted).isTrue();
verify(transactionSimulator, times(2)).processAtHead(any());
}
use of org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult in project besu by hyperledger.
the class ValidatorContractControllerTest method throwErrorIfUnexpectedSuccessfulEmptySimulationResult.
@Test
public void throwErrorIfUnexpectedSuccessfulEmptySimulationResult() {
final TransactionSimulatorResult result = new TransactionSimulatorResult(transaction, TransactionProcessingResult.successful(List.of(), 0, 0, Bytes.EMPTY, ValidationResult.valid()));
when(transactionSimulator.process(callParameter, 1)).thenReturn(Optional.of(result));
final ValidatorContractController validatorContractController = new ValidatorContractController(transactionSimulator);
Assertions.assertThatThrownBy(() -> validatorContractController.getValidators(1, CONTRACT_ADDRESS)).hasMessage("Unexpected empty result from validator smart contract call");
}
use of org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult in project besu by hyperledger.
the class TraceCallMany method getSingleCallResult.
private JsonNode getSingleCallResult(final JsonCallParameter callParameter, final TraceTypeParameter traceTypeParameter, final BlockHeader header, final WorldUpdater worldUpdater) {
final Set<TraceTypeParameter.TraceType> traceTypes = traceTypeParameter.getTraceTypes();
final DebugOperationTracer tracer = new DebugOperationTracer(buildTraceOptions(traceTypes));
final Optional<TransactionSimulatorResult> maybeSimulatorResult = transactionSimulator.processWithWorldUpdater(callParameter, buildTransactionValidationParams(), tracer, header, worldUpdater);
LOG.trace("Executing {} call for transaction {}", traceTypeParameter, callParameter);
if (maybeSimulatorResult.isEmpty()) {
throw new EmptySimulatorResultException();
}
final TransactionSimulatorResult simulatorResult = maybeSimulatorResult.get();
if (simulatorResult.isInvalid()) {
throw new TransactionInvalidException();
}
final TransactionTrace transactionTrace = new TransactionTrace(simulatorResult.getTransaction(), simulatorResult.getResult(), tracer.getTraceFrames());
final Block block = blockchainQueriesSupplier.get().getBlockchain().getChainHeadBlock();
return getTraceCallResult(protocolSchedule, traceTypes, maybeSimulatorResult, transactionTrace, block);
}
use of org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult in project besu by hyperledger.
the class BlockAdapterBase method executeCall.
private Optional<CallResult> executeCall(final DataFetchingEnvironment environment) {
final Map<String, Object> callData = environment.getArgument("data");
final Address from = (Address) callData.get("from");
final Address to = (Address) callData.get("to");
final Long gas = (Long) callData.get("gas");
final UInt256 gasPrice = (UInt256) callData.get("gasPrice");
final UInt256 value = (UInt256) callData.get("value");
final Bytes data = (Bytes) callData.get("data");
final BlockchainQueries query = getBlockchainQueries(environment);
final ProtocolSchedule protocolSchedule = environment.getGraphQlContext().get(GraphQLContextType.PROTOCOL_SCHEDULE);
final long bn = header.getNumber();
final TransactionSimulator transactionSimulator = new TransactionSimulator(query.getBlockchain(), query.getWorldStateArchive(), protocolSchedule);
long gasParam = -1;
Wei gasPriceParam = null;
Wei valueParam = null;
if (gas != null) {
gasParam = gas;
}
if (gasPrice != null) {
gasPriceParam = Wei.of(gasPrice);
}
if (value != null) {
valueParam = Wei.of(value);
}
final CallParameter param = new CallParameter(from, to, gasParam, gasPriceParam, valueParam, data);
final Optional<TransactionSimulatorResult> opt = transactionSimulator.process(param, TransactionValidationParams.transactionSimulator(), OperationTracer.NO_TRACING, bn);
if (opt.isPresent()) {
final TransactionSimulatorResult result = opt.get();
long status = 0;
if (result.isSuccessful()) {
status = 1;
}
final CallResult callResult = new CallResult(status, result.getGasEstimate(), result.getOutput());
return Optional.of(callResult);
}
return Optional.empty();
}
Aggregations