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);
}
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();
}
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);
}
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);
}
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"));
}
Aggregations