Search in sources :

Example 1 with PostRemoteKeysRequest

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));
}
Also used : ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) PostRemoteKeysRequest(tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest)

Example 2 with PostRemoteKeysRequest

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()));
}
Also used : ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) PostRemoteKeysRequest(tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest) List(java.util.List) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 3 with PostRemoteKeysRequest

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);
}
Also used : ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) PostKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult) PostRemoteKeysRequest(tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 4 with PostRemoteKeysRequest

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());
}
Also used : PostRemoteKeysRequest(tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest) Test(org.junit.jupiter.api.Test)

Example 5 with PostRemoteKeysRequest

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);
}
Also used : ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) PostKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult) PostRemoteKeysRequest(tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Aggregations

PostRemoteKeysRequest (tech.pegasys.teku.validator.client.restapi.apis.schema.PostRemoteKeysRequest)5 Test (org.junit.jupiter.api.Test)4 ExternalValidator (tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator)4 URL (java.net.URL)3 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)2 PostKeyResult (tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1