use of tech.pegasys.teku.spec.datastructures.state.Validator in project teku by ConsenSys.
the class ValidatorApiHandlerTest method createStateWithActiveValidators.
private BeaconState createStateWithActiveValidators(final UInt64 slot) {
return dataStructureUtil.randomBeaconState(32).updated(state -> {
state.setSlot(slot);
final SszMutableList<Validator> validators = state.getValidators();
for (int i = 0; i < validators.size(); i++) {
validators.update(i, validator -> validator.withActivation_eligibility_epoch(ZERO).withActivation_epoch(ZERO).withExit_epoch(SpecConfig.FAR_FUTURE_EPOCH).withWithdrawable_epoch(SpecConfig.FAR_FUTURE_EPOCH));
}
});
}
use of tech.pegasys.teku.spec.datastructures.state.Validator in project teku by ConsenSys.
the class BeaconValidatorsTest method getActiveValidatorsCount.
@TestTemplate
public void getActiveValidatorsCount(SpecContext ctx) {
BeaconState beaconState = ctx.getDataStructureUtil().randomBeaconState();
System.out.println(beaconState.hashTreeRoot());
SszList<Validator> allValidators = beaconState.getValidators();
long originalActiveValidatorCount = BeaconValidators.getEffectiveListSize(getValidators(beaconState), true, ctx.getSpec().computeEpochAtSlot(beaconState.getSlot()));
int originalValidatorCount = allValidators.size();
assertThat(originalActiveValidatorCount).isLessThanOrEqualTo(beaconState.getValidators().size());
// create one validator which IS active and add it to the list
Validator v = ctx.getDataStructureUtil().randomValidator().withActivation_eligibility_epoch(UInt64.ZERO).withActivation_epoch(GENESIS_EPOCH);
BeaconState beaconStateW = beaconState.updated(state -> state.getValidators().append(v));
int updatedValidatorCount = beaconStateW.getValidators().size();
long updatedActiveValidatorCount = BeaconValidators.getEffectiveListSize(getValidators(beaconStateW), true, ctx.getSpec().computeEpochAtSlot(beaconStateW.getSlot()));
SszList<Validator> updatedValidators = beaconStateW.getValidators();
assertThat(updatedValidators).contains(v);
assertThat(beaconStateW.getValidators()).contains(v);
assertThat(updatedValidatorCount).isEqualTo(originalValidatorCount + 1);
assertThat(updatedActiveValidatorCount).isLessThanOrEqualTo(updatedValidatorCount);
// same number of non-active validators before and after
assertThat(updatedValidatorCount - updatedActiveValidatorCount).isEqualTo(originalValidatorCount - originalActiveValidatorCount);
}
use of tech.pegasys.teku.spec.datastructures.state.Validator in project teku by ConsenSys.
the class BeaconValidatorsTest method returnRemainderIfEdgeCasePageParams.
@TestTemplate
public void returnRemainderIfEdgeCasePageParams(SpecContext ctx) {
BeaconState beaconState = ctx.getDataStructureUtil().randomBeaconState();
final SszList<Validator> validators = beaconState.getValidators();
final int validatorsSize = validators.size();
final int suppliedPageSizeParam = validatorsSize / 10 - 1;
final int suppliedPageTokenParam = 11;
final int expectedRemainderSize = validatorsSize - (suppliedPageSizeParam * suppliedPageTokenParam);
assertThat(expectedRemainderSize).isLessThan(PAGE_SIZE_DEFAULT);
assertThat(expectedRemainderSize).isGreaterThan(0);
BeaconValidators beaconValidators = new BeaconValidators(beaconState, false, SpecConfig.FAR_FUTURE_EPOCH, suppliedPageSizeParam, suppliedPageTokenParam);
assertThat(beaconValidators.total_size).isEqualTo(beaconState.getValidators().size());
assertThat(beaconValidators.next_page_token).isEqualTo(PAGE_TOKEN_DEFAULT);
assertThat(beaconValidators.validators.size()).isEqualTo(expectedRemainderSize);
}
use of tech.pegasys.teku.spec.datastructures.state.Validator in project teku by ConsenSys.
the class ValidatorResponseTest method status_shouldBeWithdrawalDone.
@Test
void status_shouldBeWithdrawalDone() {
final Validator validator = withdrawalValidator(ZERO, ONE_HUNDRED);
assertThat(ValidatorResponse.getValidatorStatus(ONE_HUNDRED, validator, FAR_FUTURE_EPOCH)).isEqualTo(ValidatorStatus.withdrawal_done);
}
use of tech.pegasys.teku.spec.datastructures.state.Validator in project teku by ConsenSys.
the class ValidatorResponseTest method status_shouldBeActiveOngoing.
@Test
void status_shouldBeActiveOngoing() {
final Validator validator = activeValidator(FAR_FUTURE_EPOCH, false);
assertThat(ValidatorResponse.getValidatorStatus(ZERO, validator, FAR_FUTURE_EPOCH)).isEqualTo(ValidatorStatus.active_ongoing);
}
Aggregations