@Test public void getDuties_WhenFound_ReturnsDuties() { final BLSPublicKey blsPublicKey = dataStructureUtil.randomPublicKey(); final tech.pegasys.teku.api.schema.ValidatorDuties schemaValidatorDuties = new tech.pegasys.teku.api.schema.ValidatorDuties( new BLSPubKey(blsPublicKey), 0, 0, 0, 0, List.of(UInt64.ZERO), UInt64.ZERO); final ValidatorDuties expectedValidatorDuties = ValidatorDuties.withDuties(blsPublicKey, 0, 0, 0, 0, List.of(UInt64.ZERO), UInt64.ZERO); when(apiClient.getDuties(any())).thenReturn(List.of(schemaValidatorDuties)); SafeFuture<Optional<List<ValidatorDuties>>> future = apiHandler.getDuties(UInt64.ONE, List.of(blsPublicKey)); List<ValidatorDuties> validatorDuties = unwrapToValue(future); assertThat(validatorDuties.get(0)) .usingRecursiveComparison() .isEqualTo(expectedValidatorDuties); }
@Override public SafeFuture<Optional<List<ValidatorDuties>>> getDuties( final UInt64 epoch, final Collection<BLSPublicKey> publicKeys) { if (publicKeys.isEmpty()) { return SafeFuture.completedFuture(Optional.of(Collections.emptyList())); } return asyncRunner.runAsync( () -> { final List<BLSPubKey> blsPubKeys = publicKeys.stream().map(BLSPubKey::new).collect(Collectors.toList()); final ValidatorDutiesRequest validatorDutiesRequest = new ValidatorDutiesRequest(epoch, blsPubKeys); final List<ValidatorDuties> validatorDuties = apiClient.getDuties(validatorDutiesRequest).stream() .map(this::mapToApiValidatorDuties) .collect(Collectors.toList()); return Optional.of(validatorDuties); }); }
RemoteValidatorApiHandler implements ValidatorApiChannel { @Override public SafeFuture<Optional<List<ValidatorDuties>>> getDuties( final UInt64 epoch, final Collection<BLSPublicKey> publicKeys) { if (publicKeys.isEmpty()) { return SafeFuture.completedFuture(Optional.of(Collections.emptyList())); } return asyncRunner.runAsync( () -> { final List<BLSPubKey> blsPubKeys = publicKeys.stream().map(BLSPubKey::new).collect(Collectors.toList()); final ValidatorDutiesRequest validatorDutiesRequest = new ValidatorDutiesRequest(epoch, blsPubKeys); final List<ValidatorDuties> validatorDuties = apiClient.getDuties(validatorDutiesRequest).stream() .map(this::mapToApiValidatorDuties) .collect(Collectors.toList()); return Optional.of(validatorDuties); }); } }
RemoteValidatorApiHandler implements ValidatorApiChannel { @Override public SafeFuture<Optional<List<ValidatorDuties>>> getDuties( final UInt64 epoch, final Collection<BLSPublicKey> publicKeys) { if (publicKeys.isEmpty()) { return SafeFuture.completedFuture(Optional.of(Collections.emptyList())); } return asyncRunner.runAsync( () -> { final List<BLSPubKey> blsPubKeys = publicKeys.stream().map(BLSPubKey::new).collect(Collectors.toList()); final ValidatorDutiesRequest validatorDutiesRequest = new ValidatorDutiesRequest(epoch, blsPubKeys); final List<ValidatorDuties> validatorDuties = apiClient.getDuties(validatorDutiesRequest).stream() .map(this::mapToApiValidatorDuties) .collect(Collectors.toList()); return Optional.of(validatorDuties); }); } RemoteValidatorApiHandler(final ServiceConfig config, final AsyncRunner asyncRunner); @VisibleForTesting  RemoteValidatorApiHandler(
      final ValidatorRestApiClient apiClient, final AsyncRunner asyncRunner); }
RemoteValidatorApiHandler implements ValidatorApiChannel { @Override public SafeFuture<Optional<List<ValidatorDuties>>> getDuties( final UInt64 epoch, final Collection<BLSPublicKey> publicKeys) { if (publicKeys.isEmpty()) { return SafeFuture.completedFuture(Optional.of(Collections.emptyList())); } return asyncRunner.runAsync( () -> { final List<BLSPubKey> blsPubKeys = publicKeys.stream().map(BLSPubKey::new).collect(Collectors.toList()); final ValidatorDutiesRequest validatorDutiesRequest = new ValidatorDutiesRequest(epoch, blsPubKeys); final List<ValidatorDuties> validatorDuties = apiClient.getDuties(validatorDutiesRequest).stream() .map(this::mapToApiValidatorDuties) .collect(Collectors.toList()); return Optional.of(validatorDuties); }); } RemoteValidatorApiHandler(final ServiceConfig config, final AsyncRunner asyncRunner); @VisibleForTesting  RemoteValidatorApiHandler(
      final ValidatorRestApiClient apiClient, final AsyncRunner asyncRunner); @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<Attestation>> createUnsignedAttestation(
      final UInt64 slot, final int committeeIndex); @Override void sendSignedAttestation(final Attestation attestation); @Override void sendSignedAttestation(
      final Attestation attestation, final Optional<Integer> validatorIndex); @Override SafeFuture<Optional<BeaconBlock>> createUnsignedBlock(
      final UInt64 slot, final BLSSignature randaoReveal, final Optional<Bytes32> graffiti); @Override void sendSignedBlock(final SignedBeaconBlock block); @Override SafeFuture<Optional<Attestation>> createAggregate(final Bytes32 attestationHashTreeRoot); @Override void sendAggregateAndProof(final SignedAggregateAndProof aggregateAndProof); @Override void subscribeToBeaconCommitteeForAggregation(
      final int committeeIndex, final UInt64 aggregationSlot); @Override void subscribeToPersistentSubnets(final Set<SubnetSubscription> subnetSubscriptions); }
RemoteValidatorApiHandler implements ValidatorApiChannel { @Override public SafeFuture<Optional<List<ValidatorDuties>>> getDuties( final UInt64 epoch, final Collection<BLSPublicKey> publicKeys) { if (publicKeys.isEmpty()) { return SafeFuture.completedFuture(Optional.of(Collections.emptyList())); } return asyncRunner.runAsync( () -> { final List<BLSPubKey> blsPubKeys = publicKeys.stream().map(BLSPubKey::new).collect(Collectors.toList()); final ValidatorDutiesRequest validatorDutiesRequest = new ValidatorDutiesRequest(epoch, blsPubKeys); final List<ValidatorDuties> validatorDuties = apiClient.getDuties(validatorDutiesRequest).stream() .map(this::mapToApiValidatorDuties) .collect(Collectors.toList()); return Optional.of(validatorDuties); }); } RemoteValidatorApiHandler(final ServiceConfig config, final AsyncRunner asyncRunner); @VisibleForTesting  RemoteValidatorApiHandler(
      final ValidatorRestApiClient apiClient, final AsyncRunner asyncRunner); @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<Attestation>> createUnsignedAttestation(
      final UInt64 slot, final int committeeIndex); @Override void sendSignedAttestation(final Attestation attestation); @Override void sendSignedAttestation(
      final Attestation attestation, final Optional<Integer> validatorIndex); @Override SafeFuture<Optional<BeaconBlock>> createUnsignedBlock(
      final UInt64 slot, final BLSSignature randaoReveal, final Optional<Bytes32> graffiti); @Override void sendSignedBlock(final SignedBeaconBlock block); @Override SafeFuture<Optional<Attestation>> createAggregate(final Bytes32 attestationHashTreeRoot); @Override void sendAggregateAndProof(final SignedAggregateAndProof aggregateAndProof); @Override void subscribeToBeaconCommitteeForAggregation(
      final int committeeIndex, final UInt64 aggregationSlot); @Override void subscribeToPersistentSubnets(final Set<SubnetSubscription> subnetSubscriptions);  }