use of tech.pegasys.teku.validator.api.ProposerDuties in project teku by ConsenSys.
the class ValidatorApiHandlerTest method getProposerDuties_shouldReturnDutiesInOrder.
@Test
void getProposerDuties_shouldReturnDutiesInOrder() {
final BeaconState state = createStateWithActiveValidators(EPOCH_START_SLOT);
when(chainDataClient.getStateAtSlotExact(EPOCH_START_SLOT)).thenReturn(completedFuture(Optional.of(state)));
when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH.minus(1));
final SafeFuture<Optional<ProposerDuties>> result = validatorApiHandler.getProposerDuties(EPOCH);
final Optional<ProposerDuties> duties = assertCompletedSuccessfully(result);
assertThat(duties.orElseThrow().getDuties()).isSortedAccordingTo(Comparator.comparing(ProposerDuty::getSlot));
}
use of tech.pegasys.teku.validator.api.ProposerDuties in project teku by ConsenSys.
the class ValidatorApiHandlerTest method getProposerDuties_shouldReturnDutiesForCurrentEpoch.
@Test
public void getProposerDuties_shouldReturnDutiesForCurrentEpoch() {
final BeaconState state = createStateWithActiveValidators(EPOCH_START_SLOT);
when(chainDataClient.getStateAtSlotExact(EPOCH_START_SLOT)).thenReturn(completedFuture(Optional.of(state)));
when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH);
final SafeFuture<Optional<ProposerDuties>> result = validatorApiHandler.getProposerDuties(EPOCH);
final ProposerDuties duties = assertCompletedSuccessfully(result).orElseThrow();
assertThat(duties.getDuties().size()).isEqualTo(spec.slotsPerEpoch(EPOCH));
assertThat(duties.getDependentRoot()).isEqualTo(spec.getCurrentDutyDependentRoot(state));
}
use of tech.pegasys.teku.validator.api.ProposerDuties in project teku by ConsenSys.
the class ValidatorApiHandlerTest method getProposerDuties_shouldAllowOneEpochTolerance.
@Test
public void getProposerDuties_shouldAllowOneEpochTolerance() {
final BeaconState state = createStateWithActiveValidators(EPOCH_START_SLOT);
when(chainDataClient.getStateAtSlotExact(EPOCH_START_SLOT)).thenReturn(completedFuture(Optional.of(state)));
when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH.minus(1));
final SafeFuture<Optional<ProposerDuties>> result = validatorApiHandler.getProposerDuties(EPOCH);
final Optional<ProposerDuties> duties = assertCompletedSuccessfully(result);
assertThat(duties.orElseThrow().getDuties().size()).isEqualTo(spec.slotsPerEpoch(EPOCH));
}
use of tech.pegasys.teku.validator.api.ProposerDuties in project teku by ConsenSys.
the class BlockDutySchedulerTest method shouldProduceBlockIfCurrentEpochIsAtBoundaryOfLookaheadEpoch.
@Test
public void shouldProduceBlockIfCurrentEpochIsAtBoundaryOfLookaheadEpoch() {
createDutySchedulerWithMockDuties();
// last slot of epoch 0
final UInt64 slot = spec.computeStartSlotAtEpoch(UInt64.valueOf(LOOKAHEAD_EPOCHS + 1)).decrement();
when(scheduledDuties.performProductionDuty(slot)).thenReturn(SafeFuture.completedFuture(DutyResult.success(Bytes32.ZERO)));
when(validatorApiChannel.getProposerDuties(ZERO)).thenReturn(SafeFuture.completedFuture(Optional.of(new ProposerDuties(dataStructureUtil.randomBytes32(), emptyList()))));
// epoch 0
dutyScheduler.onSlot(ZERO);
dutyScheduler.onBlockProductionDue(slot);
verify(scheduledDuties).performProductionDuty(slot);
}
use of tech.pegasys.teku.validator.api.ProposerDuties in project teku by ConsenSys.
the class BlockDutySchedulerTest method shouldFetchDutiesForCurrentEpoch.
@Test
public void shouldFetchDutiesForCurrentEpoch() {
createDutySchedulerWithRealDuties();
when(validatorApiChannel.getProposerDuties(any())).thenReturn(completedFuture(Optional.of(new ProposerDuties(dataStructureUtil.randomBytes32(), emptyList()))));
dutyScheduler.onSlot(spec.computeStartSlotAtEpoch(UInt64.ONE));
verify(validatorApiChannel).getProposerDuties(UInt64.ONE);
verify(validatorApiChannel, never()).getProposerDuties(UInt64.valueOf(2));
}
Aggregations