Search in sources :

Example 21 with MessageFrame

use of org.hyperledger.besu.evm.frame.MessageFrame in project besu by hyperledger.

the class EstimateGasOperationTracerTest method shouldDetectChangeInDepthDuringExecution.

@Test
public void shouldDetectChangeInDepthDuringExecution() {
    final ExecuteOperation noExecutionOperation = mock(ExecuteOperation.class);
    assertThat(operationTracer.getMaxDepth()).isEqualTo(0);
    final MessageFrame firstFrame = messageFrameTestFixture.depth(0).build();
    operationTracer.traceExecution(firstFrame, noExecutionOperation);
    assertThat(operationTracer.getMaxDepth()).isEqualTo(0);
    final MessageFrame secondFrame = messageFrameTestFixture.depth(1).build();
    operationTracer.traceExecution(secondFrame, noExecutionOperation);
    assertThat(operationTracer.getMaxDepth()).isEqualTo(1);
    final MessageFrame thirdFrame = messageFrameTestFixture.depth(1).build();
    operationTracer.traceExecution(thirdFrame, noExecutionOperation);
    assertThat(operationTracer.getMaxDepth()).isEqualTo(1);
    final MessageFrame fourthFrame = messageFrameTestFixture.depth(2).build();
    operationTracer.traceExecution(fourthFrame, noExecutionOperation);
    assertThat(operationTracer.getMaxDepth()).isEqualTo(2);
    final MessageFrame fifthFrame = messageFrameTestFixture.depth(0).build();
    operationTracer.traceExecution(fifthFrame, noExecutionOperation);
    assertThat(operationTracer.getMaxDepth()).isEqualTo(2);
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) ExecuteOperation(org.hyperledger.besu.evm.tracing.OperationTracer.ExecuteOperation) Test(org.junit.Test)

Example 22 with MessageFrame

use of org.hyperledger.besu.evm.frame.MessageFrame in project besu by hyperledger.

the class BaseFeeOperationTest method shouldReturnGasCost.

@Test
public void shouldReturnGasCost() {
    final MessageFrame frame = createMessageFrame(100, Optional.of(Wei.of(5L)));
    final Operation operation = new BaseFeeOperation(gasCalculator);
    final OperationResult result = operation.execute(frame, null);
    assertThat(result.getGasCost().isPresent()).isTrue();
    assertThat(result.getGasCost().getAsLong()).isEqualTo(gasCalculator.getBaseTierGasCost());
    assertSuccessResult(result);
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) BaseFeeOperation(org.hyperledger.besu.evm.operation.BaseFeeOperation) OperationResult(org.hyperledger.besu.evm.operation.Operation.OperationResult) Operation(org.hyperledger.besu.evm.operation.Operation) BaseFeeOperation(org.hyperledger.besu.evm.operation.BaseFeeOperation) Test(org.junit.Test)

Example 23 with MessageFrame

use of org.hyperledger.besu.evm.frame.MessageFrame in project besu by hyperledger.

the class BaseFeeOperationTest method createMessageFrame.

private MessageFrame createMessageFrame(final long initialGas, final Optional<Wei> baseFee) {
    final MessageFrame frame = mock(MessageFrame.class);
    when(frame.getRemainingGas()).thenReturn(initialGas);
    final BlockHeader blockHeader = mock(BlockHeader.class);
    when(blockHeader.getBaseFee()).thenReturn(baseFee);
    when(frame.getBlockValues()).thenReturn(blockHeader);
    return frame;
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Example 24 with MessageFrame

use of org.hyperledger.besu.evm.frame.MessageFrame in project besu by hyperledger.

the class BaseFeeOperationTest method shouldHaltIfNoBaseFeeInBlockHeader.

@Test
public void shouldHaltIfNoBaseFeeInBlockHeader() {
    final MessageFrame frame = createMessageFrame(100, Optional.empty());
    final Operation operation = new BaseFeeOperation(gasCalculator);
    final OperationResult result = operation.execute(frame, null);
    assertExceptionalHalt(result, ExceptionalHaltReason.INVALID_OPERATION);
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) BaseFeeOperation(org.hyperledger.besu.evm.operation.BaseFeeOperation) OperationResult(org.hyperledger.besu.evm.operation.Operation.OperationResult) Operation(org.hyperledger.besu.evm.operation.Operation) BaseFeeOperation(org.hyperledger.besu.evm.operation.BaseFeeOperation) Test(org.junit.Test)

Example 25 with MessageFrame

use of org.hyperledger.besu.evm.frame.MessageFrame in project besu by hyperledger.

the class ConstantinopleSStoreOperationGasCostTest method shouldCalculateGasAccordingToEip1283.

@Test
public void shouldCalculateGasAccordingToEip1283() {
    final long gasLimit = 1_000_000;
    final MessageFrame frame = codeExecutor.executeCode(code, gasLimit, account -> account.setStorageValue(UInt256.ZERO, UInt256.valueOf(originalValue)));
    assertThat(frame.getState()).isEqualTo(State.COMPLETED_SUCCESS);
    assertThat(frame.getRemainingGas()).isEqualTo(gasLimit - expectedGasUsed);
    assertThat(frame.getGasRefund()).isEqualTo(expectedGasRefund);
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Test(org.junit.Test)

Aggregations

MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)73 Test (org.junit.Test)39 Bytes (org.apache.tuweni.bytes.Bytes)28 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)15 ArrayDeque (java.util.ArrayDeque)13 Wei (org.hyperledger.besu.datatypes.Wei)12 Code (org.hyperledger.besu.evm.Code)12 MessageFrameTestFixture (org.hyperledger.besu.ethereum.core.MessageFrameTestFixture)11 OperationResult (org.hyperledger.besu.evm.operation.Operation.OperationResult)11 UInt256 (org.apache.tuweni.units.bigints.UInt256)10 Address (org.hyperledger.besu.datatypes.Address)10 EVM (org.hyperledger.besu.evm.EVM)10 TraceFrame (org.hyperledger.besu.ethereum.debug.TraceFrame)9 Bytes32 (org.apache.tuweni.bytes.Bytes32)8 ContractCreationProcessor (org.hyperledger.besu.evm.processor.ContractCreationProcessor)8 BlockHashLookup (org.hyperledger.besu.ethereum.vm.BlockHashLookup)7 MutableAccount (org.hyperledger.besu.evm.account.MutableAccount)7 Hash (org.hyperledger.besu.datatypes.Hash)6 Block (org.hyperledger.besu.ethereum.core.Block)6 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)6