Search in sources :

Example 6 with MessageFrame

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

the class SStoreOperationTest method createMessageFrame.

private MessageFrame createMessageFrame(final Address address, final Gas initialGas, final Gas remainingGas) {
    final Blockchain blockchain = mock(Blockchain.class);
    final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive();
    final WorldUpdater worldStateUpdater = worldStateArchive.getMutable().updater();
    final BlockHeader blockHeader = new BlockHeaderTestFixture().buildHeader();
    final MessageFrame frame = new MessageFrameTestFixture().address(address).worldUpdater(worldStateUpdater).blockHeader(blockHeader).blockchain(blockchain).initialGas(initialGas).build();
    worldStateUpdater.getOrCreate(address).getMutable().setBalance(Wei.of(1));
    worldStateUpdater.commit();
    frame.setGasRemaining(remainingGas);
    return frame;
}
Also used : BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) MessageFrameTestFixture(org.hyperledger.besu.ethereum.core.MessageFrameTestFixture) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Example 7 with MessageFrame

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

the class FlexiblePrivacyPrecompiledContractTest method setUp.

@Before
public void setUp() {
    final MutableWorldState mutableWorldState = mock(MutableWorldState.class);
    when(mutableWorldState.updater()).thenReturn(mock(WorldUpdater.class));
    when(worldStateArchive.getMutable()).thenReturn(mutableWorldState);
    when(worldStateArchive.getMutable(any(), any())).thenReturn(Optional.of(mutableWorldState));
    final PrivateStateStorage.Updater storageUpdater = mock(PrivateStateStorage.Updater.class);
    when(privateStateStorage.getPrivacyGroupHeadBlockMap(any())).thenReturn(Optional.of(PrivacyGroupHeadBlockMap.empty()));
    when(privateStateStorage.getPrivateBlockMetadata(any(), any())).thenReturn(Optional.empty());
    when(storageUpdater.putPrivateBlockMetadata(nullable(Bytes32.class), nullable(Bytes32.class), any())).thenReturn(storageUpdater);
    when(storageUpdater.putPrivacyGroupHeadBlockMap(nullable(Bytes32.class), any())).thenReturn(storageUpdater);
    when(storageUpdater.putTransactionReceipt(nullable(Bytes32.class), nullable(Bytes32.class), any())).thenReturn(storageUpdater);
    when(privateStateStorage.updater()).thenReturn(storageUpdater);
    messageFrame = mock(MessageFrame.class);
    final BlockDataGenerator blockGenerator = new BlockDataGenerator();
    final Block genesis = blockGenerator.genesisBlock();
    final Block block = blockGenerator.block(new BlockDataGenerator.BlockOptions().setParentHash(genesis.getHeader().getHash()));
    when(messageFrame.getBlockValues()).thenReturn(block.getHeader());
    final PrivateMetadataUpdater privateMetadataUpdater = mock(PrivateMetadataUpdater.class);
    final PrivacyGroupHeadBlockMap privacyGroupHeadBlockMap = mock(PrivacyGroupHeadBlockMap.class);
    when(messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(privateMetadataUpdater);
    when(messageFrame.hasContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(true);
    when(messageFrame.getContextVariable(KEY_IS_PERSISTING_PRIVATE_STATE, false)).thenReturn(false);
    when(privateMetadataUpdater.getPrivacyGroupHeadBlockMap()).thenReturn(privacyGroupHeadBlockMap);
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Block(org.hyperledger.besu.ethereum.core.Block) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) Bytes32(org.apache.tuweni.bytes.Bytes32) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Before(org.junit.Before)

Example 8 with MessageFrame

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

the class PrivacyPrecompiledContractTest method testSimulatedPublicTransactionIsSkipped.

@Test
public void testSimulatedPublicTransactionIsSkipped() {
    final PrivacyPrecompiledContract emptyContract = new PrivacyPrecompiledContract(null, null, null, null, null, null);
    // A simulated public transaction doesn't contain a PrivateMetadataUpdater
    final MessageFrame frame = mock(MessageFrame.class);
    when(frame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(null);
    final PrecompiledContract.PrecompileContractResult result = emptyContract.computePrecompile(null, frame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.EMPTY);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Test(org.junit.Test)

Example 9 with MessageFrame

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

the class MainnetContractCreationProcessorTest method shouldNotThrowAnExceptionWhenCodeSizeRuleNotAdded.

@Test
public void shouldNotThrowAnExceptionWhenCodeSizeRuleNotAdded() {
    processor = new ContractCreationProcessor(gasCalculator, evm, true, Collections.emptyList(), 1, Collections.emptyList());
    final Bytes contractCode = Bytes.fromHexString("00".repeat(24 * 1024 + 1));
    final MessageFrame messageFrame = new MessageFrameTestFixture().build();
    messageFrame.setOutputData(contractCode);
    messageFrame.setGasRemaining(100L);
    when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L);
    processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING);
    assertThat(messageFrame.getState()).isEqualTo(COMPLETED_SUCCESS);
}
Also used : ContractCreationProcessor(org.hyperledger.besu.evm.processor.ContractCreationProcessor) Bytes(org.apache.tuweni.bytes.Bytes) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) MessageFrameTestFixture(org.hyperledger.besu.ethereum.core.MessageFrameTestFixture) Test(org.junit.Test)

Example 10 with MessageFrame

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

the class PrivacyPrecompiledContractIntegrationTest method testSendAndReceive.

@Test
public void testSendAndReceive() {
    final List<String> publicKeys = testHarness.getPublicKeys();
    final PrivateTransaction privateTransaction = PrivateTransactionDataFixture.privateContractDeploymentTransactionBesu(publicKeys.get(0));
    final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput();
    privateTransaction.writeTo(bytesValueRLPOutput);
    final String s = bytesValueRLPOutput.encoded().toBase64String();
    final SendResponse sr = enclave.send(s, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
    final PrivacyPrecompiledContract privacyPrecompiledContract = new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), enclave, worldStateArchive, new PrivateStateRootResolver(privateStateStorage), new PrivateStateGenesisAllocator(false, (privacyGroupId, blockNumber) -> Collections::emptyList), "IntegrationTest");
    privacyPrecompiledContract.setPrivateTransactionProcessor(mockPrivateTxProcessor());
    final PrecompiledContract.PrecompileContractResult result = privacyPrecompiledContract.computePrecompile(Bytes.fromBase64String(sr.getKey()), messageFrame);
    final Bytes actual = result.getOutput();
    assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
Also used : PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) EnclaveKeyConfiguration(org.hyperledger.enclave.testutil.EnclaveKeyConfiguration) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PrivateTransaction(org.hyperledger.besu.ethereum.privacy.PrivateTransaction) OperationTracer(org.hyperledger.besu.evm.tracing.OperationTracer) AfterAll(org.junit.jupiter.api.AfterAll) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator) BeforeAll(org.junit.jupiter.api.BeforeAll) Enclave(org.hyperledger.besu.enclave.Enclave) Block(org.hyperledger.besu.ethereum.core.Block) Path(java.nio.file.Path) Bytes32(org.apache.tuweni.bytes.Bytes32) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) TesseraTestHarness(org.hyperledger.enclave.testutil.TesseraTestHarness) Test(org.junit.jupiter.api.Test) List(java.util.List) PrivateStateGenesisAllocator(org.hyperledger.besu.ethereum.privacy.PrivateStateGenesisAllocator) TempDir(org.junit.jupiter.api.io.TempDir) PrivateTransactionDataFixture(org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture) Optional(java.util.Optional) Mockito.mock(org.mockito.Mockito.mock) Hash(org.hyperledger.besu.datatypes.Hash) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Bytes(org.apache.tuweni.bytes.Bytes) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Address(org.hyperledger.besu.datatypes.Address) SendResponse(org.hyperledger.besu.enclave.types.SendResponse) EnclaveFactory(org.hyperledger.besu.enclave.EnclaveFactory) Lists(com.google.common.collect.Lists) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) TesseraTestHarnessFactory(org.hyperledger.enclave.testutil.TesseraTestHarnessFactory) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) Files(java.nio.file.Files) Vertx(io.vertx.core.Vertx) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) PrivateStateStorage(org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) Mockito.when(org.mockito.Mockito.when) BlockHashLookup(org.hyperledger.besu.ethereum.vm.BlockHashLookup) PrivateTransactionProcessor(org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) PrivateStateUtils(org.hyperledger.besu.ethereum.mainnet.PrivateStateUtils) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) PrivacyGroupHeadBlockMap(org.hyperledger.besu.ethereum.privacy.storage.PrivacyGroupHeadBlockMap) Collections(java.util.Collections) PrecompiledContract(org.hyperledger.besu.evm.precompile.PrecompiledContract) SendResponse(org.hyperledger.besu.enclave.types.SendResponse) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) Bytes(org.apache.tuweni.bytes.Bytes) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) PrivateStateGenesisAllocator(org.hyperledger.besu.ethereum.privacy.PrivateStateGenesisAllocator) PrivateStateRootResolver(org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver) Test(org.junit.jupiter.api.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