@Test public void submitSignedBlock_shouldReturn500ForInternalError() throws ExecutionException, InterruptedException { final SignedBeaconBlock internalSignedBeaconBlock = dataStructureUtil.randomSignedBeaconBlock(1); final tech.pegasys.teku.api.schema.SignedBeaconBlock signedBeaconBlock = new tech.pegasys.teku.api.schema.SignedBeaconBlock(internalSignedBeaconBlock); final SafeFuture<BlockImportResult> failImportResult = SafeFuture.completedFuture( new FailedBlockImportResult(FailureReason.INTERNAL_ERROR, Optional.empty())); when(blockImporter.importBlock(any())).thenReturn(failImportResult); final SafeFuture<ValidatorBlockResult> validatorBlockResultSafeFuture = provider.submitSignedBlock(signedBeaconBlock); assertThat(validatorBlockResultSafeFuture.get().getResponseCode()).isEqualTo(500); }
public SafeFuture<ValidatorBlockResult> submitSignedBlock( final SignedBeaconBlock signedBeaconBlock) { return blockImporter .importBlock(signedBeaconBlock.asInternalSignedBeaconBlock()) .thenApply( blockImportResult -> { int responseCode; Bytes32 hashRoot = null; if (!blockImportResult.isSuccessful()) { if (blockImportResult.getFailureReason() == BlockImportResult.FailureReason.INTERNAL_ERROR) { responseCode = 500; } else { responseCode = 202; } } else { responseCode = 200; hashRoot = blockImportResult.getBlock().getMessage().hash_tree_root(); } return new ValidatorBlockResult( responseCode, blockImportResult.getFailureCause(), Optional.ofNullable(hashRoot)); }); }
ValidatorDataProvider { public SafeFuture<ValidatorBlockResult> submitSignedBlock( final SignedBeaconBlock signedBeaconBlock) { return blockImporter .importBlock(signedBeaconBlock.asInternalSignedBeaconBlock()) .thenApply( blockImportResult -> { int responseCode; Bytes32 hashRoot = null; if (!blockImportResult.isSuccessful()) { if (blockImportResult.getFailureReason() == BlockImportResult.FailureReason.INTERNAL_ERROR) { responseCode = 500; } else { responseCode = 202; } } else { responseCode = 200; hashRoot = blockImportResult.getBlock().getMessage().hash_tree_root(); } return new ValidatorBlockResult( responseCode, blockImportResult.getFailureCause(), Optional.ofNullable(hashRoot)); }); } }
ValidatorDataProvider { public SafeFuture<ValidatorBlockResult> submitSignedBlock( final SignedBeaconBlock signedBeaconBlock) { return blockImporter .importBlock(signedBeaconBlock.asInternalSignedBeaconBlock()) .thenApply( blockImportResult -> { int responseCode; Bytes32 hashRoot = null; if (!blockImportResult.isSuccessful()) { if (blockImportResult.getFailureReason() == BlockImportResult.FailureReason.INTERNAL_ERROR) { responseCode = 500; } else { responseCode = 202; } } else { responseCode = 200; hashRoot = blockImportResult.getBlock().getMessage().hash_tree_root(); } return new ValidatorBlockResult( responseCode, blockImportResult.getFailureCause(), Optional.ofNullable(hashRoot)); }); } ValidatorDataProvider(
      final ValidatorApiChannel validatorApiChannel,
      final BlockImporter blockImporter,
      final CombinedChainDataClient combinedChainDataClient); }
ValidatorDataProvider { public SafeFuture<ValidatorBlockResult> submitSignedBlock( final SignedBeaconBlock signedBeaconBlock) { return blockImporter .importBlock(signedBeaconBlock.asInternalSignedBeaconBlock()) .thenApply( blockImportResult -> { int responseCode; Bytes32 hashRoot = null; if (!blockImportResult.isSuccessful()) { if (blockImportResult.getFailureReason() == BlockImportResult.FailureReason.INTERNAL_ERROR) { responseCode = 500; } else { responseCode = 202; } } else { responseCode = 200; hashRoot = blockImportResult.getBlock().getMessage().hash_tree_root(); } return new ValidatorBlockResult( responseCode, blockImportResult.getFailureCause(), Optional.ofNullable(hashRoot)); }); } ValidatorDataProvider(
      final ValidatorApiChannel validatorApiChannel,
      final BlockImporter blockImporter,
      final CombinedChainDataClient combinedChainDataClient); boolean isStoreAvailable(); boolean isEpochFinalized(final UInt64 epoch); SafeFuture<Optional<BeaconBlock>> getUnsignedBeaconBlockAtSlot(
      UInt64 slot, BLSSignature randao, Optional<Bytes32> graffiti); SafeFuture<Optional<Attestation>> createUnsignedAttestationAtSlot(
      UInt64 slot, int committeeIndex); SafeFuture<Optional<List<ValidatorDuties>>> getValidatorDutiesByRequest(
      final ValidatorDutiesRequest validatorDutiesRequest); void submitAttestation(Attestation attestation); SafeFuture<ValidatorBlockResult> submitSignedBlock(
      final SignedBeaconBlock signedBeaconBlock); SafeFuture<Optional<Attestation>> createAggregate(final Bytes32 attestationHashTreeRoot); void sendAggregateAndProof(SignedAggregateAndProof aggregateAndProof); void subscribeToBeaconCommitteeForAggregation(
      final SubscribeToBeaconCommitteeRequest request); void subscribeToPersistentSubnets(final List<SubnetSubscription> subnetSubscriptions); SafeFuture<Optional<List<AttesterDuty>>> getAttesterDuties(
      final UInt64 epoch, final List<Integer> indexes); SafeFuture<Optional<List<ProposerDuty>>> getProposerDuties(final UInt64 epoch); }
ValidatorDataProvider { public SafeFuture<ValidatorBlockResult> submitSignedBlock( final SignedBeaconBlock signedBeaconBlock) { return blockImporter .importBlock(signedBeaconBlock.asInternalSignedBeaconBlock()) .thenApply( blockImportResult -> { int responseCode; Bytes32 hashRoot = null; if (!blockImportResult.isSuccessful()) { if (blockImportResult.getFailureReason() == BlockImportResult.FailureReason.INTERNAL_ERROR) { responseCode = 500; } else { responseCode = 202; } } else { responseCode = 200; hashRoot = blockImportResult.getBlock().getMessage().hash_tree_root(); } return new ValidatorBlockResult( responseCode, blockImportResult.getFailureCause(), Optional.ofNullable(hashRoot)); }); } ValidatorDataProvider(
      final ValidatorApiChannel validatorApiChannel,
      final BlockImporter blockImporter,
      final CombinedChainDataClient combinedChainDataClient); boolean isStoreAvailable(); boolean isEpochFinalized(final UInt64 epoch); SafeFuture<Optional<BeaconBlock>> getUnsignedBeaconBlockAtSlot(
      UInt64 slot, BLSSignature randao, Optional<Bytes32> graffiti); SafeFuture<Optional<Attestation>> createUnsignedAttestationAtSlot(
      UInt64 slot, int committeeIndex); SafeFuture<Optional<List<ValidatorDuties>>> getValidatorDutiesByRequest(
      final ValidatorDutiesRequest validatorDutiesRequest); void submitAttestation(Attestation attestation); SafeFuture<ValidatorBlockResult> submitSignedBlock(
      final SignedBeaconBlock signedBeaconBlock); SafeFuture<Optional<Attestation>> createAggregate(final Bytes32 attestationHashTreeRoot); void sendAggregateAndProof(SignedAggregateAndProof aggregateAndProof); void subscribeToBeaconCommitteeForAggregation(
      final SubscribeToBeaconCommitteeRequest request); void subscribeToPersistentSubnets(final List<SubnetSubscription> subnetSubscriptions); SafeFuture<Optional<List<AttesterDuty>>> getAttesterDuties(
      final UInt64 epoch, final List<Integer> indexes); SafeFuture<Optional<List<ProposerDuty>>> getProposerDuties(final UInt64 epoch); static final String CANNOT_PRODUCE_FAR_FUTURE_BLOCK; static final String CANNOT_PRODUCE_HISTORIC_BLOCK; static final String NO_SLOT_PROVIDED; static final String NO_RANDAO_PROVIDED; }