Search in sources :

Example 1 with BlockProductionDuty

use of tech.pegasys.teku.validator.client.duties.BlockProductionDuty in project teku by ConsenSys.

the class BlockDutySchedulerTest method shouldNotPerformDutiesForSameSlotTwice.

@Test
public void shouldNotPerformDutiesForSameSlotTwice() {
    createDutySchedulerWithRealDuties();
    final UInt64 blockProposerSlot = UInt64.valueOf(5);
    final ProposerDuty validator1Duties = new ProposerDuty(VALIDATOR1_KEY, 5, blockProposerSlot);
    when(validatorApiChannel.getProposerDuties(eq(ZERO))).thenReturn(completedFuture(Optional.of(new ProposerDuties(dataStructureUtil.randomBytes32(), List.of(validator1Duties, new ProposerDuty(dataStructureUtil.randomPublicKey(), 6, UInt64.valueOf(4)))))));
    final BlockProductionDuty blockCreationDuty = mock(BlockProductionDuty.class);
    when(blockCreationDuty.performDuty()).thenReturn(new SafeFuture<>());
    when(blockDutyFactory.createProductionDuty(blockProposerSlot, validator1)).thenReturn(blockCreationDuty);
    // Load duties
    dutyScheduler.onSlot(spec.computeStartSlotAtEpoch(ZERO));
    // Execute
    dutyScheduler.onBlockProductionDue(blockProposerSlot);
    verify(blockCreationDuty).performDuty();
    // Somehow we triggered the same slot again.
    dutyScheduler.onBlockProductionDue(blockProposerSlot);
    // But shouldn't produce another block and get ourselves slashed.
    verifyNoMoreInteractions(blockCreationDuty);
}
Also used : BlockProductionDuty(tech.pegasys.teku.validator.client.duties.BlockProductionDuty) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 2 with BlockProductionDuty

use of tech.pegasys.teku.validator.client.duties.BlockProductionDuty in project teku by ConsenSys.

the class BlockDutySchedulerTest method shouldScheduleBlockProposalDuty.

@Test
public void shouldScheduleBlockProposalDuty() {
    createDutySchedulerWithRealDuties();
    final UInt64 blockProposerSlot = UInt64.valueOf(5);
    final ProposerDuty validator1Duties = new ProposerDuty(VALIDATOR1_KEY, 5, blockProposerSlot);
    when(validatorApiChannel.getProposerDuties(ZERO)).thenReturn(completedFuture(Optional.of(new ProposerDuties(dataStructureUtil.randomBytes32(), List.of(validator1Duties)))));
    final BlockProductionDuty blockCreationDuty = mock(BlockProductionDuty.class);
    when(blockCreationDuty.performDuty()).thenReturn(new SafeFuture<>());
    when(blockDutyFactory.createProductionDuty(blockProposerSlot, validator1)).thenReturn(blockCreationDuty);
    // Load duties
    dutyScheduler.onSlot(spec.computeStartSlotAtEpoch(ZERO));
    // Execute
    dutyScheduler.onBlockProductionDue(blockProposerSlot);
    verify(blockCreationDuty).performDuty();
}
Also used : BlockProductionDuty(tech.pegasys.teku.validator.client.duties.BlockProductionDuty) ProposerDuties(tech.pegasys.teku.validator.api.ProposerDuties) ProposerDuty(tech.pegasys.teku.validator.api.ProposerDuty) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 ProposerDuties (tech.pegasys.teku.validator.api.ProposerDuties)2 ProposerDuty (tech.pegasys.teku.validator.api.ProposerDuty)2 BlockProductionDuty (tech.pegasys.teku.validator.client.duties.BlockProductionDuty)2