Search in sources :

Example 1 with Validator

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));
        }
    });
}
Also used : Validator(tech.pegasys.teku.spec.datastructures.state.Validator) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint)

Example 2 with Validator

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);
}
Also used : Validator(tech.pegasys.teku.spec.datastructures.state.Validator) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 3 with Validator

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);
}
Also used : Validator(tech.pegasys.teku.spec.datastructures.state.Validator) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 4 with Validator

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);
}
Also used : Validator(tech.pegasys.teku.spec.datastructures.state.Validator) Test(org.junit.jupiter.api.Test)

Example 5 with Validator

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);
}
Also used : Validator(tech.pegasys.teku.spec.datastructures.state.Validator) Test(org.junit.jupiter.api.Test)

Aggregations

Validator (tech.pegasys.teku.spec.datastructures.state.Validator)45 Test (org.junit.jupiter.api.Test)21 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)19 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 List (java.util.List)5 Bytes32 (org.apache.tuweni.bytes.Bytes32)5 SpecConfig (tech.pegasys.teku.spec.config.SpecConfig)5 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)5 ArrayList (java.util.ArrayList)4 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)4 SszList (tech.pegasys.teku.infrastructure.ssz.SszList)4 DepositData (tech.pegasys.teku.spec.datastructures.operations.DepositData)4 BeaconStateAccessors (tech.pegasys.teku.spec.logic.common.helpers.BeaconStateAccessors)4 TestTemplate (org.junit.jupiter.api.TestTemplate)3 MutableBeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState)3 MiscHelpers (tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers)3 Predicates (tech.pegasys.teku.spec.logic.common.helpers.Predicates)3 OperationValidator (tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator)3 BeaconStateUtil (tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil)3