use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest in project teku by ConsenSys.
the class PostRemoteKeys method handle.
@Override
public void handle(final RestApiRequest request) throws JsonProcessingException {
final PostRemoteKeysRequest body = request.getRequestBody();
if (body.getExternalValidators().isEmpty()) {
request.respondOk(Collections.emptyList());
return;
}
List<ExternalValidator> validators = body.getExternalValidators();
request.respondOk(keyManager.importExternalValidators(validators));
}
use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest in project teku by ConsenSys.
the class ValidatorTypesTest method postRemoteKeysRequest_shouldFormatPostRemoteKeysRequestOptionalUrl.
@SuppressWarnings("unchecked")
@Test
void postRemoteKeysRequest_shouldFormatPostRemoteKeysRequestOptionalUrl() throws Exception {
final BLSPublicKey publicKey1 = dataStructureUtil.randomPublicKey();
final BLSPublicKey publicKey2 = dataStructureUtil.randomPublicKey();
final List<ExternalValidator> externalValidators = List.of(new ExternalValidator(publicKey1, Optional.empty()), new ExternalValidator(publicKey2, Optional.of(new URL("http://host.com"))));
final PostRemoteKeysRequest request = new PostRemoteKeysRequest(externalValidators);
final Map<String, Object> result = JsonTestUtil.parse(JsonUtil.serialize(request, ValidatorTypes.POST_REMOTE_KEYS_REQUEST));
assertThat(result).containsOnlyKeys("remote_keys").isInstanceOf(HashMap.class);
final List<Map<String, Object>> remoteKeys = (List<Map<String, Object>>) result.get("remote_keys");
assertThat(remoteKeys).containsExactly(Map.of("pubkey", publicKey1.toString()), Map.of("pubkey", publicKey2.toString(), "url", new URL("http://host.com").toString()));
}
use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest 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.PostRemoteKeysRequest in project teku by ConsenSys.
the class PostRemoteKeysTest method emptyRequest_shouldGiveEmptySuccess.
@Test
void emptyRequest_shouldGiveEmptySuccess() throws JsonProcessingException {
final PostRemoteKeys endpoint = new PostRemoteKeys(keyManager);
final PostRemoteKeysRequest body = new PostRemoteKeysRequest();
when(request.getRequestBody()).thenReturn(body);
endpoint.handle(request);
verify(request).respondOk(List.of());
}
use of tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest 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