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);
}
Aggregations