use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState in project teku by ConsenSys.
the class Eth1DataCacheTest method smallestDistanceWinsIfNoMajority.
@Test
void smallestDistanceWinsIfNoMajority() {
Eth1Data eth1Data1 = createEth1Data(STATE_DEPOSIT_COUNT);
Eth1Data eth1Data2 = createEth1Data(STATE_DEPOSIT_COUNT);
BeaconState beaconState = createBeaconStateWithVotes(eth1Data1, eth1Data2);
eth1DataCache.onBlockWithDeposit(IN_RANGE_TIMESTAMP_1, eth1Data1);
eth1DataCache.onBlockWithDeposit(IN_RANGE_TIMESTAMP_2, eth1Data2);
assertThat(eth1DataCache.getEth1Vote(beaconState)).isEqualTo(eth1Data1);
}
use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState in project teku by ConsenSys.
the class ValidatorApiHandlerTest method createAttestationData_shouldFailWhenHeadIsOptimistic.
@Test
public void createAttestationData_shouldFailWhenHeadIsOptimistic() {
final UInt64 slot = spec.computeStartSlotAtEpoch(EPOCH).plus(ONE);
when(chainDataClient.getCurrentSlot()).thenReturn(slot);
final BeaconState state = createStateWithActiveValidators(EPOCH_START_SLOT);
final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock(state.getSlot(), state);
final SignedBlockAndState blockAndState = new SignedBlockAndState(block, state);
final SafeFuture<Optional<SignedBlockAndState>> blockAndStateResult = completedFuture(Optional.of(blockAndState));
when(chainDataClient.getSignedBlockAndStateInEffectAtSlot(slot)).thenReturn(blockAndStateResult);
when(forkChoiceTrigger.prepareForAttestationProduction(slot)).thenReturn(SafeFuture.COMPLETE);
when(chainDataClient.isOptimisticBlock(blockAndState.getRoot())).thenReturn(true);
final int committeeIndex = 0;
final SafeFuture<Optional<AttestationData>> result = validatorApiHandler.createAttestationData(slot, committeeIndex);
assertThat(result).isCompletedExceptionally();
assertThatThrownBy(result::get).hasRootCauseInstanceOf(NodeSyncingException.class);
}
use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState in project teku by ConsenSys.
the class ValidatorApiHandlerTest method getSyncCommitteeDuties_shouldNotUseEpochPriorToFork.
@Test
void getSyncCommitteeDuties_shouldNotUseEpochPriorToFork() {
final Spec spec = TestSpecFactory.createMinimalWithAltairForkEpoch(EPOCH);
final ValidatorApiHandler validatorApiHandler = new ValidatorApiHandler(chainDataProvider, chainDataClient, syncStateProvider, blockFactory, blockImportChannel, blockGossipChannel, attestationPool, attestationManager, attestationTopicSubscriptions, activeValidatorTracker, dutyMetrics, performanceTracker, spec, forkChoiceTrigger, forkChoiceNotifier, syncCommitteeMessagePool, syncCommitteeContributionPool, syncCommitteeSubscriptionManager);
// Best state is still in Phase0
final BeaconState state = dataStructureUtil.stateBuilderPhase0().slot(PREVIOUS_EPOCH_START_SLOT.minus(1)).build();
when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH);
when(chainDataClient.getBestState()).thenReturn(Optional.of(SafeFuture.completedFuture(state)));
when(chainDataClient.getStateAtSlotExact(any())).thenReturn(new SafeFuture<>());
final SafeFuture<Optional<SyncCommitteeDuties>> result = validatorApiHandler.getSyncCommitteeDuties(EPOCH, IntList.of(1));
assertThat(result).isNotDone();
// The start of the sync committee period is prior to the fork block so we should use the
// fork block to ensure we actually have sync committees available.
verify(chainDataClient).getStateAtSlotExact(EPOCH_START_SLOT);
}
use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState in project teku by ConsenSys.
the class ValidatorApiHandlerTest method createUnsignedBlock_shouldCreateBlock.
@Test
public void createUnsignedBlock_shouldCreateBlock() throws Exception {
final UInt64 newSlot = UInt64.valueOf(25);
final BeaconState blockSlotState = dataStructureUtil.randomBeaconState(newSlot);
final BLSSignature randaoReveal = dataStructureUtil.randomSignature();
final BeaconBlock createdBlock = dataStructureUtil.randomBeaconBlock(newSlot.longValue());
when(chainDataClient.getStateAtSlotExact(newSlot)).thenReturn(SafeFuture.completedFuture(Optional.of(blockSlotState)));
when(blockFactory.createUnsignedBlock(blockSlotState, newSlot, randaoReveal, Optional.empty())).thenReturn(createdBlock);
final SafeFuture<Optional<BeaconBlock>> result = validatorApiHandler.createUnsignedBlock(newSlot, randaoReveal, Optional.empty());
verify(blockFactory).createUnsignedBlock(blockSlotState, newSlot, randaoReveal, Optional.empty());
assertThat(result).isCompletedWithValue(Optional.of(createdBlock));
}
use of tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState in project teku by ConsenSys.
the class ValidatorApiHandlerTest method getAttestationDuties_shouldAllowOneEpochTolerance.
@Test
public void getAttestationDuties_shouldAllowOneEpochTolerance() {
final BeaconState state = createStateWithActiveValidators();
final BLSPublicKey validator1Key = BLSPublicKey.fromBytesCompressed(state.getValidators().get(1).getPubkeyBytes());
when(chainDataClient.getStateAtSlotExact(PREVIOUS_EPOCH_START_SLOT)).thenReturn(completedFuture(Optional.of(state)));
when(chainDataClient.getCurrentEpoch()).thenReturn(EPOCH.minus(2));
final SafeFuture<Optional<AttesterDuties>> result = validatorApiHandler.getAttestationDuties(EPOCH, IntList.of(1, 32));
final Optional<AttesterDuties> duties = assertCompletedSuccessfully(result);
assertThat(duties.orElseThrow().getDuties()).containsExactly(new AttesterDuty(validator1Key, 1, 4, 0, 1, 1, UInt64.valueOf(108)));
}
Aggregations