Search in sources :

Example 1 with MigratingContext

use of org.hyperledger.besu.consensus.common.MigratingContext in project besu by hyperledger.

the class ConsensusScheduleBesuControllerBuilderTest method createsMigratingContext.

@Test
public void createsMigratingContext() {
    final ConsensusContext context1 = Mockito.mock(ConsensusContext.class);
    final ConsensusContext context2 = Mockito.mock(ConsensusContext.class);
    final Map<Long, BesuControllerBuilder> besuControllerBuilderSchedule = new TreeMap<>();
    besuControllerBuilderSchedule.put(0L, besuControllerBuilder1);
    besuControllerBuilderSchedule.put(10L, besuControllerBuilder2);
    when(besuControllerBuilder1.createConsensusContext(any(), any(), any())).thenReturn(context1);
    when(besuControllerBuilder2.createConsensusContext(any(), any(), any())).thenReturn(context2);
    final ConsensusScheduleBesuControllerBuilder controllerBuilder = new ConsensusScheduleBesuControllerBuilder(besuControllerBuilderSchedule);
    final ConsensusContext consensusContext = controllerBuilder.createConsensusContext(Mockito.mock(Blockchain.class), Mockito.mock(WorldStateArchive.class), Mockito.mock(ProtocolSchedule.class));
    assertThat(consensusContext).isInstanceOf(MigratingContext.class);
    final MigratingContext migratingContext = (MigratingContext) consensusContext;
    final ForksSchedule<ConsensusContext> contextSchedule = migratingContext.getConsensusContextSchedule();
    final NavigableSet<ForkSpec<ConsensusContext>> expectedConsensusContextSpecs = new TreeSet<>(ForkSpec.COMPARATOR);
    expectedConsensusContextSpecs.add(new ForkSpec<>(0L, context1));
    expectedConsensusContextSpecs.add(new ForkSpec<>(10L, context2));
    assertThat(contextSchedule.getForks()).isEqualTo(expectedConsensusContextSpecs);
    assertThat(contextSchedule.getFork(0).getValue()).isSameAs(context1);
    assertThat(contextSchedule.getFork(1).getValue()).isSameAs(context1);
    assertThat(contextSchedule.getFork(9).getValue()).isSameAs(context1);
    assertThat(contextSchedule.getFork(10).getValue()).isSameAs(context2);
    assertThat(contextSchedule.getFork(11).getValue()).isSameAs(context2);
}
Also used : ForkSpec(org.hyperledger.besu.consensus.common.ForkSpec) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) TreeMap(java.util.TreeMap) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) MigratingContext(org.hyperledger.besu.consensus.common.MigratingContext) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) TreeSet(java.util.TreeSet) ConsensusContext(org.hyperledger.besu.ethereum.ConsensusContext) Test(org.junit.Test)

Aggregations

TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 ForkSpec (org.hyperledger.besu.consensus.common.ForkSpec)1 MigratingContext (org.hyperledger.besu.consensus.common.MigratingContext)1 ConsensusContext (org.hyperledger.besu.ethereum.ConsensusContext)1 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)1 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)1 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)1 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)1 Test (org.junit.Test)1