Search in sources :

Example 1 with BlockValues

use of org.hyperledger.besu.evm.frame.BlockValues in project hedera-services by hashgraph.

the class CallEvmTxProcessorTest method assertTransactionSenderAndValue.

@Test
void assertTransactionSenderAndValue() {
    // setup:
    doReturn(Optional.of(receiver.getId().asEvmAddress())).when(transaction).getTo();
    given(worldState.updater()).willReturn(mock(HederaWorldState.Updater.class));
    given(codeCache.getIfPresent(any())).willReturn(new Code());
    given(transaction.getSender()).willReturn(sender.getId().asEvmAddress());
    given(transaction.getValue()).willReturn(Wei.of(1L));
    final MessageFrame.Builder commonInitialFrame = MessageFrame.builder().messageFrameStack(mock(Deque.class)).maxStackSize(MAX_STACK_SIZE).worldUpdater(mock(WorldUpdater.class)).initialGas(mock(Gas.class)).originator(sender.getId().asEvmAddress()).gasPrice(mock(Wei.class)).sender(sender.getId().asEvmAddress()).value(Wei.of(transaction.getValue().getAsBigInteger())).apparentValue(Wei.of(transaction.getValue().getAsBigInteger())).blockValues(mock(BlockValues.class)).depth(0).completer(__ -> {
    }).miningBeneficiary(mock(Address.class)).blockHashLookup(h -> null);
    // when:
    MessageFrame buildMessageFrame = callEvmTxProcessor.buildInitialFrame(commonInitialFrame, worldState.updater(), (Address) transaction.getTo().get(), Bytes.EMPTY);
    // expect:
    assertEquals(transaction.getSender(), buildMessageFrame.getSenderAddress());
    assertEquals(transaction.getValue(), buildMessageFrame.getApparentValue());
}
Also used : WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Gas(org.hyperledger.besu.evm.Gas) BlockValues(org.hyperledger.besu.evm.frame.BlockValues) Wei(org.hyperledger.besu.datatypes.Wei) Code(org.hyperledger.besu.evm.Code) Test(org.junit.jupiter.api.Test)

Example 2 with BlockValues

use of org.hyperledger.besu.evm.frame.BlockValues in project hedera-services by hashgraph.

the class CreateEvmTxProcessorTest method assertTransactionSenderAndValue.

@Test
void assertTransactionSenderAndValue() {
    // setup:
    doReturn(Optional.of(receiver.getId().asEvmAddress())).when(transaction).getTo();
    given(transaction.getSender()).willReturn(sender.getId().asEvmAddress());
    given(transaction.getValue()).willReturn(Wei.of(1L));
    final MessageFrame.Builder commonInitialFrame = MessageFrame.builder().messageFrameStack(mock(Deque.class)).maxStackSize(MAX_STACK_SIZE).worldUpdater(mock(WorldUpdater.class)).initialGas(mock(Gas.class)).originator(sender.getId().asEvmAddress()).gasPrice(mock(Wei.class)).sender(sender.getId().asEvmAddress()).value(Wei.of(transaction.getValue().getAsBigInteger())).apparentValue(Wei.of(transaction.getValue().getAsBigInteger())).blockValues(mock(BlockValues.class)).depth(0).completer(__ -> {
    }).miningBeneficiary(mock(Address.class)).blockHashLookup(h -> null);
    // when:
    MessageFrame buildMessageFrame = createEvmTxProcessor.buildInitialFrame(commonInitialFrame, worldState.updater(), (Address) transaction.getTo().get(), Bytes.EMPTY);
    // expect:
    assertEquals(transaction.getSender(), buildMessageFrame.getSenderAddress());
    assertEquals(transaction.getValue(), buildMessageFrame.getApparentValue());
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Gas(org.hyperledger.besu.evm.Gas) BlockValues(org.hyperledger.besu.evm.frame.BlockValues) Wei(org.hyperledger.besu.datatypes.Wei) Test(org.junit.jupiter.api.Test)

Example 3 with BlockValues

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

the class PrevRanDaoOperationTest method pushesPrevRandaoWhenDifficultyZero.

@Test
public void pushesPrevRandaoWhenDifficultyZero() {
    PrevRanDaoOperation op = new PrevRanDaoOperation(new LondonGasCalculator());
    MessageFrame messageFrame = mock(MessageFrame.class);
    BlockValues blockHeader = mock(BlockValues.class);
    Bytes32 prevRandao = Bytes32.fromHexString("0xb0b0face");
    when(blockHeader.getDifficultyBytes()).thenReturn(UInt256.ZERO);
    when(blockHeader.getMixHashOrPrevRandao()).thenReturn(prevRandao);
    when(messageFrame.getBlockValues()).thenReturn(blockHeader);
    EVM evm = mock(EVM.class);
    Operation.OperationResult r = op.executeFixedCostOperation(messageFrame, evm);
    assertThat(r.getHaltReason()).isNotPresent();
    verify(messageFrame).pushStackItem(prevRandao);
}
Also used : PrevRanDaoOperation(org.hyperledger.besu.evm.operation.PrevRanDaoOperation) LondonGasCalculator(org.hyperledger.besu.evm.gascalculator.LondonGasCalculator) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) BlockValues(org.hyperledger.besu.evm.frame.BlockValues) Operation(org.hyperledger.besu.evm.operation.Operation) PrevRanDaoOperation(org.hyperledger.besu.evm.operation.PrevRanDaoOperation) Bytes32(org.apache.tuweni.bytes.Bytes32) EVM(org.hyperledger.besu.evm.EVM) Test(org.junit.Test)

Example 4 with BlockValues

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

the class PrivacyPrecompiledContract method isMining.

boolean isMining(final MessageFrame messageFrame) {
    boolean isMining = false;
    final BlockValues currentBlockHeader = messageFrame.getBlockValues();
    if (!BlockHeader.class.isAssignableFrom(currentBlockHeader.getClass())) {
        if (messageFrame.getContextVariable(KEY_IS_PERSISTING_PRIVATE_STATE, false)) {
            throw new IllegalArgumentException("The MessageFrame contains an illegal block header type. Cannot persist private block" + " metadata without current block hash.");
        } else {
            isMining = true;
        }
    }
    return isMining;
}
Also used : BlockValues(org.hyperledger.besu.evm.frame.BlockValues) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Example 5 with BlockValues

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

the class PrevRanDaoOperationTest method pushesDifficultyWhenPresent.

@Test
public void pushesDifficultyWhenPresent() {
    PrevRanDaoOperation op = new PrevRanDaoOperation(new LondonGasCalculator());
    MessageFrame messageFrame = mock(MessageFrame.class);
    BlockValues blockHeader = mock(BlockValues.class);
    Bytes32 prevRandao = Bytes32.fromHexString("0xb0b0face");
    Bytes difficulty = Bytes.random(32);
    when(blockHeader.getDifficultyBytes()).thenReturn(difficulty);
    when(blockHeader.getMixHashOrPrevRandao()).thenReturn(prevRandao);
    when(messageFrame.getBlockValues()).thenReturn(blockHeader);
    EVM evm = mock(EVM.class);
    Operation.OperationResult r = op.executeFixedCostOperation(messageFrame, evm);
    assertThat(r.getHaltReason()).isNotPresent();
    verify(messageFrame).pushStackItem(difficulty);
}
Also used : PrevRanDaoOperation(org.hyperledger.besu.evm.operation.PrevRanDaoOperation) Bytes(org.apache.tuweni.bytes.Bytes) LondonGasCalculator(org.hyperledger.besu.evm.gascalculator.LondonGasCalculator) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) BlockValues(org.hyperledger.besu.evm.frame.BlockValues) Operation(org.hyperledger.besu.evm.operation.Operation) PrevRanDaoOperation(org.hyperledger.besu.evm.operation.PrevRanDaoOperation) Bytes32(org.apache.tuweni.bytes.Bytes32) EVM(org.hyperledger.besu.evm.EVM) Test(org.junit.Test)

Aggregations

BlockValues (org.hyperledger.besu.evm.frame.BlockValues)8 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)6 Wei (org.hyperledger.besu.datatypes.Wei)4 Bytes32 (org.apache.tuweni.bytes.Bytes32)3 Code (org.hyperledger.besu.evm.Code)3 EVM (org.hyperledger.besu.evm.EVM)3 Gas (org.hyperledger.besu.evm.Gas)3 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)3 Test (org.junit.jupiter.api.Test)3 Bytes (org.apache.tuweni.bytes.Bytes)2 Hash (org.hyperledger.besu.datatypes.Hash)2 LondonGasCalculator (org.hyperledger.besu.evm.gascalculator.LondonGasCalculator)2 Operation (org.hyperledger.besu.evm.operation.Operation)2 PrevRanDaoOperation (org.hyperledger.besu.evm.operation.PrevRanDaoOperation)2 Test (org.junit.Test)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 ArrayDeque (java.util.ArrayDeque)1 Collection (java.util.Collection)1