use of org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture in project besu by hyperledger.
the class TraceTransactionIntegrationTest method setUp.
@BeforeEach
public void setUp() {
final ExecutionContextTestFixture contextTestFixture = ExecutionContextTestFixture.create();
genesisBlock = contextTestFixture.getGenesis();
blockchain = contextTestFixture.getBlockchain();
worldStateArchive = contextTestFixture.getStateArchive();
final ProtocolSchedule protocolSchedule = contextTestFixture.getProtocolSchedule();
transactionProcessor = protocolSchedule.getByBlockNumber(0).getTransactionProcessor();
blockHashLookup = new BlockHashLookup(genesisBlock.getHeader(), blockchain);
}
use of org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture in project besu by hyperledger.
the class OperationBenchmarkHelper method create.
public static OperationBenchmarkHelper create() throws IOException {
final Path storageDirectory = Files.createTempDirectory("benchmark");
final KeyValueStorage keyValueStorage = new RocksDBKeyValueStorage(new RocksDBConfigurationBuilder().databaseDir(storageDirectory).build(), new NoOpMetricsSystem(), RocksDBMetricsFactory.PUBLIC_ROCKS_DB_METRICS);
final ExecutionContextTestFixture executionContext = ExecutionContextTestFixture.builder().keyValueStorage(keyValueStorage).build();
final MutableBlockchain blockchain = executionContext.getBlockchain();
for (int i = 1; i < 256; i++) {
blockchain.appendBlock(new Block(new BlockHeaderTestFixture().parentHash(blockchain.getChainHeadHash()).number(i).difficulty(Difficulty.ONE).buildHeader(), new BlockBody(emptyList(), emptyList())), emptyList());
}
final MessageFrame messageFrame = new MessageFrameTestFixture().executionContextTestFixture(executionContext).blockHeader(new BlockHeaderTestFixture().parentHash(blockchain.getChainHeadHash()).number(blockchain.getChainHeadBlockNumber() + 1).difficulty(Difficulty.ONE).buildHeader()).build();
return new OperationBenchmarkHelper(storageDirectory, keyValueStorage, messageFrame, blockchain);
}
use of org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture in project besu by hyperledger.
the class PoWBlockCreatorTest method createMainnetBlock1_fixedDifficulty1.
@Test
public void createMainnetBlock1_fixedDifficulty1() {
final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}").getConfigOptions();
final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(new ProtocolScheduleBuilder(genesisConfigOptions, BigInteger.valueOf(42), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, genesisConfigOptions.isQuorum(), EvmConfiguration.DEFAULT).createProtocolSchedule()).build();
final PoWSolver solver = new PoWSolver(Lists.newArrayList(BLOCK_1_NONCE), PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
final BaseFeePendingTransactionsSorter pendingTransactions = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
final PoWBlockCreator blockCreator = new PoWBlockCreator(BLOCK_1_COINBASE, () -> Optional.empty(), parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, executionContextTestFixture.getProtocolContext(), executionContextTestFixture.getProtocolSchedule(), solver, Wei.ZERO, 0.8, executionContextTestFixture.getBlockchain().getChainHeadHeader());
blockCreator.createBlock(BLOCK_1_TIMESTAMP);
// If we weren't setting difficulty to 2^256-1 a difficulty of 1 would have caused a
// IllegalArgumentException at the previous line, as 2^256 is 33 bytes.
}
use of org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture in project besu by hyperledger.
the class PoWBlockCreatorTest method rewardBeneficiary_zeroReward_skipZeroRewardsTrue.
@Test
public void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() {
final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}").getConfigOptions();
final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(new ProtocolScheduleBuilder(genesisConfigOptions, BigInteger.valueOf(42), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, genesisConfigOptions.isQuorum(), EvmConfiguration.DEFAULT).createProtocolSchedule()).build();
final PoWSolver solver = new PoWSolver(Lists.newArrayList(BLOCK_1_NONCE), PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
final BaseFeePendingTransactionsSorter pendingTransactions = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
final PoWBlockCreator blockCreator = new PoWBlockCreator(BLOCK_1_COINBASE, () -> Optional.of(10_000_000L), parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, executionContextTestFixture.getProtocolContext(), executionContextTestFixture.getProtocolSchedule(), solver, Wei.ZERO, 0.8, executionContextTestFixture.getBlockchain().getChainHeadHeader());
final MutableWorldState mutableWorldState = executionContextTestFixture.getStateArchive().getMutable();
assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNull();
final ProcessableBlockHeader header = BlockHeaderBuilder.create().parentHash(Hash.ZERO).coinbase(BLOCK_1_COINBASE).difficulty(Difficulty.ONE).number(1).gasLimit(1).timestamp(1).buildProcessableBlockHeader();
blockCreator.rewardBeneficiary(mutableWorldState, header, Collections.emptyList(), BLOCK_1_COINBASE, Wei.ZERO, true);
assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNull();
}
use of org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture in project besu by hyperledger.
the class PoWBlockCreatorTest method rewardBeneficiary_zeroReward_skipZeroRewardsFalse.
@Test
public void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() {
final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}").getConfigOptions();
final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(new ProtocolScheduleBuilder(genesisConfigOptions, BigInteger.valueOf(42), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, genesisConfigOptions.isQuorum(), EvmConfiguration.DEFAULT).createProtocolSchedule()).build();
final PoWSolver solver = new PoWSolver(Lists.newArrayList(BLOCK_1_NONCE), PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
final BaseFeePendingTransactionsSorter pendingTransactions = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
final PoWBlockCreator blockCreator = new PoWBlockCreator(BLOCK_1_COINBASE, () -> Optional.of(10_000_000L), parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, executionContextTestFixture.getProtocolContext(), executionContextTestFixture.getProtocolSchedule(), solver, Wei.ZERO, 0.8, executionContextTestFixture.getBlockchain().getChainHeadHeader());
final MutableWorldState mutableWorldState = executionContextTestFixture.getStateArchive().getMutable();
assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNull();
final ProcessableBlockHeader header = BlockHeaderBuilder.create().parentHash(Hash.ZERO).coinbase(BLOCK_1_COINBASE).difficulty(Difficulty.ONE).number(1).gasLimit(1).timestamp(1).buildProcessableBlockHeader();
blockCreator.rewardBeneficiary(mutableWorldState, header, Collections.emptyList(), BLOCK_1_COINBASE, Wei.ZERO, false);
assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNotNull();
assertThat(mutableWorldState.get(BLOCK_1_COINBASE).getBalance()).isEqualTo(Wei.ZERO);
}
Aggregations