Search in sources :

Example 11 with ValidatorConfig

use of tech.pegasys.teku.validator.api.ValidatorConfig 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 12 with ValidatorConfig

use of tech.pegasys.teku.validator.api.ValidatorConfig 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 13 with ValidatorConfig

use of tech.pegasys.teku.validator.api.ValidatorConfig in project teku by ConsenSys.

the class ValidatorLoaderTest method shouldNotRemoveExternalValidatorsOnReload.

@Test
void shouldNotRemoveExternalValidatorsOnReload() {
    final PublicKeyLoader publicKeyLoader = mock(PublicKeyLoader.class);
    final List<BLSPublicKey> initialKeys = List.of(PUBLIC_KEY1);
    final String publicKeysUrl = "http://example.com";
    when(publicKeyLoader.getPublicKeys(List.of(publicKeysUrl))).thenReturn(initialKeys);
    final ValidatorConfig config = ValidatorConfig.builder().validatorExternalSignerUrl(SIGNER_URL).validatorExternalSignerPublicKeySources(Collections.singletonList(publicKeysUrl)).validatorExternalSignerSlashingProtectionEnabled(true).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.getPublicKeys()).containsOnly(PUBLIC_KEY1);
    final List<BLSPublicKey> reconfiguredKeys = List.of(PUBLIC_KEY2);
    when(publicKeyLoader.getPublicKeys(List.of(publicKeysUrl))).thenReturn(reconfiguredKeys);
    validatorLoader.loadValidators();
    assertThat(validators.getPublicKeys()).containsExactlyInAnyOrder(PUBLIC_KEY1, PUBLIC_KEY2);
}
Also used : BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 14 with ValidatorConfig

use of tech.pegasys.teku.validator.api.ValidatorConfig in project teku by ConsenSys.

the class ValidatorLoaderTest method shouldReturnErrorIfDeleteOnReadOnlySource.

@Test
void shouldReturnErrorIfDeleteOnReadOnlySource(@TempDir Path tempDir) throws Exception {
    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.empty());
    final DeleteKeyResult result = validatorLoader.deleteLocalMutableValidator(dataStructureUtil.randomPublicKey());
    assertThat(result.getStatus()).isEqualTo(DeletionStatus.ERROR);
    assertThat(result.getMessage().orElse("")).contains("Unable to delete validator");
}
Also used : DeleteKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 15 with ValidatorConfig

use of tech.pegasys.teku.validator.api.ValidatorConfig in project teku by ConsenSys.

the class ExternalSignerIntegrationTest method setup.

@BeforeEach
void setup(final ClientAndServer client) throws MalformedURLException {
    this.client = client;
    final ValidatorConfig config = ValidatorConfig.builder().validatorExternalSignerPublicKeySources(List.of(KEYPAIR.getPublicKey().toString())).validatorExternalSignerUrl(new URL("http://127.0.0.1:" + client.getLocalPort())).validatorExternalSignerTimeout(TIMEOUT).build();
    final HttpClientExternalSignerFactory httpClientExternalSignerFactory = new HttpClientExternalSignerFactory(config);
    externalSigner = new ExternalSigner(spec, httpClientExternalSignerFactory.get(), config.getValidatorExternalSignerUrl(), KEYPAIR.getPublicKey(), TIMEOUT, queue, metricsSystem);
}
Also used : URL(java.net.URL) HttpClientExternalSignerFactory(tech.pegasys.teku.validator.client.loader.HttpClientExternalSignerFactory) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ValidatorConfig (tech.pegasys.teku.validator.api.ValidatorConfig)26 Test (org.junit.jupiter.api.Test)23 Validator (tech.pegasys.teku.validator.client.Validator)10 AbstractBeaconNodeCommandTest (tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)6 SimpleDataDirLayout (tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)4 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)4 URL (java.net.URL)3 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)3 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)3 ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)3 HttpClientExternalSignerFactory (tech.pegasys.teku.validator.client.loader.HttpClientExternalSignerFactory)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 InteropConfig (tech.pegasys.teku.validator.api.InteropConfig)2 PostKeyResult (tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult)2 DeleteKeyResult (tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult)1