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;
}
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);
}
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);
}
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);
}
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));
}
Aggregations