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