Fix and restore disabled block creation unit tests (#7331)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
pull/7312/head
Fabio Di Fabio 4 months ago committed by GitHub
parent 782553eb03
commit 465fd1cbe5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 69
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockCreatorTest.java
  2. 4
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LegacyFeeMarketBlockTransactionSelectorTest.java
  3. 94
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java
  4. 34
      ethereum/blockcreation/src/test/resources/block-creation-fixed-difficulty-genesis.json
  5. 32
      ethereum/blockcreation/src/test/resources/block-creation-genesis.json
  6. 5
      ethereum/core/src/integration-test/java/org/hyperledger/besu/ethereum/vm/TraceTransactionIntegrationTest.java
  7. 13
      ethereum/core/src/integration-test/resources/genesis-it.json
  8. 5
      ethereum/core/src/jmh/java/org/hyperledger/besu/ethereum/vm/operations/OperationBenchmarkHelper.java
  9. 13
      ethereum/core/src/jmh/resources/genesis-jmh.json
  10. 18
      ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java
  11. 9
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java
  12. 15
      ethereum/eth/src/test/resources/txpool-test-genesis.json

@ -26,8 +26,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SECPPrivateKey;
import org.hyperledger.besu.crypto.SignatureAlgorithm;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.BLSPublicKey;
@ -73,13 +74,18 @@ import org.hyperledger.besu.ethereum.mainnet.BodyValidation;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams;
import org.hyperledger.besu.ethereum.mainnet.TransactionValidator;
import org.hyperledger.besu.ethereum.mainnet.TransactionValidatorFactory;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
import org.hyperledger.besu.ethereum.mainnet.WithdrawalsProcessor;
import org.hyperledger.besu.ethereum.mainnet.feemarket.CancunFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.requests.DepositRequestProcessor;
import org.hyperledger.besu.ethereum.mainnet.requests.DepositRequestValidator;
import org.hyperledger.besu.ethereum.mainnet.requests.ProcessRequestContext;
import org.hyperledger.besu.ethereum.mainnet.requests.RequestProcessorCoordinator;
import org.hyperledger.besu.ethereum.mainnet.requests.RequestsValidatorCoordinator;
import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason;
import org.hyperledger.besu.evm.account.Account;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.evm.log.Log;
import org.hyperledger.besu.evm.log.LogTopic;
@ -89,13 +95,13 @@ import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import java.math.BigInteger;
import java.time.Clock;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt64;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@ -103,6 +109,17 @@ import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
abstract class AbstractBlockCreatorTest {
private static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM =
Suppliers.memoize(SignatureAlgorithmFactory::getInstance);
private static final SECPPrivateKey PRIVATE_KEY1 =
SIGNATURE_ALGORITHM
.get()
.createPrivateKey(
Bytes32.fromHexString(
"8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"));
private static final KeyPair KEYS1 =
new KeyPair(PRIVATE_KEY1, SIGNATURE_ALGORITHM.get().createPublicKey(PRIVATE_KEY1));
@Mock private WithdrawalsProcessor withdrawalsProcessor;
protected EthScheduler ethScheduler = new DeterministicEthScheduler();
@ -301,10 +318,8 @@ abstract class AbstractBlockCreatorTest {
assertThat(blockCreationResult.getBlock().getBody().getWithdrawals()).isEmpty();
}
@Disabled
@Test
public void computesGasUsageFromIncludedTransactions() {
final KeyPair senderKeys = SignatureAlgorithmFactory.getInstance().generateKeyPair();
final AbstractBlockCreator blockCreator = blockCreatorWithBlobGasSupport();
BlobTestFixture blobTestFixture = new BlobTestFixture();
BlobsWithCommitments bwc = blobTestFixture.createBlobsWithCommitments(6);
@ -313,13 +328,14 @@ abstract class AbstractBlockCreatorTest {
ttf.to(Optional.of(Address.ZERO))
.type(TransactionType.BLOB)
.chainId(Optional.of(BigInteger.valueOf(42)))
.gasLimit(21000)
.maxFeePerGas(Optional.of(Wei.of(15)))
.maxFeePerBlobGas(Optional.of(Wei.of(128)))
.maxPriorityFeePerGas(Optional.of(Wei.of(1)))
.versionedHashes(Optional.of(bwc.getVersionedHashes()))
.createTransaction(senderKeys);
.blobsWithCommitments(Optional.of(bwc))
.createTransaction(KEYS1);
ttf.blobsWithCommitments(Optional.of(bwc));
final BlockCreationResult blockCreationResult =
blockCreator.createBlock(
Optional.of(List.of(fullOfBlobs)),
@ -336,13 +352,17 @@ abstract class AbstractBlockCreatorTest {
}
private AbstractBlockCreator blockCreatorWithBlobGasSupport() {
final var alwaysValidTransactionValidatorFactory = mock(TransactionValidatorFactory.class);
when(alwaysValidTransactionValidatorFactory.get())
.thenReturn(new AlwaysValidTransactionValidator());
final ProtocolSpecAdapters protocolSpecAdapters =
ProtocolSpecAdapters.create(
0,
specBuilder -> {
specBuilder.feeMarket(new CancunFeeMarket(0, Optional.empty()));
specBuilder.isReplayProtectionSupported(true);
specBuilder.withdrawalsProcessor(withdrawalsProcessor);
specBuilder.transactionValidatorFactoryBuilder(
(evm, gasLimitCalculator, feeMarket) -> alwaysValidTransactionValidatorFactory);
return specBuilder;
});
return createBlockCreator(protocolSpecAdapters);
@ -356,16 +376,19 @@ abstract class AbstractBlockCreatorTest {
}
private AbstractBlockCreator blockCreatorWithoutWithdrawalsProcessor() {
return createBlockCreator(new ProtocolSpecAdapters(Map.of()));
final ProtocolSpecAdapters protocolSpecAdapters =
ProtocolSpecAdapters.create(0, specBuilder -> specBuilder.withdrawalsProcessor(null));
return createBlockCreator(protocolSpecAdapters);
}
private AbstractBlockCreator createBlockCreator(final ProtocolSpecAdapters protocolSpecAdapters) {
final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.DEFAULT.getConfigOptions();
final var genesisConfigFile = GenesisConfigFile.fromResource("/block-creation-genesis.json");
final ExecutionContextTestFixture executionContextTestFixture =
ExecutionContextTestFixture.builder()
ExecutionContextTestFixture.builder(genesisConfigFile)
.protocolSchedule(
new ProtocolScheduleBuilder(
genesisConfigOptions,
genesisConfigFile.getConfigOptions(),
BigInteger.valueOf(42),
protocolSpecAdapters,
PrivacyParameters.DEFAULT,
@ -452,4 +475,24 @@ abstract class AbstractBlockCreatorTest {
.buildBlockHeader();
}
}
static class AlwaysValidTransactionValidator implements TransactionValidator {
@Override
public ValidationResult<TransactionInvalidReason> validate(
final Transaction transaction,
final Optional<Wei> baseFee,
final Optional<Wei> blobBaseFee,
final TransactionValidationParams transactionValidationParams) {
return ValidationResult.valid();
}
@Override
public ValidationResult<TransactionInvalidReason> validateForSender(
final Transaction transaction,
final Account sender,
final TransactionValidationParams validationParams) {
return ValidationResult.valid();
}
}
}

@ -42,10 +42,6 @@ import org.hyperledger.besu.util.number.Fraction;
import java.time.ZoneId;
import java.util.function.Function;
import org.junit.jupiter.api.Disabled;
@Disabled(
"disabled since it's flaky with a timeout see https://github.com/hyperledger/besu/issues/6850")
public class LegacyFeeMarketBlockTransactionSelectorTest
extends AbstractBlockTransactionSelectorTest {

@ -21,7 +21,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
@ -38,6 +37,7 @@ import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyCalculators;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionBroadcaster;
@ -75,6 +75,7 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest {
private static final long BLOCK_1_TIMESTAMP = Long.parseUnsignedLong("55ba4224", 16);
private static final long BLOCK_1_NONCE = Long.parseLong("539bd4979fef1ec4", 16);
private static final long FIXED_DIFFICULTY_NONCE = 26;
private static final Bytes BLOCK_1_EXTRA_DATA =
Bytes.fromHexString("0x476574682f76312e302e302f6c696e75782f676f312e342e32");
@ -82,24 +83,25 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest {
@Test
void createMainnetBlock1() throws IOException {
final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.DEFAULT.getConfigOptions();
final var genesisConfigFile = GenesisConfigFile.mainnet();
final MiningParameters miningParameters = createMiningParameters(BLOCK_1_NONCE);
final ExecutionContextTestFixture executionContextTestFixture =
ExecutionContextTestFixture.builder()
ExecutionContextTestFixture.builder(genesisConfigFile)
.protocolSchedule(
new ProtocolScheduleBuilder(
genesisConfigOptions,
genesisConfigFile.getConfigOptions(),
BigInteger.valueOf(42),
ProtocolSpecAdapters.create(0, Function.identity()),
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
miningParameters,
new BadBlockManager())
.createProtocolSchedule())
.build();
final MiningParameters miningParameters = createMiningParameters();
final PoWSolver solver =
new PoWSolver(
miningParameters,
@ -136,26 +138,31 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest {
@Test
void createMainnetBlock1_fixedDifficulty1() {
final GenesisConfigOptions genesisConfigOptions =
GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}")
.getConfigOptions();
final var genesisConfigFile =
GenesisConfigFile.fromResource("/block-creation-fixed-difficulty-genesis.json");
final MiningParameters miningParameters = createMiningParameters(FIXED_DIFFICULTY_NONCE);
final ExecutionContextTestFixture executionContextTestFixture =
ExecutionContextTestFixture.builder()
ExecutionContextTestFixture.builder(genesisConfigFile)
.protocolSchedule(
new ProtocolScheduleBuilder(
genesisConfigOptions,
genesisConfigFile.getConfigOptions(),
BigInteger.valueOf(42),
ProtocolSpecAdapters.create(0, Function.identity()),
ProtocolSpecAdapters.create(
0,
specBuilder ->
specBuilder.difficultyCalculator(
FixedDifficultyCalculators.calculator(
genesisConfigFile.getConfigOptions()))),
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
miningParameters,
new BadBlockManager())
.createProtocolSchedule())
.build();
final MiningParameters miningParameters = createMiningParameters();
final PoWSolver solver =
new PoWSolver(
miningParameters,
@ -184,24 +191,31 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest {
@Test
void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() {
final GenesisConfigOptions genesisConfigOptions =
GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}")
.getConfigOptions();
final var genesisConfigFile =
GenesisConfigFile.fromResource("/block-creation-fixed-difficulty-genesis.json");
final MiningParameters miningParameters = createMiningParameters(FIXED_DIFFICULTY_NONCE);
ProtocolSchedule protocolSchedule =
new ProtocolScheduleBuilder(
genesisConfigOptions,
genesisConfigFile.getConfigOptions(),
BigInteger.valueOf(42),
ProtocolSpecAdapters.create(0, Function.identity()),
ProtocolSpecAdapters.create(
0,
specBuilder ->
specBuilder.difficultyCalculator(
FixedDifficultyCalculators.calculator(
genesisConfigFile.getConfigOptions()))),
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
miningParameters,
new BadBlockManager())
.createProtocolSchedule();
final ExecutionContextTestFixture executionContextTestFixture =
ExecutionContextTestFixture.builder().protocolSchedule(protocolSchedule).build();
final MiningParameters miningParameters = createMiningParameters();
ExecutionContextTestFixture.builder(genesisConfigFile)
.protocolSchedule(protocolSchedule)
.build();
final PoWSolver solver =
new PoWSolver(
@ -253,24 +267,31 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest {
@Test
void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() {
final GenesisConfigOptions genesisConfigOptions =
GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}")
.getConfigOptions();
final var genesisConfigFile =
GenesisConfigFile.fromResource("/block-creation-fixed-difficulty-genesis.json");
final MiningParameters miningParameters = createMiningParameters(FIXED_DIFFICULTY_NONCE);
ProtocolSchedule protocolSchedule =
new ProtocolScheduleBuilder(
genesisConfigOptions,
genesisConfigFile.getConfigOptions(),
BigInteger.valueOf(42),
ProtocolSpecAdapters.create(0, Function.identity()),
ProtocolSpecAdapters.create(
0,
specBuilder ->
specBuilder.difficultyCalculator(
FixedDifficultyCalculators.calculator(
genesisConfigFile.getConfigOptions()))),
PrivacyParameters.DEFAULT,
false,
EvmConfiguration.DEFAULT,
MiningParameters.MINING_DISABLED,
miningParameters,
new BadBlockManager())
.createProtocolSchedule();
final ExecutionContextTestFixture executionContextTestFixture =
ExecutionContextTestFixture.builder().protocolSchedule(protocolSchedule).build();
final MiningParameters miningParameters = createMiningParameters();
ExecutionContextTestFixture.builder(genesisConfigFile)
.protocolSchedule(protocolSchedule)
.build();
final PoWSolver solver =
new PoWSolver(
@ -348,11 +369,12 @@ class PoWBlockCreatorTest extends AbstractBlockCreatorTest {
return transactionPool;
}
private MiningParameters createMiningParameters() {
private MiningParameters createMiningParameters(final long nonce) {
return ImmutableMiningParameters.builder()
.mutableInitValues(
MutableInitValues.builder()
.nonceGenerator(Lists.newArrayList(BLOCK_1_NONCE))
.nonceGenerator(Lists.newArrayList(nonce))
// .nonceGenerator(new IncrementingNonceGenerator(0))
.extraData(BLOCK_1_EXTRA_DATA)
.minTransactionGasPrice(Wei.ONE)
.coinbase(BLOCK_1_COINBASE)

@ -0,0 +1,34 @@
{
"config": {
"chainId": 42,
"frontierBlock": 0,
"ethash": {
"fixeddifficulty":10
}
},
"nonce": "0x42",
"timestamp": "0x0",
"extraData": "",
"gasLimit": "0x1fffffffffffff",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"baseFeePerGas": "0x7",
"alloc": {
"fe3b557e8fb62b89f4916b721be55ceb828dbd73": {
"privateKey": "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored",
"balance": "0xad78ebc5ac6200000"
},
"627306090abaB3A6e1400e9345bC60c78a8BEf57": {
"privateKey": "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored",
"balance": "90000000000000000000000"
},
"f17f52151EbEF6C7334FAD080c5704D77216b732": {
"privateKey": "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored",
"balance": "90000000000000000000000"
}
}
}

@ -0,0 +1,32 @@
{
"config": {
"chainId": 42,
"cancunTime": 0,
"terminalTotalDifficulty": 0
},
"nonce": "0x42",
"timestamp": "0x0",
"extraData": "",
"gasLimit": "0x1fffffffffffff",
"difficulty": "0x10000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"baseFeePerGas": "0x7",
"alloc": {
"fe3b557e8fb62b89f4916b721be55ceb828dbd73": {
"privateKey": "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored",
"balance": "0xad78ebc5ac6200000"
},
"627306090abaB3A6e1400e9345bC60c78a8BEf57": {
"privateKey": "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored",
"balance": "90000000000000000000000"
},
"f17f52151EbEF6C7334FAD080c5704D77216b732": {
"privateKey": "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
"comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored",
"balance": "90000000000000000000000"
}
}
}

@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.hyperledger.besu.evm.operation.BlockHashOperation.BlockHashLookup;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.TransactionType;
@ -68,7 +69,9 @@ public class TraceTransactionIntegrationTest {
@BeforeEach
public void setUp() {
final ExecutionContextTestFixture contextTestFixture = ExecutionContextTestFixture.create();
final ExecutionContextTestFixture contextTestFixture =
ExecutionContextTestFixture.builder(GenesisConfigFile.fromResource("/genesis-it.json"))
.build();
genesisBlock = contextTestFixture.getGenesis();
blockchain = contextTestFixture.getBlockchain();
worldStateArchive = contextTestFixture.getStateArchive();

@ -0,0 +1,13 @@
{
"config": {
"petersburgBlock": 0
},
"coinbase": "0x0000000000000000000000000000000000000000",
"difficulty": "0x0000001",
"extraData": "",
"gasLimit": "0x2fefd8",
"nonce": "0x0000000000000107",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x00"
}

@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.vm.operations;
import static java.util.Collections.emptyList;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -74,7 +75,9 @@ public class OperationBenchmarkHelper {
KeyValueSegmentIdentifier.BLOCKCHAIN, optimisticRocksDBColumnarKeyValueStorage);
final ExecutionContextTestFixture executionContext =
ExecutionContextTestFixture.builder().blockchainKeyValueStorage(keyValueStorage).build();
ExecutionContextTestFixture.builder(GenesisConfigFile.fromResource("/genesis-jmh.json"))
.blockchainKeyValueStorage(keyValueStorage)
.build();
final MutableBlockchain blockchain = executionContext.getBlockchain();
for (int i = 1; i < 256; i++) {

@ -0,0 +1,13 @@
{
"config": {
"petersburgBlock": 0
},
"coinbase": "0x0000000000000000000000000000000000000000",
"difficulty": "0x0000001",
"extraData": "",
"gasLimit": "0x2fefd8",
"nonce": "0x0000000000000107",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x00"
}

@ -17,7 +17,6 @@ package org.hyperledger.besu.ethereum.core;
import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.chain.DefaultBlockchain;
@ -48,9 +47,9 @@ public class ExecutionContextTestFixture {
private final ProtocolSchedule protocolSchedule;
private final ProtocolContext protocolContext;
private static final GenesisConfigFile genesisConfigFile = GenesisConfigFile.mainnet();
private ExecutionContextTestFixture(
final GenesisConfigFile genesisConfigFile,
final ProtocolSchedule protocolSchedule,
final KeyValueStorage blockchainKeyValueStorage,
final KeyValueStorage variablesKeyValueStorage) {
@ -76,11 +75,11 @@ public class ExecutionContextTestFixture {
}
public static ExecutionContextTestFixture create() {
return new Builder().build();
return new Builder(GenesisConfigFile.mainnet()).build();
}
public static Builder builder() {
return new Builder();
public static Builder builder(final GenesisConfigFile genesisConfigFile) {
return new Builder(genesisConfigFile);
}
public Block getGenesis() {
@ -112,10 +111,15 @@ public class ExecutionContextTestFixture {
}
public static class Builder {
private final GenesisConfigFile genesisConfigFile;
private KeyValueStorage variablesKeyValueStorage;
private KeyValueStorage blockchainKeyValueStorage;
private ProtocolSchedule protocolSchedule;
public Builder(final GenesisConfigFile genesisConfigFile) {
this.genesisConfigFile = genesisConfigFile;
}
public Builder variablesKeyValueStorage(final KeyValueStorage keyValueStorage) {
this.variablesKeyValueStorage = keyValueStorage;
return this;
@ -135,7 +139,7 @@ public class ExecutionContextTestFixture {
if (protocolSchedule == null) {
protocolSchedule =
new ProtocolScheduleBuilder(
new StubGenesisConfigOptions().petersburgBlock(0),
genesisConfigFile.getConfigOptions(),
BigInteger.valueOf(42),
ProtocolSpecAdapters.create(0, Function.identity()),
new PrivacyParameters(),
@ -152,7 +156,7 @@ public class ExecutionContextTestFixture {
variablesKeyValueStorage = new InMemoryKeyValueStorage();
}
return new ExecutionContextTestFixture(
protocolSchedule, variablesKeyValueStorage, blockchainKeyValueStorage);
genesisConfigFile, protocolSchedule, variablesKeyValueStorage, blockchainKeyValueStorage);
}
}
}

@ -43,7 +43,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.quality.Strictness.LENIENT;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Address;
@ -191,9 +191,10 @@ public abstract class AbstractTransactionPoolTest {
protected abstract ExecutionContextTestFixture createExecutionContextTestFixture();
protected static ExecutionContextTestFixture createExecutionContextTestFixtureBaseFeeMarket() {
final var genesisConfigFile = GenesisConfigFile.fromResource("/txpool-test-genesis.json");
final ProtocolSchedule protocolSchedule =
new ProtocolScheduleBuilder(
new StubGenesisConfigOptions().londonBlock(0L).baseFeePerGas(10L),
genesisConfigFile.getConfigOptions(),
BigInteger.valueOf(1),
ProtocolSpecAdapters.create(0, Function.identity()),
new PrivacyParameters(),
@ -203,7 +204,9 @@ public abstract class AbstractTransactionPoolTest {
new BadBlockManager())
.createProtocolSchedule();
final ExecutionContextTestFixture executionContextTestFixture =
ExecutionContextTestFixture.builder().protocolSchedule(protocolSchedule).build();
ExecutionContextTestFixture.builder(genesisConfigFile)
.protocolSchedule(protocolSchedule)
.build();
final Block block =
new Block(

@ -0,0 +1,15 @@
{
"config": {
"chainId": 1,
"cancunTime": 0,
"terminalTotalDifficulty": 0
},
"nonce": "0x42",
"timestamp": "0x0",
"extraData": "",
"gasLimit": "0x1fffffffffffff",
"difficulty": "0x10000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"baseFeePerGas": "0xA"
}
Loading…
Cancel
Save