getByBlockNumber replaced by getByBlockHeader on tests (#5259)

* Replace getByBlockNumber by getByBlockHeader

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

* Replace getByBlockNumber by getByBlockHeader

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

* Replace BlockDataGenerator by BlockHeaderTestFixture

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

* Replace BlockDataGenerator by BlockHeaderTestFixture

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

* Add final to method param

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

* Replace BlockDataGEnerator by BlockHeaderTestFixture

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

* Replace BlockDataGenerator by BlockHeaderTestFixture

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

* Remove BlockDataGenerator

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

---------

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
pull/5267/head
Gabriel Fukushima 2 years ago committed by GitHub
parent be76759322
commit 0e36f661e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java
  2. 8
      besu/src/test/java/org/hyperledger/besu/PrivacyTest.java
  3. 14
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java
  4. 5
      consensus/common/src/main/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactory.java
  5. 9
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/CombinedProtocolScheduleFactoryTest.java
  6. 19
      consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/BaseBftProtocolScheduleBuilderTest.java
  7. 2
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftProtocolScheduleTest.java
  8. 12
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/MergeProtocolScheduleTest.java
  9. 2
      consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/TransitionProtocolScheduleTest.java
  10. 2
      consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/QbftProtocolScheduleTest.java
  11. 21
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java
  12. 12
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java
  13. 8
      ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java
  14. 7
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/AbstractIsolationTests.java
  15. 16
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java
  16. 129
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolScheduleTest.java
  17. 2
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolScheduleTest.java
  18. 46
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java
  19. 3
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/privacy/storage/migration/PrivateStorageMigrationTest.java
  20. 18
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java
  21. 11
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java
  22. 3
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTest.java
  23. 2
      ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/mainnet/DifficultyCalculatorTests.java

@ -404,7 +404,7 @@ public class PrivacyReorgTest {
final Block block) { final Block block) {
besuController besuController
.getProtocolSchedule() .getProtocolSchedule()
.getByBlockNumber(blockchain.getChainHeadBlockNumber()) .getByBlockHeader(blockchain.getChainHeadHeader())
.getBlockImporter() .getBlockImporter()
.importBlock(protocolContext, block, HeaderValidationMode.NONE); .importBlock(protocolContext, block, HeaderValidationMode.NONE);
} }

@ -29,6 +29,8 @@ import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.enclave.EnclaveFactory; import org.hyperledger.besu.enclave.EnclaveFactory;
import org.hyperledger.besu.ethereum.GasLimitCalculator; import org.hyperledger.besu.ethereum.GasLimitCalculator;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters;
@ -145,8 +147,12 @@ public class PrivacyTest {
final BesuController besuController, final Address defaultPrivacy) { final BesuController besuController, final Address defaultPrivacy) {
return besuController return besuController
.getProtocolSchedule() .getProtocolSchedule()
.getByBlockNumber(1) .getByBlockHeader(blockHeader(0))
.getPrecompileContractRegistry() .getPrecompileContractRegistry()
.get(defaultPrivacy); .get(defaultPrivacy);
} }
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}
} }

@ -57,10 +57,10 @@ public class CliqueProtocolScheduleTest {
final ProtocolSchedule protocolSchedule = final ProtocolSchedule protocolSchedule =
CliqueProtocolSchedule.create(config, NODE_KEY, false, EvmConfiguration.DEFAULT); CliqueProtocolSchedule.create(config, NODE_KEY, false, EvmConfiguration.DEFAULT);
final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockNumber(1); final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockHeader(blockHeader(1));
final ProtocolSpec tangerineWhistleSpec = protocolSchedule.getByBlockNumber(2); final ProtocolSpec tangerineWhistleSpec = protocolSchedule.getByBlockHeader(blockHeader(2));
final ProtocolSpec spuriousDragonSpec = protocolSchedule.getByBlockNumber(3); final ProtocolSpec spuriousDragonSpec = protocolSchedule.getByBlockHeader(blockHeader(3));
final ProtocolSpec byzantiumSpec = protocolSchedule.getByBlockNumber(1035301); final ProtocolSpec byzantiumSpec = protocolSchedule.getByBlockHeader(blockHeader(1035301));
assertThat(homesteadSpec.equals(tangerineWhistleSpec)).isFalse(); assertThat(homesteadSpec.equals(tangerineWhistleSpec)).isFalse();
assertThat(tangerineWhistleSpec.equals(spuriousDragonSpec)).isFalse(); assertThat(tangerineWhistleSpec.equals(spuriousDragonSpec)).isFalse();
@ -75,7 +75,7 @@ public class CliqueProtocolScheduleTest {
NODE_KEY, NODE_KEY,
false, false,
EvmConfiguration.DEFAULT) EvmConfiguration.DEFAULT)
.getByBlockNumber(0); .getByBlockHeader(blockHeader(0));
assertThat(homestead.getName()).isEqualTo("Frontier"); assertThat(homestead.getName()).isEqualTo("Frontier");
assertThat(homestead.getBlockReward()).isEqualTo(Wei.ZERO); assertThat(homestead.getBlockReward()).isEqualTo(Wei.ZERO);
@ -180,4 +180,8 @@ public class CliqueProtocolScheduleTest {
.getBlockHeaderValidator() .getBlockHeaderValidator()
.validateHeader(blockHeader, parentBlockHeader, null, HeaderValidationMode.LIGHT); .validateHeader(blockHeader, parentBlockHeader, null, HeaderValidationMode.LIGHT);
} }
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}
} }

@ -36,10 +36,11 @@ public class CombinedProtocolScheduleFactory {
* @param chainId the chain id * @param chainId the chain id
* @return the protocol schedule * @return the protocol schedule
*/ */
public ProtocolSchedule create( public BftProtocolSchedule create(
final NavigableSet<ForkSpec<ProtocolSchedule>> forkSpecs, final NavigableSet<ForkSpec<ProtocolSchedule>> forkSpecs,
final Optional<BigInteger> chainId) { final Optional<BigInteger> chainId) {
final MutableProtocolSchedule combinedProtocolSchedule = new MutableProtocolSchedule(chainId); final BftProtocolSchedule combinedProtocolSchedule =
new BftProtocolSchedule(new MutableProtocolSchedule(chainId));
for (ForkSpec<ProtocolSchedule> spec : forkSpecs) { for (ForkSpec<ProtocolSchedule> spec : forkSpecs) {
checkState( checkState(
spec.getValue() instanceof MutableProtocolSchedule, spec.getValue() instanceof MutableProtocolSchedule,

@ -20,7 +20,6 @@ import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule; import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters;
@ -58,9 +57,7 @@ public class CombinedProtocolScheduleFactoryTest {
final BlockNumberStreamingProtocolSchedule combinedProtocolSchedule = final BlockNumberStreamingProtocolSchedule combinedProtocolSchedule =
new BlockNumberStreamingProtocolSchedule( new BlockNumberStreamingProtocolSchedule(
(MutableProtocolSchedule) combinedProtocolScheduleFactory.create(consensusSchedule, Optional.of(BigInteger.TEN)));
combinedProtocolScheduleFactory.create(
consensusSchedule, Optional.of(BigInteger.TEN)));
assertThat(combinedProtocolSchedule.getByBlockNumber(0L).getName()).isEqualTo("Frontier"); assertThat(combinedProtocolSchedule.getByBlockNumber(0L).getName()).isEqualTo("Frontier");
assertThat(combinedProtocolSchedule.getByBlockNumber(0L)) assertThat(combinedProtocolSchedule.getByBlockNumber(0L))
@ -101,9 +98,7 @@ public class CombinedProtocolScheduleFactoryTest {
final BlockNumberStreamingProtocolSchedule combinedProtocolSchedule = final BlockNumberStreamingProtocolSchedule combinedProtocolSchedule =
new BlockNumberStreamingProtocolSchedule( new BlockNumberStreamingProtocolSchedule(
(MutableProtocolSchedule) combinedProtocolScheduleFactory.create(consensusSchedule, Optional.of(BigInteger.TEN)));
combinedProtocolScheduleFactory.create(
consensusSchedule, Optional.of(BigInteger.TEN)));
// consensus schedule 1 // consensus schedule 1
assertThat(combinedProtocolSchedule.getByBlockNumber(0L).getName()).isEqualTo("Frontier"); assertThat(combinedProtocolSchedule.getByBlockNumber(0L).getName()).isEqualTo("Frontier");

@ -28,6 +28,7 @@ import org.hyperledger.besu.consensus.common.ForksSchedule;
import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule; import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
@ -60,7 +61,7 @@ public class BaseBftProtocolScheduleBuilderTest {
final ProtocolSchedule schedule = final ProtocolSchedule schedule =
createProtocolSchedule(List.of(new ForkSpec<>(0, configOptions))); createProtocolSchedule(List.of(new ForkSpec<>(0, configOptions)));
final ProtocolSpec spec = schedule.getByBlockNumber(1); final ProtocolSpec spec = schedule.getByBlockHeader(blockHeader(1));
assertThat(spec.getBlockReward()).isEqualTo(Wei.of(arbitraryBlockReward)); assertThat(spec.getBlockReward()).isEqualTo(Wei.of(arbitraryBlockReward));
assertThat(spec.getMiningBeneficiaryCalculator().calculateBeneficiary(mock(BlockHeader.class))) assertThat(spec.getMiningBeneficiaryCalculator().calculateBeneficiary(mock(BlockHeader.class)))
@ -76,7 +77,7 @@ public class BaseBftProtocolScheduleBuilderTest {
final ProtocolSchedule schedule = final ProtocolSchedule schedule =
createProtocolSchedule(List.of(new ForkSpec<>(0, configOptions))); createProtocolSchedule(List.of(new ForkSpec<>(0, configOptions)));
final ProtocolSpec spec = schedule.getByBlockNumber(1); final ProtocolSpec spec = schedule.getByBlockHeader(blockHeader(1));
final Address headerCoinbase = Address.fromHexString("0x123"); final Address headerCoinbase = Address.fromHexString("0x123");
final BlockHeader header = mock(BlockHeader.class); final BlockHeader header = mock(BlockHeader.class);
@ -131,7 +132,7 @@ public class BaseBftProtocolScheduleBuilderTest {
// Check initial config // Check initial config
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
final ProtocolSpec spec = schedule.getByBlockNumber(i); final ProtocolSpec spec = schedule.getByBlockHeader(blockHeader(i));
final Address expectedBeneficiary = initialBeneficiaryIsEmpty ? headerCoinbase : beneficiary1; final Address expectedBeneficiary = initialBeneficiaryIsEmpty ? headerCoinbase : beneficiary1;
assertThat(spec.getBlockReward()).isEqualTo(Wei.of(BigInteger.valueOf(3))); assertThat(spec.getBlockReward()).isEqualTo(Wei.of(BigInteger.valueOf(3)));
assertThat(spec.getMiningBeneficiaryCalculator().calculateBeneficiary(header)) assertThat(spec.getMiningBeneficiaryCalculator().calculateBeneficiary(header))
@ -140,7 +141,7 @@ public class BaseBftProtocolScheduleBuilderTest {
// Check fork1 // Check fork1
for (int i = 2; i < 5; i++) { for (int i = 2; i < 5; i++) {
final ProtocolSpec spec = schedule.getByBlockNumber(i); final ProtocolSpec spec = schedule.getByBlockHeader(blockHeader(i));
final Address expectedBeneficiary = initialBeneficiaryIsEmpty ? beneficiary2 : headerCoinbase; final Address expectedBeneficiary = initialBeneficiaryIsEmpty ? beneficiary2 : headerCoinbase;
assertThat(spec.getBlockReward()).isEqualTo(Wei.of(BigInteger.valueOf(2))); assertThat(spec.getBlockReward()).isEqualTo(Wei.of(BigInteger.valueOf(2)));
assertThat(spec.getMiningBeneficiaryCalculator().calculateBeneficiary(header)) assertThat(spec.getMiningBeneficiaryCalculator().calculateBeneficiary(header))
@ -149,7 +150,7 @@ public class BaseBftProtocolScheduleBuilderTest {
// Check fork2 // Check fork2
for (int i = 5; i < 8; i++) { for (int i = 5; i < 8; i++) {
final ProtocolSpec spec = schedule.getByBlockNumber(i); final ProtocolSpec spec = schedule.getByBlockHeader(blockHeader(i));
final Address expectedBeneficiary = initialBeneficiaryIsEmpty ? headerCoinbase : beneficiary3; final Address expectedBeneficiary = initialBeneficiaryIsEmpty ? headerCoinbase : beneficiary3;
assertThat(spec.getBlockReward()).isEqualTo(Wei.of(BigInteger.valueOf(1))); assertThat(spec.getBlockReward()).isEqualTo(Wei.of(BigInteger.valueOf(1)));
assertThat(spec.getMiningBeneficiaryCalculator().calculateBeneficiary(header)) assertThat(spec.getMiningBeneficiaryCalculator().calculateBeneficiary(header))
@ -219,9 +220,9 @@ public class BaseBftProtocolScheduleBuilderTest {
new ForkSpec<>(transitionBlock, blockRewardTransition)))); new ForkSpec<>(transitionBlock, blockRewardTransition))));
assertThat(schedule.streamMilestoneBlocks().count()).isEqualTo(2); assertThat(schedule.streamMilestoneBlocks().count()).isEqualTo(2);
assertThat(schedule.getByBlockNumber(0).getBlockReward()) assertThat(schedule.getByBlockHeader(blockHeader(0)).getBlockReward())
.isEqualTo(Wei.of(arbitraryBlockReward)); .isEqualTo(Wei.of(arbitraryBlockReward));
assertThat(schedule.getByBlockNumber(transitionBlock).getBlockReward()) assertThat(schedule.getByBlockHeader(blockHeader(transitionBlock)).getBlockReward())
.isEqualTo(Wei.of(forkBlockReward)); .isEqualTo(Wei.of(forkBlockReward));
} }
@ -256,4 +257,8 @@ public class BaseBftProtocolScheduleBuilderTest {
return bftConfig; return bftConfig;
} }
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}
} }

@ -41,7 +41,6 @@ import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.core.Util;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
import org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration;
@ -94,7 +93,6 @@ public class IbftProtocolScheduleTest {
private BlockNumberStreamingProtocolSchedule createProtocolSchedule( private BlockNumberStreamingProtocolSchedule createProtocolSchedule(
final GenesisConfigOptions genesisConfig, final List<ForkSpec<BftConfigOptions>> forks) { final GenesisConfigOptions genesisConfig, final List<ForkSpec<BftConfigOptions>> forks) {
return new BlockNumberStreamingProtocolSchedule( return new BlockNumberStreamingProtocolSchedule(
(MutableProtocolSchedule)
IbftProtocolScheduleBuilder.create( IbftProtocolScheduleBuilder.create(
genesisConfig, genesisConfig,
new ForksSchedule<>(forks), new ForksSchedule<>(forks),

@ -19,6 +19,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.evm.operation.PrevRanDaoOperation; import org.hyperledger.besu.evm.operation.PrevRanDaoOperation;
@ -39,8 +41,8 @@ public class MergeProtocolScheduleTest {
final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions(); final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule protocolSchedule = MergeProtocolSchedule.create(config, false); final ProtocolSchedule protocolSchedule = MergeProtocolSchedule.create(config, false);
final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockNumber(1); final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockHeader(blockHeader(1));
final ProtocolSpec londonSpec = protocolSchedule.getByBlockNumber(1559); final ProtocolSpec londonSpec = protocolSchedule.getByBlockHeader(blockHeader(1559));
assertThat(homesteadSpec).isNotEqualTo(londonSpec); assertThat(homesteadSpec).isNotEqualTo(londonSpec);
assertThat(homesteadSpec.getFeeMarket().implementsBaseFee()).isFalse(); assertThat(homesteadSpec.getFeeMarket().implementsBaseFee()).isFalse();
@ -51,7 +53,7 @@ public class MergeProtocolScheduleTest {
public void parametersAlignWithMainnetWithAdjustments() { public void parametersAlignWithMainnetWithAdjustments() {
final ProtocolSpec london = final ProtocolSpec london =
MergeProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), false) MergeProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), false)
.getByBlockNumber(0); .getByBlockHeader(blockHeader(0));
assertThat(london.getName()).isEqualTo("Frontier"); assertThat(london.getName()).isEqualTo("Frontier");
assertThat(london.getBlockReward()).isEqualTo(Wei.ZERO); assertThat(london.getBlockReward()).isEqualTo(Wei.ZERO);
@ -60,4 +62,8 @@ public class MergeProtocolScheduleTest {
var op = london.getEvm().getOperationsUnsafe()[0x44]; var op = london.getEvm().getOperationsUnsafe()[0x44];
assertThat(op).isInstanceOf(PrevRanDaoOperation.class); assertThat(op).isInstanceOf(PrevRanDaoOperation.class);
} }
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}
} }

@ -47,10 +47,8 @@ public class TransitionProtocolScheduleTest {
@Mock MergeContext mergeContext; @Mock MergeContext mergeContext;
@Mock ProtocolSchedule preMergeProtocolSchedule; @Mock ProtocolSchedule preMergeProtocolSchedule;
@Mock ProtocolSchedule postMergeProtocolSchedule; @Mock ProtocolSchedule postMergeProtocolSchedule;
@Mock TimestampSchedule timestampSchedule; @Mock TimestampSchedule timestampSchedule;
@Mock BlockHeader blockHeader; @Mock BlockHeader blockHeader;
private static final Difficulty TTD = Difficulty.of(100L); private static final Difficulty TTD = Difficulty.of(100L);
private static final long BLOCK_NUMBER = 29L; private static final long BLOCK_NUMBER = 29L;
private static final long TIMESTAMP = 1L; private static final long TIMESTAMP = 1L;

@ -36,7 +36,6 @@ import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.core.Util;
import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode;
import org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration;
@ -127,7 +126,6 @@ public class QbftProtocolScheduleTest {
private BlockNumberStreamingProtocolSchedule createProtocolSchedule( private BlockNumberStreamingProtocolSchedule createProtocolSchedule(
final GenesisConfigOptions genesisConfig, final List<ForkSpec<QbftConfigOptions>> forks) { final GenesisConfigOptions genesisConfig, final List<ForkSpec<QbftConfigOptions>> forks) {
return new BlockNumberStreamingProtocolSchedule( return new BlockNumberStreamingProtocolSchedule(
(MutableProtocolSchedule)
QbftProtocolScheduleBuilder.create( QbftProtocolScheduleBuilder.create(
genesisConfig, genesisConfig,
new ForksSchedule<>(forks), new ForksSchedule<>(forks),

@ -106,9 +106,6 @@ public class EthFeeHistoryTest {
@Test @Test
public void cantGetBlockHigherThanChainHead() { public void cantGetBlockHigherThanChainHead() {
final ProtocolSpec londonSpec = mock(ProtocolSpec.class);
when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(5));
when(protocolSchedule.getForNextBlockHeader(any(), anyLong())).thenReturn(londonSpec);
assertThat( assertThat(
((JsonRpcErrorResponse) feeHistoryRequest("0x2", "11", new double[] {100.0})) ((JsonRpcErrorResponse) feeHistoryRequest("0x2", "11", new double[] {100.0}))
.getError()) .getError())
@ -117,9 +114,6 @@ public class EthFeeHistoryTest {
@Test @Test
public void blockCountBounds() { public void blockCountBounds() {
final ProtocolSpec londonSpec = mock(ProtocolSpec.class);
when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(5));
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(londonSpec);
assertThat( assertThat(
((JsonRpcErrorResponse) feeHistoryRequest("0x0", "latest", new double[] {100.0})) ((JsonRpcErrorResponse) feeHistoryRequest("0x0", "latest", new double[] {100.0}))
.getError()) .getError())
@ -134,7 +128,10 @@ public class EthFeeHistoryTest {
public void doesntGoPastChainHeadWithHighBlockCount() { public void doesntGoPastChainHeadWithHighBlockCount() {
final ProtocolSpec londonSpec = mock(ProtocolSpec.class); final ProtocolSpec londonSpec = mock(ProtocolSpec.class);
when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(5)); when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(5));
when(protocolSchedule.getForNextBlockHeader(any(), anyLong())).thenReturn(londonSpec); when(protocolSchedule.getForNextBlockHeader(
eq(blockchain.getChainHeadHeader()),
eq(blockchain.getChainHeadHeader().getTimestamp())))
.thenReturn(londonSpec);
final FeeHistory.FeeHistoryResult result = final FeeHistory.FeeHistoryResult result =
(ImmutableFeeHistoryResult) (ImmutableFeeHistoryResult)
((JsonRpcSuccessResponse) feeHistoryRequest("0x14", "latest")).getResult(); ((JsonRpcSuccessResponse) feeHistoryRequest("0x14", "latest")).getResult();
@ -148,7 +145,10 @@ public class EthFeeHistoryTest {
public void correctlyHandlesForkBlock() { public void correctlyHandlesForkBlock() {
final ProtocolSpec londonSpec = mock(ProtocolSpec.class); final ProtocolSpec londonSpec = mock(ProtocolSpec.class);
when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(11)); when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(11));
when(protocolSchedule.getForNextBlockHeader(any(), anyLong())).thenReturn(londonSpec); when(protocolSchedule.getForNextBlockHeader(
eq(blockchain.getChainHeadHeader()),
eq(blockchain.getChainHeadHeader().getTimestamp())))
.thenReturn(londonSpec);
final FeeHistory.FeeHistoryResult result = final FeeHistory.FeeHistoryResult result =
(FeeHistory.FeeHistoryResult) (FeeHistory.FeeHistoryResult)
((JsonRpcSuccessResponse) feeHistoryRequest("0x1", "latest")).getResult(); ((JsonRpcSuccessResponse) feeHistoryRequest("0x1", "latest")).getResult();
@ -160,13 +160,16 @@ public class EthFeeHistoryTest {
public void allZeroPercentilesForZeroBlock() { public void allZeroPercentilesForZeroBlock() {
final ProtocolSpec londonSpec = mock(ProtocolSpec.class); final ProtocolSpec londonSpec = mock(ProtocolSpec.class);
when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(5)); when(londonSpec.getFeeMarket()).thenReturn(FeeMarket.london(5));
when(protocolSchedule.getForNextBlockHeader(any(), anyLong())).thenReturn(londonSpec);
final BlockDataGenerator.BlockOptions blockOptions = BlockDataGenerator.BlockOptions.create(); final BlockDataGenerator.BlockOptions blockOptions = BlockDataGenerator.BlockOptions.create();
blockOptions.hasTransactions(false); blockOptions.hasTransactions(false);
blockOptions.setParentHash(blockchain.getChainHeadHash()); blockOptions.setParentHash(blockchain.getChainHeadHash());
blockOptions.setBlockNumber(11); blockOptions.setBlockNumber(11);
final Block emptyBlock = gen.block(blockOptions); final Block emptyBlock = gen.block(blockOptions);
blockchain.appendBlock(emptyBlock, gen.receipts(emptyBlock)); blockchain.appendBlock(emptyBlock, gen.receipts(emptyBlock));
when(protocolSchedule.getForNextBlockHeader(
eq(blockchain.getChainHeadHeader()),
eq(blockchain.getChainHeadHeader().getTimestamp())))
.thenReturn(londonSpec);
final FeeHistory.FeeHistoryResult result = final FeeHistory.FeeHistoryResult result =
(FeeHistory.FeeHistoryResult) (FeeHistory.FeeHistoryResult)
((JsonRpcSuccessResponse) feeHistoryRequest("0x1", "latest", new double[] {100.0})) ((JsonRpcSuccessResponse) feeHistoryRequest("0x1", "latest", new double[] {100.0}))

@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.api.query.TransactionReceiptWithMetadata; import org.hyperledger.besu.ethereum.api.query.TransactionReceiptWithMetadata;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.mainnet.PoWHasher; import org.hyperledger.besu.ethereum.mainnet.PoWHasher;
@ -50,7 +51,6 @@ import org.apache.tuweni.units.bigints.UInt256s;
import org.junit.Test; import org.junit.Test;
public class EthGetTransactionReceiptTest { public class EthGetTransactionReceiptTest {
private final TransactionReceipt statusReceipt = private final TransactionReceipt statusReceipt =
new TransactionReceipt(1, 12, Collections.emptyList(), Optional.empty()); new TransactionReceipt(1, 12, Collections.emptyList(), Optional.empty());
private final Hash stateRoot = private final Hash stateRoot =
@ -163,7 +163,7 @@ public class EthGetTransactionReceiptTest {
when(blockchain.headBlockNumber()).thenReturn(1L); when(blockchain.headBlockNumber()).thenReturn(1L);
when(blockchain.transactionReceiptByTransactionHash(receiptHash)) when(blockchain.transactionReceiptByTransactionHash(receiptHash))
.thenReturn(Optional.of(statusReceiptWithMetadata)); .thenReturn(Optional.of(statusReceiptWithMetadata));
when(protocolSchedule.getByBlockNumber(1)).thenReturn(statusTransactionTypeSpec); when(protocolSchedule.getByBlockHeader(blockHeader(1))).thenReturn(statusTransactionTypeSpec);
final JsonRpcSuccessResponse response = final JsonRpcSuccessResponse response =
(JsonRpcSuccessResponse) ethGetTransactionReceipt.response(request); (JsonRpcSuccessResponse) ethGetTransactionReceipt.response(request);
@ -179,7 +179,7 @@ public class EthGetTransactionReceiptTest {
when(blockchain.headBlockNumber()).thenReturn(1L); when(blockchain.headBlockNumber()).thenReturn(1L);
when(blockchain.transactionReceiptByTransactionHash(receiptHash)) when(blockchain.transactionReceiptByTransactionHash(receiptHash))
.thenReturn(Optional.of(rootReceiptWithMetaData)); .thenReturn(Optional.of(rootReceiptWithMetaData));
when(protocolSchedule.getByBlockNumber(1)).thenReturn(rootTransactionTypeSpec); when(protocolSchedule.getByBlockHeader(blockHeader(1))).thenReturn(rootTransactionTypeSpec);
final JsonRpcSuccessResponse response = final JsonRpcSuccessResponse response =
(JsonRpcSuccessResponse) ethGetTransactionReceipt.response(request); (JsonRpcSuccessResponse) ethGetTransactionReceipt.response(request);
@ -200,7 +200,7 @@ public class EthGetTransactionReceiptTest {
statusReceipt, transaction1559, hash, 1, 2, Optional.of(baseFee), blockHash, 4); statusReceipt, transaction1559, hash, 1, 2, Optional.of(baseFee), blockHash, 4);
when(blockchain.transactionReceiptByTransactionHash(receiptHash)) when(blockchain.transactionReceiptByTransactionHash(receiptHash))
.thenReturn(Optional.of(transactionReceiptWithMetadata)); .thenReturn(Optional.of(transactionReceiptWithMetadata));
when(protocolSchedule.getByBlockNumber(1)).thenReturn(rootTransactionTypeSpec); when(protocolSchedule.getByBlockHeader(blockHeader(1))).thenReturn(rootTransactionTypeSpec);
final JsonRpcSuccessResponse response = final JsonRpcSuccessResponse response =
(JsonRpcSuccessResponse) ethGetTransactionReceipt.response(request); (JsonRpcSuccessResponse) ethGetTransactionReceipt.response(request);
@ -215,4 +215,8 @@ public class EthGetTransactionReceiptTest {
baseFee.add(transaction1559.getMaxPriorityFeePerGas().get()), baseFee.add(transaction1559.getMaxPriorityFeePerGas().get()),
transaction1559.getMaxFeePerGas().get())); transaction1559.getMaxFeePerGas().get()));
} }
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}
} }

@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.MutableWorldState;
@ -77,7 +78,6 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public abstract class AbstractBlockTransactionSelectorTest { public abstract class AbstractBlockTransactionSelectorTest {
protected static final KeyPair keyPair = protected static final KeyPair keyPair =
SignatureAlgorithmFactory.getInstance().generateKeyPair(); SignatureAlgorithmFactory.getInstance().generateKeyPair();
protected final MetricsSystem metricsSystem = new NoOpMetricsSystem(); protected final MetricsSystem metricsSystem = new NoOpMetricsSystem();
@ -124,7 +124,7 @@ public abstract class AbstractBlockTransactionSelectorTest {
FixedDifficultyProtocolSchedule.create( FixedDifficultyProtocolSchedule.create(
GenesisConfigFile.development().getConfigOptions(), EvmConfiguration.DEFAULT); GenesisConfigFile.development().getConfigOptions(), EvmConfiguration.DEFAULT);
final MainnetTransactionProcessor mainnetTransactionProcessor = final MainnetTransactionProcessor mainnetTransactionProcessor =
protocolSchedule.getByBlockNumber(0).getTransactionProcessor(); protocolSchedule.getByBlockHeader(blockHeader(0)).getTransactionProcessor();
// The block should fit 5 transactions only // The block should fit 5 transactions only
final ProcessableBlockHeader blockHeader = createBlock(5000); final ProcessableBlockHeader blockHeader = createBlock(5000);
@ -522,4 +522,8 @@ public abstract class AbstractBlockTransactionSelectorTest {
any(), any(), any(), eq(tx), any(), any(), anyBoolean(), any(), any())) any(), any(), any(), eq(tx), any(), any(), anyBoolean(), any(), any()))
.thenReturn(TransactionProcessingResult.invalid(ValidationResult.invalid(invalidReason))); .thenReturn(TransactionProcessingResult.invalid(ValidationResult.invalid(invalidReason)));
} }
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}
} }

@ -35,6 +35,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.SealableBlockHeader; import org.hyperledger.besu.ethereum.core.SealableBlockHeader;
@ -241,10 +242,14 @@ public abstract class AbstractIsolationTests {
protected BlockProcessingResult executeBlock(final MutableWorldState ws, final Block block) { protected BlockProcessingResult executeBlock(final MutableWorldState ws, final Block block) {
var res = var res =
protocolSchedule protocolSchedule
.getByBlockNumber(0) .getByBlockHeader(blockHeader(0))
.getBlockProcessor() .getBlockProcessor()
.processBlock(blockchain, ws, block); .processBlock(blockchain, ws, block);
blockchain.appendBlock(block, res.getReceipts()); blockchain.appendBlock(block, res.getReceipts());
return res; return res;
} }
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}
} }

@ -39,21 +39,21 @@ public class FixedProtocolScheduleTest {
assertThat( assertThat(
schedule schedule
.getByBlockNumber(0) .getByBlockHeader(blockHeader(0))
.getDifficultyCalculator() .getDifficultyCalculator()
.nextDifficulty(1, parentHeader, null)) .nextDifficulty(1, parentHeader, null))
.isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY);
assertThat( assertThat(
schedule schedule
.getByBlockNumber(500) .getByBlockHeader(blockHeader(500))
.getDifficultyCalculator() .getDifficultyCalculator()
.nextDifficulty(1, parentHeader, null)) .nextDifficulty(1, parentHeader, null))
.isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY);
assertThat( assertThat(
schedule schedule
.getByBlockNumber(500_000) .getByBlockHeader(blockHeader(500_000))
.getDifficultyCalculator() .getDifficultyCalculator()
.nextDifficulty(1, parentHeader, null)) .nextDifficulty(1, parentHeader, null))
.isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY);
@ -72,23 +72,27 @@ public class FixedProtocolScheduleTest {
assertThat( assertThat(
schedule schedule
.getByBlockNumber(0) .getByBlockHeader(blockHeader(0))
.getDifficultyCalculator() .getDifficultyCalculator()
.nextDifficulty(1, parentHeader, null)) .nextDifficulty(1, parentHeader, null))
.isEqualTo(10000); .isEqualTo(10000);
assertThat( assertThat(
schedule schedule
.getByBlockNumber(500) .getByBlockHeader(blockHeader(500))
.getDifficultyCalculator() .getDifficultyCalculator()
.nextDifficulty(1, parentHeader, null)) .nextDifficulty(1, parentHeader, null))
.isEqualTo(10000); .isEqualTo(10000);
assertThat( assertThat(
schedule schedule
.getByBlockNumber(500_000) .getByBlockHeader(blockHeader(500_000))
.getDifficultyCalculator() .getDifficultyCalculator()
.nextDifficulty(1, parentHeader, null)) .nextDifficulty(1, parentHeader, null))
.isEqualTo(10000); .isEqualTo(10000);
} }
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}
} }

@ -15,6 +15,8 @@
package org.hyperledger.besu.ethereum.mainnet; package org.hyperledger.besu.ethereum.mainnet;
import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration;
@ -29,27 +31,39 @@ public class MainnetProtocolScheduleTest {
@Test @Test
public void shouldReturnDefaultProtocolSpecsWhenCustomNumbersAreNotUsed() { public void shouldReturnDefaultProtocolSpecsWhenCustomNumbersAreNotUsed() {
final ProtocolSchedule sched = ProtocolScheduleFixture.MAINNET; final ProtocolSchedule sched = ProtocolScheduleFixture.MAINNET;
Assertions.assertThat(sched.getByBlockNumber(1L).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(1L)).getName()).isEqualTo("Frontier");
Assertions.assertThat(sched.getByBlockNumber(1_150_000L).getName()).isEqualTo("Homestead"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(1_150_000L)).getName())
Assertions.assertThat(sched.getByBlockNumber(1_920_000L).getName()) .isEqualTo("Homestead");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(1_920_000L)).getName())
.isEqualTo("DaoRecoveryInit"); .isEqualTo("DaoRecoveryInit");
Assertions.assertThat(sched.getByBlockNumber(1_920_001L).getName()) Assertions.assertThat(sched.getByBlockHeader(blockHeader(1_920_001L)).getName())
.isEqualTo("DaoRecoveryTransition"); .isEqualTo("DaoRecoveryTransition");
Assertions.assertThat(sched.getByBlockNumber(1_920_010L).getName()).isEqualTo("Homestead"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(1_920_010L)).getName())
Assertions.assertThat(sched.getByBlockNumber(2_463_000L).getName()) .isEqualTo("Homestead");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(2_463_000L)).getName())
.isEqualTo("TangerineWhistle"); .isEqualTo("TangerineWhistle");
Assertions.assertThat(sched.getByBlockNumber(2_675_000L).getName()).isEqualTo("SpuriousDragon"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(2_675_000L)).getName())
Assertions.assertThat(sched.getByBlockNumber(4_730_000L).getName()).isEqualTo("Byzantium"); .isEqualTo("SpuriousDragon");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(4_730_000L)).getName())
.isEqualTo("Byzantium");
// Constantinople was originally scheduled for 7_080_000, but postponed // Constantinople was originally scheduled for 7_080_000, but postponed
Assertions.assertThat(sched.getByBlockNumber(7_080_000L).getName()).isEqualTo("Byzantium"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(7_080_000L)).getName())
Assertions.assertThat(sched.getByBlockNumber(7_280_000L).getName()).isEqualTo("Petersburg"); .isEqualTo("Byzantium");
Assertions.assertThat(sched.getByBlockNumber(9_069_000L).getName()).isEqualTo("Istanbul"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(7_280_000L)).getName())
Assertions.assertThat(sched.getByBlockNumber(9_200_000L).getName()).isEqualTo("MuirGlacier"); .isEqualTo("Petersburg");
Assertions.assertThat(sched.getByBlockNumber(12_244_000L).getName()).isEqualTo("Berlin"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(9_069_000L)).getName())
Assertions.assertThat(sched.getByBlockNumber(12_965_000L).getName()).isEqualTo("London"); .isEqualTo("Istanbul");
Assertions.assertThat(sched.getByBlockNumber(13_773_000L).getName()).isEqualTo("ArrowGlacier"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(9_200_000L)).getName())
Assertions.assertThat(sched.getByBlockNumber(15_050_000L).getName()).isEqualTo("GrayGlacier"); .isEqualTo("MuirGlacier");
Assertions.assertThat(sched.getByBlockNumber(Long.MAX_VALUE).getName()) Assertions.assertThat(sched.getByBlockHeader(blockHeader(12_244_000L)).getName())
.isEqualTo("Berlin");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(12_965_000L)).getName())
.isEqualTo("London");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(13_773_000L)).getName())
.isEqualTo("ArrowGlacier");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(15_050_000L)).getName())
.isEqualTo("GrayGlacier");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(Long.MAX_VALUE)).getName())
.isEqualTo("GrayGlacier"); .isEqualTo("GrayGlacier");
} }
@ -58,8 +72,9 @@ public class MainnetProtocolScheduleTest {
final ProtocolSchedule sched = final ProtocolSchedule sched =
MainnetProtocolSchedule.fromConfig( MainnetProtocolSchedule.fromConfig(
GenesisConfigFile.fromConfig("{}").getConfigOptions(), EvmConfiguration.DEFAULT); GenesisConfigFile.fromConfig("{}").getConfigOptions(), EvmConfiguration.DEFAULT);
Assertions.assertThat(sched.getByBlockNumber(1L).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(1L)).getName()).isEqualTo("Frontier");
Assertions.assertThat(sched.getByBlockNumber(Long.MAX_VALUE).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(Long.MAX_VALUE)).getName())
.isEqualTo("Frontier");
} }
@Test @Test
@ -69,16 +84,22 @@ public class MainnetProtocolScheduleTest {
final ProtocolSchedule sched = final ProtocolSchedule sched =
MainnetProtocolSchedule.fromConfig( MainnetProtocolSchedule.fromConfig(
GenesisConfigFile.fromConfig(json).getConfigOptions(), EvmConfiguration.DEFAULT); GenesisConfigFile.fromConfig(json).getConfigOptions(), EvmConfiguration.DEFAULT);
Assertions.assertThat(sched.getByBlockNumber(1).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(1)).getName()).isEqualTo("Frontier");
Assertions.assertThat(sched.getByBlockNumber(2).getName()).isEqualTo("Homestead"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(2)).getName()).isEqualTo("Homestead");
Assertions.assertThat(sched.getByBlockNumber(3).getName()).isEqualTo("DaoRecoveryInit"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(3)).getName())
Assertions.assertThat(sched.getByBlockNumber(4).getName()).isEqualTo("DaoRecoveryTransition"); .isEqualTo("DaoRecoveryInit");
Assertions.assertThat(sched.getByBlockNumber(13).getName()).isEqualTo("Homestead"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(4)).getName())
Assertions.assertThat(sched.getByBlockNumber(14).getName()).isEqualTo("TangerineWhistle"); .isEqualTo("DaoRecoveryTransition");
Assertions.assertThat(sched.getByBlockNumber(15).getName()).isEqualTo("SpuriousDragon"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(13)).getName()).isEqualTo("Homestead");
Assertions.assertThat(sched.getByBlockNumber(16).getName()).isEqualTo("Byzantium"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(14)).getName())
Assertions.assertThat(sched.getByBlockNumber(18).getName()).isEqualTo("Constantinople"); .isEqualTo("TangerineWhistle");
Assertions.assertThat(sched.getByBlockNumber(19).getName()).isEqualTo("Petersburg"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(15)).getName())
.isEqualTo("SpuriousDragon");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(16)).getName()).isEqualTo("Byzantium");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(18)).getName())
.isEqualTo("Constantinople");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(19)).getName())
.isEqualTo("Petersburg");
} }
@Test @Test
@ -104,11 +125,16 @@ public class MainnetProtocolScheduleTest {
this.getClass().getResource("/goerli.json"), StandardCharsets.UTF_8)) this.getClass().getResource("/goerli.json"), StandardCharsets.UTF_8))
.getConfigOptions(), .getConfigOptions(),
EvmConfiguration.DEFAULT); EvmConfiguration.DEFAULT);
Assertions.assertThat(sched.getByBlockNumber(0L).getName()).isEqualTo("Petersburg"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(0L)).getName())
Assertions.assertThat(sched.getByBlockNumber(1_561_651L).getName()).isEqualTo("Istanbul"); .isEqualTo("Petersburg");
Assertions.assertThat(sched.getByBlockNumber(4_460_644L).getName()).isEqualTo("Berlin"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(1_561_651L)).getName())
Assertions.assertThat(sched.getByBlockNumber(5_062_605L).getName()).isEqualTo("London"); .isEqualTo("Istanbul");
Assertions.assertThat(sched.getByBlockNumber(Long.MAX_VALUE).getName()).isEqualTo("London"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(4_460_644L)).getName())
.isEqualTo("Berlin");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(5_062_605L)).getName())
.isEqualTo("London");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(Long.MAX_VALUE)).getName())
.isEqualTo("London");
} }
@Test @Test
@ -120,16 +146,29 @@ public class MainnetProtocolScheduleTest {
this.getClass().getResource("/rinkeby.json"), StandardCharsets.UTF_8)) this.getClass().getResource("/rinkeby.json"), StandardCharsets.UTF_8))
.getConfigOptions(), .getConfigOptions(),
EvmConfiguration.DEFAULT); EvmConfiguration.DEFAULT);
Assertions.assertThat(sched.getByBlockNumber(0L).getName()).isEqualTo("Frontier"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(0L)).getName()).isEqualTo("Frontier");
Assertions.assertThat(sched.getByBlockNumber(1L).getName()).isEqualTo("Homestead"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(1L)).getName()).isEqualTo("Homestead");
Assertions.assertThat(sched.getByBlockNumber(2L).getName()).isEqualTo("TangerineWhistle"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(2L)).getName())
Assertions.assertThat(sched.getByBlockNumber(3L).getName()).isEqualTo("SpuriousDragon"); .isEqualTo("TangerineWhistle");
Assertions.assertThat(sched.getByBlockNumber(1_035_301L).getName()).isEqualTo("Byzantium"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(3L)).getName())
Assertions.assertThat(sched.getByBlockNumber(3_660_663L).getName()).isEqualTo("Constantinople"); .isEqualTo("SpuriousDragon");
Assertions.assertThat(sched.getByBlockNumber(4_321_234L).getName()).isEqualTo("Petersburg"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(1_035_301L)).getName())
Assertions.assertThat(sched.getByBlockNumber(5_435_345L).getName()).isEqualTo("Istanbul"); .isEqualTo("Byzantium");
Assertions.assertThat(sched.getByBlockNumber(8_290_928L).getName()).isEqualTo("Berlin"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(3_660_663L)).getName())
Assertions.assertThat(sched.getByBlockNumber(8_897_988L).getName()).isEqualTo("London"); .isEqualTo("Constantinople");
Assertions.assertThat(sched.getByBlockNumber(Long.MAX_VALUE).getName()).isEqualTo("London"); Assertions.assertThat(sched.getByBlockHeader(blockHeader(4_321_234L)).getName())
.isEqualTo("Petersburg");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(5_435_345L)).getName())
.isEqualTo("Istanbul");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(8_290_928L)).getName())
.isEqualTo("Berlin");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(8_897_988L)).getName())
.isEqualTo("London");
Assertions.assertThat(sched.getByBlockHeader(blockHeader(Long.MAX_VALUE)).getName())
.isEqualTo("London");
}
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
} }
} }

@ -100,7 +100,7 @@ public class MutableProtocolScheduleTest {
final MutableProtocolSchedule protocolSchedule = new MutableProtocolSchedule(CHAIN_ID); final MutableProtocolSchedule protocolSchedule = new MutableProtocolSchedule(CHAIN_ID);
protocolSchedule.putMilestone(0, spec1); protocolSchedule.putMilestone(0, spec1);
protocolSchedule.putMilestone(0, spec2); protocolSchedule.putMilestone(0, spec2);
assertThat(protocolSchedule.getByBlockNumber(0)).isSameAs(spec2); assertThat(protocolSchedule.getByBlockHeader(header(0))).isSameAs(spec2);
} }
@Test @Test

@ -22,6 +22,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule; import org.hyperledger.besu.ethereum.core.BlockNumberStreamingProtocolSchedule;
import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.internal.EvmConfiguration;
@ -40,7 +42,6 @@ import org.mockito.stubbing.Answer;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class ProtocolScheduleBuilderTest { public class ProtocolScheduleBuilderTest {
@Mock GenesisConfigOptions configOptions; @Mock GenesisConfigOptions configOptions;
@Mock private Function<ProtocolSpecBuilder, ProtocolSpecBuilder> modifier; @Mock private Function<ProtocolSpecBuilder, ProtocolSpecBuilder> modifier;
private static final BigInteger CHAIN_ID = BigInteger.ONE; private static final BigInteger CHAIN_ID = BigInteger.ONE;
@ -68,15 +69,17 @@ public class ProtocolScheduleBuilderTest {
final ProtocolSchedule protocolSchedule = builder.createProtocolSchedule(); final ProtocolSchedule protocolSchedule = builder.createProtocolSchedule();
assertThat(protocolSchedule.getChainId()).contains(CHAIN_ID); assertThat(protocolSchedule.getChainId()).contains(CHAIN_ID);
assertThat(protocolSchedule.getByBlockNumber(0).getName()).isEqualTo("Frontier"); assertThat(protocolSchedule.getByBlockHeader(blockHeader(0)).getName()).isEqualTo("Frontier");
assertThat(protocolSchedule.getByBlockNumber(1).getName()).isEqualTo("Homestead"); assertThat(protocolSchedule.getByBlockHeader(blockHeader(1)).getName()).isEqualTo("Homestead");
assertThat(protocolSchedule.getByBlockNumber(2).getName()).isEqualTo("DaoRecoveryInit"); assertThat(protocolSchedule.getByBlockHeader(blockHeader(2)).getName())
assertThat(protocolSchedule.getByBlockNumber(3).getName()).isEqualTo("DaoRecoveryTransition"); .isEqualTo("DaoRecoveryInit");
assertThat(protocolSchedule.getByBlockNumber(12).getName()).isEqualTo("Homestead"); assertThat(protocolSchedule.getByBlockHeader(blockHeader(3)).getName())
assertThat(protocolSchedule.getByBlockNumber(13).getName()).isEqualTo("Byzantium"); .isEqualTo("DaoRecoveryTransition");
assertThat(protocolSchedule.getByBlockNumber(14).getName()).isEqualTo("Byzantium"); assertThat(protocolSchedule.getByBlockHeader(blockHeader(12)).getName()).isEqualTo("Homestead");
assertThat(protocolSchedule.getByBlockNumber(15).getName()).isEqualTo("ParisFork"); assertThat(protocolSchedule.getByBlockHeader(blockHeader(13)).getName()).isEqualTo("Byzantium");
assertThat(protocolSchedule.getByBlockNumber(50).getName()).isEqualTo("ParisFork"); assertThat(protocolSchedule.getByBlockHeader(blockHeader(14)).getName()).isEqualTo("Byzantium");
assertThat(protocolSchedule.getByBlockHeader(blockHeader(15)).getName()).isEqualTo("ParisFork");
assertThat(protocolSchedule.getByBlockHeader(blockHeader(50)).getName()).isEqualTo("ParisFork");
} }
@Test @Test
@ -86,8 +89,8 @@ public class ProtocolScheduleBuilderTest {
final ProtocolSchedule protocolSchedule = builder.createProtocolSchedule(); final ProtocolSchedule protocolSchedule = builder.createProtocolSchedule();
assertThat(protocolSchedule.getChainId()).contains(CHAIN_ID); assertThat(protocolSchedule.getChainId()).contains(CHAIN_ID);
assertThat(protocolSchedule.getByBlockNumber(0).getName()).isEqualTo("Byzantium"); assertThat(protocolSchedule.getByBlockHeader(blockHeader(0)).getName()).isEqualTo("Byzantium");
assertThat(protocolSchedule.getByBlockNumber(1).getName()).isEqualTo("Byzantium"); assertThat(protocolSchedule.getByBlockHeader(blockHeader(1)).getName()).isEqualTo("Byzantium");
} }
@Test @Test
@ -114,9 +117,9 @@ public class ProtocolScheduleBuilderTest {
// added at the point at which the modifier is applied. // added at the point at which the modifier is applied.
assertThat(schedule.streamMilestoneBlocks().collect(Collectors.toList())) assertThat(schedule.streamMilestoneBlocks().collect(Collectors.toList()))
.containsExactly(0L, 2L, 5L); .containsExactly(0L, 2L, 5L);
assertThat(schedule.getByBlockNumber(0).getName()).isEqualTo("Frontier"); assertThat(schedule.getByBlockHeader(blockHeader(0)).getName()).isEqualTo("Frontier");
assertThat(schedule.getByBlockNumber(2).getName()).isEqualTo("Frontier"); assertThat(schedule.getByBlockHeader(blockHeader(2)).getName()).isEqualTo("Frontier");
assertThat(schedule.getByBlockNumber(5).getName()).isEqualTo("Homestead"); assertThat(schedule.getByBlockHeader(blockHeader(5)).getName()).isEqualTo("Homestead");
verify(modifier, times(2)).apply(any()); verify(modifier, times(2)).apply(any());
} }
@ -132,8 +135,8 @@ public class ProtocolScheduleBuilderTest {
// added at the point at which the modifier is applied. // added at the point at which the modifier is applied.
assertThat(schedule.streamMilestoneBlocks().collect(Collectors.toList())) assertThat(schedule.streamMilestoneBlocks().collect(Collectors.toList()))
.containsExactly(0L, 2L); .containsExactly(0L, 2L);
assertThat(schedule.getByBlockNumber(0).getName()).isEqualTo("Frontier"); assertThat(schedule.getByBlockHeader(blockHeader(0)).getName()).isEqualTo("Frontier");
assertThat(schedule.getByBlockNumber(2).getName()).isEqualTo("Frontier"); assertThat(schedule.getByBlockHeader(blockHeader(2)).getName()).isEqualTo("Frontier");
verify(modifier, times(1)).apply(any()); verify(modifier, times(1)).apply(any());
} }
@ -150,9 +153,8 @@ public class ProtocolScheduleBuilderTest {
// added at the point at which the modifier is applied. // added at the point at which the modifier is applied.
assertThat(schedule.streamMilestoneBlocks().collect(Collectors.toList())) assertThat(schedule.streamMilestoneBlocks().collect(Collectors.toList()))
.containsExactly(0L, 5L); .containsExactly(0L, 5L);
assertThat(schedule.getByBlockNumber(0).getName()).isEqualTo("Frontier"); assertThat(schedule.getByBlockHeader(blockHeader(0)).getName()).isEqualTo("Frontier");
assertThat(schedule.getByBlockNumber(5).getName()).isEqualTo("Homestead"); assertThat(schedule.getByBlockHeader(blockHeader(5)).getName()).isEqualTo("Homestead");
verify(modifier, times(1)).apply(any()); verify(modifier, times(1)).apply(any());
} }
@ -170,4 +172,8 @@ public class ProtocolScheduleBuilderTest {
return new BlockNumberStreamingProtocolSchedule( return new BlockNumberStreamingProtocolSchedule(
(MutableProtocolSchedule) builder.createProtocolSchedule()); (MutableProtocolSchedule) builder.createProtocolSchedule());
} }
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}
} }

@ -22,7 +22,6 @@ import static org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver.EMP
import static org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage.SCHEMA_VERSION_1_0_0; import static org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage.SCHEMA_VERSION_1_0_0;
import static org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage.SCHEMA_VERSION_1_4_0; import static org.hyperledger.besu.ethereum.privacy.storage.PrivateStateKeyValueStorage.SCHEMA_VERSION_1_4_0;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -103,7 +102,7 @@ public class PrivateStorageMigrationTest {
privateStateStorage = new PrivateStateKeyValueStorage(kvStorage); privateStateStorage = new PrivateStateKeyValueStorage(kvStorage);
privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage); privateStateRootResolver = new PrivateStateRootResolver(privateStateStorage);
lenient().when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(protocolSpec); lenient().when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec);
lenient().when(protocolSpec.getTransactionProcessor()).thenReturn(transactionProcessor); lenient().when(protocolSpec.getTransactionProcessor()).thenReturn(transactionProcessor);
lenient() lenient()
.when(protocolSpec.getTransactionReceiptFactory()) .when(protocolSpec.getTransactionReceiptFactory())

@ -16,7 +16,6 @@ package org.hyperledger.besu.ethereum.eth.sync;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -36,6 +35,8 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockDataGenerator;
import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.BlockImporter; import org.hyperledger.besu.ethereum.core.BlockImporter;
import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil;
import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.Difficulty;
@ -325,10 +326,11 @@ public abstract class AbstractBlockPropagationManagerTest {
@Test @Test
public void handlesDuplicateAnnouncements() { public void handlesDuplicateAnnouncements() {
final ProtocolSchedule stubProtocolSchedule = spy(protocolSchedule); final ProtocolSchedule stubProtocolSchedule = spy(protocolSchedule);
final ProtocolSpec stubProtocolSpec = spy(protocolSchedule.getByBlockNumber(2)); final ProtocolSpec stubProtocolSpec = spy(protocolSchedule.getByBlockHeader(blockHeader(2)));
final BlockImporter stubBlockImporter = spy(stubProtocolSpec.getBlockImporter()); final BlockImporter stubBlockImporter = spy(stubProtocolSpec.getBlockImporter());
doReturn(stubProtocolSpec).when(stubProtocolSchedule).getByBlockNumber(anyLong()); doReturn(stubProtocolSpec).when(stubProtocolSchedule).getByBlockHeader(any());
doReturn(stubBlockImporter).when(stubProtocolSpec).getBlockImporter(); doReturn(stubBlockImporter).when(stubProtocolSpec).getBlockImporter();
final BlockPropagationManager blockPropagationManager = final BlockPropagationManager blockPropagationManager =
new BlockPropagationManager( new BlockPropagationManager(
@ -378,9 +380,9 @@ public abstract class AbstractBlockPropagationManagerTest {
@Test @Test
public void handlesPendingDuplicateAnnouncements() { public void handlesPendingDuplicateAnnouncements() {
final ProtocolSchedule stubProtocolSchedule = spy(protocolSchedule); final ProtocolSchedule stubProtocolSchedule = spy(protocolSchedule);
final ProtocolSpec stubProtocolSpec = spy(protocolSchedule.getByBlockNumber(2)); final ProtocolSpec stubProtocolSpec = spy(protocolSchedule.getByBlockHeader(blockHeader(2)));
final BlockImporter stubBlockImporter = spy(stubProtocolSpec.getBlockImporter()); final BlockImporter stubBlockImporter = spy(stubProtocolSpec.getBlockImporter());
doReturn(stubProtocolSpec).when(stubProtocolSchedule).getByBlockNumber(anyLong()); doReturn(stubProtocolSpec).when(stubProtocolSchedule).getByBlockHeader(any());
doReturn(stubBlockImporter).when(stubProtocolSpec).getBlockImporter(); doReturn(stubBlockImporter).when(stubProtocolSpec).getBlockImporter();
final BlockPropagationManager blockPropagationManager = final BlockPropagationManager blockPropagationManager =
new BlockPropagationManager( new BlockPropagationManager(
@ -772,7 +774,7 @@ public abstract class AbstractBlockPropagationManagerTest {
blockchainUtil.importFirstBlocks(2); blockchainUtil.importFirstBlocks(2);
final Block firstBlock = blockchainUtil.getBlock(1); final Block firstBlock = blockchainUtil.getBlock(1);
final BadBlockManager badBlocksManager = final BadBlockManager badBlocksManager =
protocolSchedule.getByBlockNumber(1).getBadBlocksManager(); protocolSchedule.getByBlockHeader(blockHeader(1)).getBadBlocksManager();
final Block badBlock = final Block badBlock =
new BlockDataGenerator() new BlockDataGenerator()
.block( .block(
@ -983,4 +985,8 @@ public abstract class AbstractBlockPropagationManagerTest {
} }
public abstract Blockchain getFullBlockchain(); public abstract Blockchain getFullBlockchain();
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}
} }

@ -21,7 +21,6 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -83,12 +82,15 @@ public class BackwardSyncContextTest {
private MutableBlockchain remoteBlockchain; private MutableBlockchain remoteBlockchain;
private RespondingEthPeer peer; private RespondingEthPeer peer;
private MutableBlockchain localBlockchain; private MutableBlockchain localBlockchain;
private static final BlockDataGenerator blockDataGenerator = new BlockDataGenerator();
@Spy @Spy
private ProtocolSchedule protocolSchedule = private ProtocolSchedule protocolSchedule =
MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions()); MainnetProtocolSchedule.fromConfig(new StubGenesisConfigOptions());
@Spy private ProtocolSpec mockProtocolSpec = protocolSchedule.getByBlockNumber(0L); @Spy
private ProtocolSpec protocolSpec =
protocolSchedule.getByBlockHeader(blockDataGenerator.header(0L));
@Mock(answer = Answers.RETURNS_DEEP_STUBS) @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ProtocolContext protocolContext; private ProtocolContext protocolContext;
@ -101,12 +103,11 @@ public class BackwardSyncContextTest {
private BackwardChain backwardChain; private BackwardChain backwardChain;
private Block uncle; private Block uncle;
private Block genesisBlock; private Block genesisBlock;
private static final BlockDataGenerator blockDataGenerator = new BlockDataGenerator();
@Before @Before
public void setup() { public void setup() {
when(mockProtocolSpec.getBlockValidator()).thenReturn(blockValidator); when(protocolSpec.getBlockValidator()).thenReturn(blockValidator);
when(protocolSchedule.getByBlockNumber(anyLong())).thenReturn(mockProtocolSpec); doReturn(protocolSpec).when(protocolSchedule).getByBlockHeader(any());
genesisBlock = blockDataGenerator.genesisBlock(); genesisBlock = blockDataGenerator.genesisBlock();
remoteBlockchain = createInMemoryBlockchain(genesisBlock); remoteBlockchain = createInMemoryBlockchain(genesisBlock);
localBlockchain = createInMemoryBlockchain(genesisBlock); localBlockchain = createInMemoryBlockchain(genesisBlock);

@ -26,7 +26,6 @@ import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason
import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.TRANSACTION_REPLACEMENT_UNDERPRICED; import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.TRANSACTION_REPLACEMENT_UNDERPRICED;
import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.TX_FEECAP_EXCEEDED; import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.TX_FEECAP_EXCEEDED;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.atLeastOnce;
@ -136,7 +135,7 @@ public abstract class AbstractTransactionPoolTest {
when(protocolSpec.getTransactionValidator()).thenReturn(transactionValidator); when(protocolSpec.getTransactionValidator()).thenReturn(transactionValidator);
when(protocolSpec.getFeeMarket()).thenReturn(getFeeMarket()); when(protocolSpec.getFeeMarket()).thenReturn(getFeeMarket());
protocolSchedule = spy(executionContext.getProtocolSchedule()); protocolSchedule = spy(executionContext.getProtocolSchedule());
doReturn(protocolSpec).when(protocolSchedule).getByBlockNumber(anyLong()); doReturn(protocolSpec).when(protocolSchedule).getByBlockHeader(any());
blockGasLimit = blockchain.getChainHeadBlock().getHeader().getGasLimit(); blockGasLimit = blockchain.getChainHeadBlock().getHeader().getGasLimit();
ethProtocolManager = EthProtocolManagerTestUtil.create(); ethProtocolManager = EthProtocolManagerTestUtil.create();
ethContext = spy(ethProtocolManager.ethContext()); ethContext = spy(ethProtocolManager.ethContext());

@ -171,7 +171,7 @@ public class DifficultyCalculatorTests {
final long currentTime = extractLong(value, "currentTimestamp"); final long currentTime = extractLong(value, "currentTimestamp");
final UInt256 currentDifficulty = final UInt256 currentDifficulty =
UInt256.fromHexString(value.get("currentDifficulty").asText()); UInt256.fromHexString(value.get("currentDifficulty").asText());
final var spec = protocolSchedule.getByBlockNumber(currentBlockNumber); final var spec = protocolSchedule.getByBlockHeader(testHeader);
final var calculator = spec.getDifficultyCalculator(); final var calculator = spec.getDifficultyCalculator();
assertThat(UInt256.valueOf(calculator.nextDifficulty(currentTime, testHeader, null))) assertThat(UInt256.valueOf(calculator.nextDifficulty(currentTime, testHeader, null)))
.describedAs("File %s Test %s", testFile, entry.getKey()) .describedAs("File %s Test %s", testFile, entry.getKey())

Loading…
Cancel
Save