@Test public void activeValidatorsResponseShouldConformToDefaults() { BeaconState beaconState = dataStructureUtil.randomBeaconState(); BeaconValidators validators = new BeaconValidators( beaconState, true, BeaconStateUtil.get_current_epoch(beaconState), PAGE_SIZE_DEFAULT, PAGE_TOKEN_DEFAULT); int expectedNextPageToken = beaconState.getValidators().size() < PAGE_SIZE_DEFAULT ? 0 : PAGE_TOKEN_DEFAULT + 1; long activeValidatorCount = BeaconValidators.getEffectiveListSize( getValidators(beaconState), true, BeaconStateUtil.compute_epoch_at_slot(beaconState.getSlot())); assertThat(validators.validators.size()) .isEqualTo(Math.min(PAGE_SIZE_DEFAULT, activeValidatorCount)); assertThat(validators.total_size).isEqualTo(activeValidatorCount); assertThat(validators.next_page_token).isEqualTo(expectedNextPageToken); }
public static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch) { if (!activeOnly) { return list.size(); } else { return list.stream().filter(v -> is_active_validator(v, epoch)).count(); } }
BeaconValidators { public static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch) { if (!activeOnly) { return list.size(); } else { return list.stream().filter(v -> is_active_validator(v, epoch)).count(); } } }
BeaconValidators { public static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch) { if (!activeOnly) { return list.size(); } else { return list.stream().filter(v -> is_active_validator(v, epoch)).count(); } } @VisibleForTesting  BeaconValidators(tech.pegasys.teku.datastructures.state.BeaconState state); @VisibleForTesting  BeaconValidators(); @VisibleForTesting  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken);  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state, List<BLSPubKey> filter);  BeaconValidators(
      final BeaconState state, final boolean activeOnly, final int pageSize, final int pageToken);   BeaconValidators(
      final List<Validator> list,
      final List<UInt64> balances,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken); }
BeaconValidators { public static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch) { if (!activeOnly) { return list.size(); } else { return list.stream().filter(v -> is_active_validator(v, epoch)).count(); } } @VisibleForTesting  BeaconValidators(tech.pegasys.teku.datastructures.state.BeaconState state); @VisibleForTesting  BeaconValidators(); @VisibleForTesting  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken);  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state, List<BLSPubKey> filter);  BeaconValidators(
      final BeaconState state, final boolean activeOnly, final int pageSize, final int pageToken);   BeaconValidators(
      final List<Validator> list,
      final List<UInt64> balances,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken); static BeaconValidators emptySet(); static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch); }
BeaconValidators { public static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch) { if (!activeOnly) { return list.size(); } else { return list.stream().filter(v -> is_active_validator(v, epoch)).count(); } } @VisibleForTesting  BeaconValidators(tech.pegasys.teku.datastructures.state.BeaconState state); @VisibleForTesting  BeaconValidators(); @VisibleForTesting  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken);  BeaconValidators(
      tech.pegasys.teku.datastructures.state.BeaconState state, List<BLSPubKey> filter);  BeaconValidators(
      final BeaconState state, final boolean activeOnly, final int pageSize, final int pageToken);   BeaconValidators(
      final List<Validator> list,
      final List<UInt64> balances,
      final boolean activeOnly,
      final UInt64 epoch,
      final int pageSize,
      final int pageToken); static BeaconValidators emptySet(); static long getEffectiveListSize(List<Validator> list, boolean activeOnly, UInt64 epoch); static final int PAGE_SIZE_DEFAULT; static final int PAGE_TOKEN_DEFAULT; final List<ValidatorWithIndex> validators; final Long total_size; final Integer next_page_token; }