@Test public void createUnsignedBlock_shouldCreateBlock() throws Exception { final UInt64 newSlot = UInt64.valueOf(25); final Bytes32 blockRoot = dataStructureUtil.randomBytes32(); final BeaconState previousState = dataStructureUtil.randomBeaconState(); final BeaconBlockAndState previousBlockAndState = dataStructureUtil.randomBlockAndState(previousState.getSlot(), previousState); final BLSSignature randaoReveal = dataStructureUtil.randomSignature(); final BeaconBlock createdBlock = dataStructureUtil.randomBeaconBlock(newSlot.longValue()); when(chainDataClient.getBestBlockRoot()).thenReturn(Optional.of(blockRoot)); when(chainDataClient.getHeadSlot()).thenReturn(UInt64.valueOf(24)); when(chainDataClient.getBlockAndStateInEffectAtSlot(newSlot.minus(ONE))) .thenReturn(SafeFuture.completedFuture(Optional.of(previousBlockAndState))); when(blockFactory.createUnsignedBlock( previousState, previousBlockAndState.getBlock(), newSlot, randaoReveal, Optional.empty())) .thenReturn(createdBlock); final SafeFuture<Optional<BeaconBlock>> result = validatorApiHandler.createUnsignedBlock(newSlot, randaoReveal, Optional.empty()); assertThat(result).isCompletedWithValue(Optional.of(createdBlock)); }
@Override public SafeFuture<Optional<BeaconBlock>> createUnsignedBlock( final UInt64 slot, final BLSSignature randaoReveal, final Optional<Bytes32> graffiti) { if (isSyncActive()) { return NodeSyncingException.failedFuture(); } return createFromBlockAndState( slot.minus(UInt64.ONE), blockAndState -> blockFactory.createUnsignedBlock( blockAndState.getState(), blockAndState.getBlock(), slot, randaoReveal, graffiti)); }
ValidatorApiHandler implements ValidatorApiChannel { @Override public SafeFuture<Optional<BeaconBlock>> createUnsignedBlock( final UInt64 slot, final BLSSignature randaoReveal, final Optional<Bytes32> graffiti) { if (isSyncActive()) { return NodeSyncingException.failedFuture(); } return createFromBlockAndState( slot.minus(UInt64.ONE), blockAndState -> blockFactory.createUnsignedBlock( blockAndState.getState(), blockAndState.getBlock(), slot, randaoReveal, graffiti)); } }
ValidatorApiHandler implements ValidatorApiChannel { @Override public SafeFuture<Optional<BeaconBlock>> createUnsignedBlock( final UInt64 slot, final BLSSignature randaoReveal, final Optional<Bytes32> graffiti) { if (isSyncActive()) { return NodeSyncingException.failedFuture(); } return createFromBlockAndState( slot.minus(UInt64.ONE), blockAndState -> blockFactory.createUnsignedBlock( blockAndState.getState(), blockAndState.getBlock(), slot, randaoReveal, graffiti)); } ValidatorApiHandler(
      final CombinedChainDataClient combinedChainDataClient,
      final SyncStateTracker syncStateTracker,
      final StateTransition stateTransition,
      final BlockFactory blockFactory,
      final AggregatingAttestationPool attestationPool,
      final AttestationManager attestationManager,
      final AttestationTopicSubscriber attestationTopicSubscriber,
      final EventBus eventBus,
      final DutyMetrics dutyMetrics,
      final PerformanceTracker performanceTracker); }
ValidatorApiHandler implements ValidatorApiChannel { @Override public SafeFuture<Optional<BeaconBlock>> createUnsignedBlock( final UInt64 slot, final BLSSignature randaoReveal, final Optional<Bytes32> graffiti) { if (isSyncActive()) { return NodeSyncingException.failedFuture(); } return createFromBlockAndState( slot.minus(UInt64.ONE), blockAndState -> blockFactory.createUnsignedBlock( blockAndState.getState(), blockAndState.getBlock(), slot, randaoReveal, graffiti)); } ValidatorApiHandler(
      final CombinedChainDataClient combinedChainDataClient,
      final SyncStateTracker syncStateTracker,
      final StateTransition stateTransition,
      final BlockFactory blockFactory,
      final AggregatingAttestationPool attestationPool,
      final AttestationManager attestationManager,
      final AttestationTopicSubscriber attestationTopicSubscriber,
      final EventBus eventBus,
      final DutyMetrics dutyMetrics,
      final PerformanceTracker performanceTracker); @Override SafeFuture<Optional<ForkInfo>> getForkInfo(); @Override SafeFuture<Optional<UInt64>> getGenesisTime(); @Override SafeFuture<Optional<List<ValidatorDuties>>> getDuties(
      final UInt64 epoch, final Collection<BLSPublicKey> publicKeys); @Override SafeFuture<Optional<List<AttesterDuties>>> getAttestationDuties(
      final UInt64 epoch, final Collection<Integer> validatorIndexes); @Override SafeFuture<Optional<List<ProposerDuties>>> getProposerDuties(final UInt64 epoch); @Override SafeFuture<Optional<BeaconBlock>> createUnsignedBlock(
      final UInt64 slot, final BLSSignature randaoReveal, final Optional<Bytes32> graffiti); @Override SafeFuture<Optional<Attestation>> createUnsignedAttestation(
      final UInt64 slot, final int committeeIndex); @Override SafeFuture<Optional<Attestation>> createAggregate(final Bytes32 attestationHashTreeRoot); @Override void subscribeToBeaconCommitteeForAggregation(
      final int committeeIndex, final UInt64 aggregationSlot); @Override void subscribeToPersistentSubnets(Set<SubnetSubscription> subnetSubscriptions); @Override void sendSignedAttestation(
      final Attestation attestation, final Optional<Integer> expectedValidatorIndex); @Override void sendSignedAttestation(final Attestation attestation); @Override void sendAggregateAndProof(final SignedAggregateAndProof aggregateAndProof); @Override void sendSignedBlock(final SignedBeaconBlock block); }
ValidatorApiHandler implements ValidatorApiChannel { @Override public SafeFuture<Optional<BeaconBlock>> createUnsignedBlock( final UInt64 slot, final BLSSignature randaoReveal, final Optional<Bytes32> graffiti) { if (isSyncActive()) { return NodeSyncingException.failedFuture(); } return createFromBlockAndState( slot.minus(UInt64.ONE), blockAndState -> blockFactory.createUnsignedBlock( blockAndState.getState(), blockAndState.getBlock(), slot, randaoReveal, graffiti)); } ValidatorApiHandler(
      final CombinedChainDataClient combinedChainDataClient,
      final SyncStateTracker syncStateTracker,
      final StateTransition stateTransition,
      final BlockFactory blockFactory,
      final AggregatingAttestationPool attestationPool,
      final AttestationManager attestationManager,
      final AttestationTopicSubscriber attestationTopicSubscriber,
      final EventBus eventBus,
      final DutyMetrics dutyMetrics,
      final PerformanceTracker performanceTracker); @Override SafeFuture<Optional<ForkInfo>> getForkInfo(); @Override SafeFuture<Optional<UInt64>> getGenesisTime(); @Override SafeFuture<Optional<List<ValidatorDuties>>> getDuties(
      final UInt64 epoch, final Collection<BLSPublicKey> publicKeys); @Override SafeFuture<Optional<List<AttesterDuties>>> getAttestationDuties(
      final UInt64 epoch, final Collection<Integer> validatorIndexes); @Override SafeFuture<Optional<List<ProposerDuties>>> getProposerDuties(final UInt64 epoch); @Override SafeFuture<Optional<BeaconBlock>> createUnsignedBlock(
      final UInt64 slot, final BLSSignature randaoReveal, final Optional<Bytes32> graffiti); @Override SafeFuture<Optional<Attestation>> createUnsignedAttestation(
      final UInt64 slot, final int committeeIndex); @Override SafeFuture<Optional<Attestation>> createAggregate(final Bytes32 attestationHashTreeRoot); @Override void subscribeToBeaconCommitteeForAggregation(
      final int committeeIndex, final UInt64 aggregationSlot); @Override void subscribeToPersistentSubnets(Set<SubnetSubscription> subnetSubscriptions); @Override void sendSignedAttestation(
      final Attestation attestation, final Optional<Integer> expectedValidatorIndex); @Override void sendSignedAttestation(final Attestation attestation); @Override void sendAggregateAndProof(final SignedAggregateAndProof aggregateAndProof); @Override void sendSignedBlock(final SignedBeaconBlock block);  }