Search in sources :

Example 1 with TransactionSimulatorResult

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));
}
Also used : TransactionSimulatorResult(org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult) Test(org.junit.Test)

Example 2 with TransactionSimulatorResult

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());
}
Also used : TransactionSimulatorResult(org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult) Test(org.junit.Test)

Example 3 with TransactionSimulatorResult

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");
}
Also used : TransactionSimulatorResult(org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult) Test(org.junit.Test)

Example 4 with TransactionSimulatorResult

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);
}
Also used : TransactionSimulatorResult(org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) Block(org.hyperledger.besu.ethereum.core.Block)

Example 5 with TransactionSimulatorResult

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();
}
Also used : Address(org.hyperledger.besu.datatypes.Address) CallParameter(org.hyperledger.besu.ethereum.transaction.CallParameter) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) Bytes(org.apache.tuweni.bytes.Bytes) TransactionSimulatorResult(org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) Wei(org.hyperledger.besu.datatypes.Wei) TransactionSimulator(org.hyperledger.besu.ethereum.transaction.TransactionSimulator) UInt256(org.apache.tuweni.units.bigints.UInt256)

Aggregations

TransactionSimulatorResult (org.hyperledger.besu.ethereum.transaction.TransactionSimulatorResult)20 Test (org.junit.Test)10 Address (org.hyperledger.besu.datatypes.Address)5 Bytes (org.apache.tuweni.bytes.Bytes)4 CallParameter (org.hyperledger.besu.ethereum.transaction.CallParameter)4 TransactionSimulator (org.hyperledger.besu.ethereum.transaction.TransactionSimulator)4 TransactionTrace (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace)3 Block (org.hyperledger.besu.ethereum.core.Block)3 DebugOperationTracer (org.hyperledger.besu.ethereum.vm.DebugOperationTracer)3 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)2 Optional (java.util.Optional)2 UInt256 (org.apache.tuweni.units.bigints.UInt256)2 Hash (org.hyperledger.besu.crypto.Hash)2 Wei (org.hyperledger.besu.datatypes.Wei)2 TraceTypeParameter (org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TraceTypeParameter)2 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)2 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)2 Transaction (org.hyperledger.besu.ethereum.core.Transaction)2 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)2 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)2