Search in sources :

Example 1 with ProposerDuties

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));
}
Also used : Optional(java.util.Optional) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 2 with ProposerDuties

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));
}
Also used : Optional(java.util.Optional) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 3 with ProposerDuties

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));
}
Also used : Optional(java.util.Optional) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 4 with ProposerDuties

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);
}
Also used : ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 5 with ProposerDuties

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));
}
Also used : ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)10 ProposerDuties (tech.pegasys.teku.validator.api.ProposerDuties)10 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)5 Optional (java.util.Optional)4 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 ProposerDuty (tech.pegasys.teku.validator.api.ProposerDuty)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 BlockProductionDuty (tech.pegasys.teku.validator.client.duties.BlockProductionDuty)2 GetProposerDutiesResponse (tech.pegasys.teku.api.response.v1.validator.GetProposerDutiesResponse)1 BLSPubKey (tech.pegasys.teku.api.schema.BLSPubKey)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1