Search in sources :

Example 6 with ValidatorConfig

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

the class ValidatorLoaderTest method shouldLoadAdditionalLocalValidatorsOnReload.

@Test
void shouldLoadAdditionalLocalValidatorsOnReload(@TempDir final Path tempDir) throws Exception {
    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());
    // No validators initially
    validatorLoader.loadValidators();
    final OwnedValidators validators = validatorLoader.getOwnedValidators();
    assertThat(validators.getPublicKeys()).isEmpty();
    // Then we add one and reload
    writeKeystore(tempDir);
    validatorLoader.loadValidators();
    assertThat(validators.getPublicKeys()).containsExactlyInAnyOrder(PUBLIC_KEY1);
}
Also used : ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 7 with ValidatorConfig

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

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

the class ValidatorLoaderTest method shouldLoadAdditionalExternalValidatorsOnReload.

@Test
void shouldLoadAdditionalExternalValidatorsOnReload() {
    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_KEY1, 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 9 with ValidatorConfig

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

the class ValidatorLoaderTest method initializeInteropValidatorsWhenInteropIsEnabled.

@Test
void initializeInteropValidatorsWhenInteropIsEnabled() {
    final int ownedValidatorCount = 10;
    final InteropConfig interopConfig = InteropConfig.builder().specProvider(spec).interopEnabled(true).interopOwnedValidatorCount(ownedValidatorCount).build();
    final ValidatorConfig config = ValidatorConfig.builder().build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, interopConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
    validatorLoader.loadValidators();
    final OwnedValidators validators = validatorLoader.getOwnedValidators();
    assertThat(validators.getValidatorCount()).isEqualTo(ownedValidatorCount);
}
Also used : InteropConfig(tech.pegasys.teku.validator.api.InteropConfig) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 10 with ValidatorConfig

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

the class ValidatorLoaderTest method shouldNotLoadMutableValidatorIfNotEnabled.

@Test
void shouldNotLoadMutableValidatorIfNotEnabled() {
    final ValidatorConfig config = ValidatorConfig.builder().build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
    validatorLoader.loadValidators();
    final PostKeyResult result = validatorLoader.loadLocalMutableValidator(null, "", Optional.empty());
    assertThat(result).isEqualTo(PostKeyResult.error("Not able to add validator"));
}
Also used : PostKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

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