use of org.hyperledger.besu.consensus.common.ForkSpec in project besu by hyperledger.
the class QbftProtocolScheduleTest method blockModeTransitionsCreatesBlockModeHeaderValidators.
@Test
public void blockModeTransitionsCreatesBlockModeHeaderValidators() {
final MutableQbftConfigOptions arbitraryTransition = new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT);
arbitraryTransition.setBlockRewardWei(BigInteger.ONE);
final BlockHeader parentHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(1, proposerNodeKey, validators, null, Optional.empty()).buildHeader();
final BlockHeader blockHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(2, proposerNodeKey, validators, parentHeader, Optional.empty()).buildHeader();
final ProtocolSchedule schedule = createProtocolSchedule(JsonGenesisConfigOptions.fromJsonObject(JsonUtil.createEmptyObjectNode()), List.of(new ForkSpec<>(0, JsonQbftConfigOptions.DEFAULT), new ForkSpec<>(1, arbitraryTransition), new ForkSpec<>(2, JsonQbftConfigOptions.DEFAULT)));
assertThat(schedule.streamMilestoneBlocks().count()).isEqualTo(3);
assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 0)).isTrue();
assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 1)).isTrue();
assertThat(validateHeader(schedule, validators, parentHeader, blockHeader, 2)).isTrue();
}
use of org.hyperledger.besu.consensus.common.ForkSpec in project besu by hyperledger.
the class QbftBlockCreatorFactoryTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
final MiningParameters miningParams = mock(MiningParameters.class);
when(miningParams.getExtraData()).thenReturn(Bytes.wrap("Qbft tests".getBytes(UTF_8)));
final MutableQbftConfigOptions qbftConfigOptions = new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT);
qbftConfigOptions.setValidatorContractAddress(Optional.of("1"));
final ForkSpec<QbftConfigOptions> spec = new ForkSpec<>(0, qbftConfigOptions);
final ForksSchedule<QbftConfigOptions> forksSchedule = mock(ForksSchedule.class);
when(forksSchedule.getFork(anyLong())).thenReturn(spec);
qbftBlockCreatorFactory = new QbftBlockCreatorFactory(mock(AbstractPendingTransactionsSorter.class), mock(ProtocolContext.class), mock(ProtocolSchedule.class), forksSchedule, miningParams, mock(Address.class), extraDataCodec);
}
use of org.hyperledger.besu.consensus.common.ForkSpec 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);
}
use of org.hyperledger.besu.consensus.common.ForkSpec in project besu by hyperledger.
the class ConsensusScheduleBesuControllerBuilderTest method mustCreateCombinedProtocolScheduleUsingProtocolSchedulesOrderedByBlock.
@Test
public void mustCreateCombinedProtocolScheduleUsingProtocolSchedulesOrderedByBlock() {
// Use an ordered map with keys in the incorrect order so that we can show that set is created
// with the correct order
final Map<Long, BesuControllerBuilder> besuControllerBuilderSchedule = new TreeMap<>();
besuControllerBuilderSchedule.put(30L, besuControllerBuilder3);
besuControllerBuilderSchedule.put(10L, besuControllerBuilder2);
besuControllerBuilderSchedule.put(0L, besuControllerBuilder1);
when(besuControllerBuilder1.createProtocolSchedule()).thenReturn(protocolSchedule1);
when(besuControllerBuilder2.createProtocolSchedule()).thenReturn(protocolSchedule2);
when(besuControllerBuilder3.createProtocolSchedule()).thenReturn(protocolSchedule3);
final StubGenesisConfigOptions genesisConfigOptions = new StubGenesisConfigOptions();
genesisConfigOptions.chainId(BigInteger.TEN);
when(genesisConfigFile.getConfigOptions()).thenReturn(genesisConfigOptions);
final ConsensusScheduleBesuControllerBuilder consensusScheduleBesuControllerBuilder = new ConsensusScheduleBesuControllerBuilder(besuControllerBuilderSchedule, combinedProtocolScheduleFactory);
consensusScheduleBesuControllerBuilder.genesisConfigFile(genesisConfigFile);
consensusScheduleBesuControllerBuilder.createProtocolSchedule();
final NavigableSet<ForkSpec<ProtocolSchedule>> expectedProtocolSchedulesSpecs = new TreeSet<>(ForkSpec.COMPARATOR);
expectedProtocolSchedulesSpecs.add(new ForkSpec<>(0L, protocolSchedule1));
expectedProtocolSchedulesSpecs.add(new ForkSpec<>(10L, protocolSchedule2));
expectedProtocolSchedulesSpecs.add(new ForkSpec<>(30L, protocolSchedule3));
Mockito.verify(combinedProtocolScheduleFactory).apply(expectedProtocolSchedulesSpecs, Optional.of(BigInteger.TEN));
}
use of org.hyperledger.besu.consensus.common.ForkSpec in project besu by hyperledger.
the class QbftForksSchedulesFactoryTest method createsScheduleWithForkThatOverridesGenesisValues.
@Test
public void createsScheduleWithForkThatOverridesGenesisValues() {
final MutableQbftConfigOptions configOptions = new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT);
final ObjectNode fork = JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 1, BftFork.VALIDATORS_KEY, List.of("1", "2", "3"), BftFork.BLOCK_PERIOD_SECONDS_KEY, 10, BftFork.BLOCK_REWARD_KEY, "5", QbftFork.VALIDATOR_SELECTION_MODE_KEY, VALIDATOR_SELECTION_MODE.CONTRACT, QbftFork.VALIDATOR_CONTRACT_ADDRESS_KEY, "10"));
final ForksSchedule<QbftConfigOptions> forksSchedule = QbftForksSchedulesFactory.create(createGenesisConfig(configOptions, fork));
assertThat(forksSchedule.getFork(0)).usingRecursiveComparison().isEqualTo(new ForkSpec<>(0, configOptions));
final Map<String, Object> forkOptions = new HashMap<>(configOptions.asMap());
forkOptions.put(BftFork.BLOCK_PERIOD_SECONDS_KEY, 10);
forkOptions.put(BftFork.BLOCK_REWARD_KEY, "5");
forkOptions.put(QbftFork.VALIDATOR_SELECTION_MODE_KEY, "5");
forkOptions.put(QbftFork.VALIDATOR_CONTRACT_ADDRESS_KEY, "10");
final QbftConfigOptions expectedForkConfig = new MutableQbftConfigOptions(new JsonQbftConfigOptions(JsonUtil.objectNodeFromMap(forkOptions)));
final ForkSpec<QbftConfigOptions> expectedFork = new ForkSpec<>(1, expectedForkConfig);
assertThat(forksSchedule.getFork(1)).usingRecursiveComparison().isEqualTo(expectedFork);
assertThat(forksSchedule.getFork(2)).usingRecursiveComparison().isEqualTo(expectedFork);
}
Aggregations