Search in sources :

Example 16 with Validator

use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.

the class ValidatorLoaderTest method shouldNotInitializeMutableValidatorsWithoutDirectoryStructure.

@Test
void shouldNotInitializeMutableValidatorsWithoutDirectoryStructure(@TempDir Path tempDir, @TempDir Path tempDirMutable) throws Exception {
    final DataDirLayout dataDirLayout = new SimpleDataDirLayout(tempDirMutable);
    writeKeystore(tempDir);
    final ValidatorConfig config = ValidatorConfig.builder().validatorKeys(List.of(tempDir.toAbsolutePath() + File.pathSeparator + tempDir.toAbsolutePath())).build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.of(dataDirLayout));
    validatorLoader.loadValidators();
    final OwnedValidators validators = validatorLoader.getOwnedValidators();
    assertThat(validators.getValidatorCount()).isEqualTo(1);
    final Validator validator1 = validators.getValidator(PUBLIC_KEY1).orElseThrow();
    assertThat(validator1).isNotNull();
    assertThat(validator1.getPublicKey()).isEqualTo(PUBLIC_KEY1);
    assertThat(validator1.isReadOnly()).isTrue();
}
Also used : SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 17 with Validator

use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.

the class ValidatorLoaderTest method shouldLoadMutableValidatorIfEnabled.

@Test
void shouldLoadMutableValidatorIfEnabled(@TempDir final Path tempDir) throws Exception {
    final ValidatorConfig config = ValidatorConfig.builder().build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.of(new SimpleDataDirLayout(tempDir)));
    validatorLoader.loadValidators();
    final String keystoreString = Resources.toString(Resources.getResource("pbkdf2TestVector.json"), StandardCharsets.UTF_8);
    PostKeyResult result = validatorLoader.loadLocalMutableValidator(KeyStoreLoader.loadFromString(keystoreString), "testpassword", Optional.empty());
    assertThat(result.getImportStatus()).isEqualTo(ImportStatus.IMPORTED);
    final Optional<Validator> validator = validatorLoader.getOwnedValidators().getValidator(PUBLIC_KEY1);
    assertThat(validator).isPresent();
    assertThat(validator.orElseThrow().getSigner()).isInstanceOf(DeletableSigner.class);
}
Also used : SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) PostKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult) Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 18 with Validator

use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.

the class ValidatorLoaderTest method shouldInitializeOnlyLocalValidatorsWhenRestDisabled.

@Test
void shouldInitializeOnlyLocalValidatorsWhenRestDisabled(@TempDir Path tempDir, @TempDir Path tempDirMutable) throws Exception {
    final DataDirLayout dataDirLayout = new SimpleDataDirLayout(tempDirMutable);
    writeKeystore(tempDir);
    writeMutableKeystore(dataDirLayout);
    final ValidatorConfig config = ValidatorConfig.builder().validatorKeys(List.of(tempDir.toAbsolutePath() + File.pathSeparator + tempDir.toAbsolutePath())).build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
    validatorLoader.loadValidators();
    final OwnedValidators validators = validatorLoader.getOwnedValidators();
    assertThat(validators.getValidatorCount()).isEqualTo(1);
    final Validator validator1 = validators.getValidator(PUBLIC_KEY1).orElseThrow();
    assertThat(validator1).isNotNull();
    assertThat(validator1.getPublicKey()).isEqualTo(PUBLIC_KEY1);
    assertThat(validator1.isReadOnly()).isTrue();
}
Also used : SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 19 with Validator

use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.

the class ValidatorTypesTest method listKeysResponse_shouldFormatListOfPublicKeys.

@Test
void listKeysResponse_shouldFormatListOfPublicKeys() throws Exception {
    final List<Validator> keys = List.of(new Validator(dataStructureUtil.randomPublicKey(), NO_OP_SIGNER, Optional::empty, true), new Validator(dataStructureUtil.randomPublicKey(), NO_OP_SIGNER, Optional::empty, false));
    final Map<String, Object> result = JsonTestUtil.parse(JsonUtil.serialize(keys, ValidatorTypes.LIST_KEYS_RESPONSE_TYPE));
    assertThat(result).containsOnlyKeys("data");
    final List<Map<String, Object>> keysList = JsonTestUtil.getList(result, "data");
    assertThat(keysList).hasSize(keys.size());
    for (int i = 0; i < keys.size(); i++) {
        assertThat(keysList.get(i)).containsOnly(entry("validating_pubkey", keys.get(i).getPublicKey().toBytesCompressed().toHexString()), entry("readonly", keys.get(i).isReadOnly()));
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) Validator(tech.pegasys.teku.validator.client.Validator) Test(org.junit.jupiter.api.Test)

Example 20 with Validator

use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.

the class GetKeysTest method shouldListEmpytValidatorKeys.

@Test
void shouldListEmpytValidatorKeys() throws Exception {
    final List<Validator> activeValidatorList = Collections.emptyList();
    when(keyManager.getActiveValidatorKeys()).thenReturn(activeValidatorList);
    final GetKeys endpoint = new GetKeys(keyManager);
    final RestApiRequest request = mock(RestApiRequest.class);
    endpoint.handle(request);
    verify(request).respondOk(activeValidatorList);
}
Also used : RestApiRequest(tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiRequest) Validator(tech.pegasys.teku.validator.client.Validator) Test(org.junit.jupiter.api.Test)

Aggregations

Validator (tech.pegasys.teku.validator.client.Validator)40 Test (org.junit.jupiter.api.Test)32 Optional (java.util.Optional)15 ValidatorConfig (tech.pegasys.teku.validator.api.ValidatorConfig)10 BLSSignature (tech.pegasys.teku.bls.BLSSignature)7 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)7 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)7 List (java.util.List)6 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)6 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)6 ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)6 ArrayList (java.util.ArrayList)5 SimpleDataDirLayout (tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)4 Signer (tech.pegasys.teku.core.signatures.Signer)3 ValidatorSigningRecord (tech.pegasys.teku.data.signingrecord.ValidatorSigningRecord)3 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)3 ValidatorLogger (tech.pegasys.teku.infrastructure.logging.ValidatorLogger)3 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)3 Spec (tech.pegasys.teku.spec.Spec)3 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)3