use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult in project teku by ConsenSys.
the class ActiveKeyManager method importExternalValidators.
@Override
public List<PostKeyResult> importExternalValidators(final List<ExternalValidator> validators) {
final List<PostKeyResult> importResults = new ArrayList<>();
boolean reloadRequired = false;
for (ExternalValidator v : validators) {
try {
importResults.add(validatorLoader.loadExternalMutableValidator(v.getPublicKey(), v.getUrl()));
if (importResults.get(importResults.size() - 1).getImportStatus() == ImportStatus.IMPORTED) {
reloadRequired = true;
}
} catch (Exception e) {
importResults.add(PostKeyResult.error(e.getMessage()));
}
}
if (reloadRequired) {
validatorTimingChannel.onValidatorsAdded();
}
return importResults;
}
use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult 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"));
}
use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult 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.client.restapi.apis.schema.PostKeyResult in project teku by ConsenSys.
the class PostRemoteKeysTest method validResponse_shouldGiveValidPostKeyResults.
@Test
void validResponse_shouldGiveValidPostKeyResults() throws JsonProcessingException, MalformedURLException {
final PostRemoteKeys endpoint = new PostRemoteKeys(keyManager);
List<ExternalValidator> externalValidators = List.of(new ExternalValidator(BLSTestUtil.randomKeyPair(1).getPublicKey(), Optional.of(new URL("http://host.com"))), new ExternalValidator(BLSTestUtil.randomKeyPair(2).getPublicKey(), Optional.empty()));
final PostRemoteKeysRequest body = new PostRemoteKeysRequest(externalValidators);
when(request.getRequestBody()).thenReturn(body);
List<PostKeyResult> results = List.of(PostKeyResult.success(), PostKeyResult.success());
when(keyManager.importExternalValidators(externalValidators)).thenReturn(results);
endpoint.handle(request);
verify(request).respondOk(results);
}
use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult in project teku by ConsenSys.
the class PostRemoteKeysTest method duplicate_shouldGiveDuplicateResponse.
@Test
void duplicate_shouldGiveDuplicateResponse() throws JsonProcessingException, MalformedURLException {
final PostRemoteKeys endpoint = new PostRemoteKeys(keyManager);
BLSPublicKey publicKey = BLSTestUtil.randomKeyPair(1).getPublicKey();
URL url = new URL("http://host.com");
List<ExternalValidator> externalValidators = List.of(new ExternalValidator(publicKey, Optional.of(url)), new ExternalValidator(publicKey, Optional.of(url)));
final PostRemoteKeysRequest body = new PostRemoteKeysRequest(externalValidators);
when(request.getRequestBody()).thenReturn(body);
List<PostKeyResult> results = List.of(PostKeyResult.success(), PostKeyResult.duplicate());
when(keyManager.importExternalValidators(externalValidators)).thenReturn(results);
endpoint.handle(request);
verify(request).respondOk(results);
}
Aggregations