use of org.hyperledger.besu.ethereum.eth.manager.ForkIdManager in project besu by hyperledger.
the class ForkIdsTest method testForkId.
@Test
public void testForkId() {
final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(EthNetworkConfig.jsonConfig(chainName));
final GenesisConfigOptions configOptions = genesisConfigFile.getConfigOptions();
final ProtocolSchedule schedule = MainnetProtocolSchedule.fromConfig(configOptions, EvmConfiguration.DEFAULT);
final GenesisState genesisState = GenesisState.fromConfig(genesisConfigFile, schedule);
final Blockchain mockBlockchain = mock(Blockchain.class);
when(mockBlockchain.getGenesisBlock()).thenReturn(genesisState.getBlock());
final AtomicLong blockNumber = new AtomicLong();
when(mockBlockchain.getChainHeadBlockNumber()).thenAnswer(o -> blockNumber.get());
final ForkIdManager forkIdManager = new ForkIdManager(mockBlockchain, genesisConfigFile.getForks(), false);
final var actualForkIds = Streams.concat(((MutableProtocolSchedule) schedule).streamMilestoneBlocks(), Stream.of(Long.MAX_VALUE)).map(block -> {
blockNumber.set(block);
return forkIdManager.getForkIdForChainHead();
}).collect(Collectors.toList());
assertThat(actualForkIds).containsExactlyElementsOf(expectedForkIds);
}
use of org.hyperledger.besu.ethereum.eth.manager.ForkIdManager in project besu by hyperledger.
the class ForkIdBackwardCompatibilityTest method assertBackwardCompatibilityWorks.
@Test
public void assertBackwardCompatibilityWorks() {
LOG.info("Running test case {}", name);
final ForkIdManager forkIdManager = new ForkIdManager(mockBlockchain(genesisHash, head), forks, legacyEth64);
final ForkId legacyForkId = legacyEth64 ? new LegacyForkIdManager(mockBlockchain(genesisHash, head), forks).getLatestForkId() : null;
assertThat(forkIdManager.getForkIdForChainHead()).isEqualTo(legacyEth64 ? legacyForkId : wantForkId);
}
Aggregations