Search in sources :

Example 1 with ForkIdManager

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);
}
Also used : EthNetworkConfig(org.hyperledger.besu.cli.config.EthNetworkConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) Bytes(org.apache.tuweni.bytes.Bytes) GenesisState(org.hyperledger.besu.ethereum.chain.GenesisState) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) NetworkName(org.hyperledger.besu.cli.config.NetworkName) GenesisConfigFile(org.hyperledger.besu.config.GenesisConfigFile) ForkId(org.hyperledger.besu.ethereum.eth.manager.ForkId) Parameterized(org.junit.runners.Parameterized) Collection(java.util.Collection) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) MainnetProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ForkIdManager(org.hyperledger.besu.ethereum.eth.manager.ForkIdManager) Streams(com.google.common.collect.Streams) EvmConfiguration(org.hyperledger.besu.evm.internal.EvmConfiguration) Collectors(java.util.stream.Collectors) MutableProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Stream(java.util.stream.Stream) Mockito.mock(org.mockito.Mockito.mock) GenesisState(org.hyperledger.besu.ethereum.chain.GenesisState) AtomicLong(java.util.concurrent.atomic.AtomicLong) GenesisConfigFile(org.hyperledger.besu.config.GenesisConfigFile) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) MainnetProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule) MutableProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule) ForkIdManager(org.hyperledger.besu.ethereum.eth.manager.ForkIdManager) Test(org.junit.Test)

Example 2 with ForkIdManager

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);
}
Also used : ForkId(org.hyperledger.besu.ethereum.eth.manager.ForkId) ForkIdManager(org.hyperledger.besu.ethereum.eth.manager.ForkIdManager) Test(org.junit.Test)

Aggregations

ForkId (org.hyperledger.besu.ethereum.eth.manager.ForkId)2 ForkIdManager (org.hyperledger.besu.ethereum.eth.manager.ForkIdManager)2 Test (org.junit.Test)2 Streams (com.google.common.collect.Streams)1 Collection (java.util.Collection)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 EthNetworkConfig (org.hyperledger.besu.cli.config.EthNetworkConfig)1 NetworkName (org.hyperledger.besu.cli.config.NetworkName)1 GenesisConfigFile (org.hyperledger.besu.config.GenesisConfigFile)1 GenesisConfigOptions (org.hyperledger.besu.config.GenesisConfigOptions)1 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)1 GenesisState (org.hyperledger.besu.ethereum.chain.GenesisState)1 MainnetProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule)1 MutableProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule)1 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)1