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