Search in sources :

Example 1 with SignedVoluntaryExit

use of tech.pegasys.teku.api.schema.SignedVoluntaryExit in project teku by ConsenSys.

the class PostVoluntaryExitIntegrationTest method shouldReturnServerErrorWhenUnexpectedErrorHappens.

@Test
public void shouldReturnServerErrorWhenUnexpectedErrorHappens() throws Exception {
    final tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit signedVoluntaryExit = dataStructureUtil.randomSignedVoluntaryExit();
    final SignedVoluntaryExit schemaExit = new SignedVoluntaryExit(signedVoluntaryExit);
    doThrow(new RuntimeException()).when(voluntaryExitPool).add(signedVoluntaryExit);
    Response response = post(PostVoluntaryExit.ROUTE, jsonProvider.objectToJSON(schemaExit));
    assertThat(response.code()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
}
Also used : Response(okhttp3.Response) SignedVoluntaryExit(tech.pegasys.teku.api.schema.SignedVoluntaryExit) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 2 with SignedVoluntaryExit

use of tech.pegasys.teku.api.schema.SignedVoluntaryExit in project teku by ConsenSys.

the class PostVoluntaryExitTest method shouldReturnBadRequest_ifVoluntaryExitInvalid.

@Test
void shouldReturnBadRequest_ifVoluntaryExitInvalid() throws Exception {
    final SignedVoluntaryExit exit = new SignedVoluntaryExit(dataStructureUtil.randomSignedVoluntaryExit());
    when(context.body()).thenReturn(jsonProvider.objectToJSON(exit));
    when(provider.postVoluntaryExit(exit)).thenReturn(SafeFuture.completedFuture(InternalValidationResult.reject("Oh dear")));
    handler.handle(context);
    verify(provider).postVoluntaryExit(exit);
    verify(context).status(SC_BAD_REQUEST);
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.api.schema.SignedVoluntaryExit) Test(org.junit.jupiter.api.Test)

Example 3 with SignedVoluntaryExit

use of tech.pegasys.teku.api.schema.SignedVoluntaryExit in project teku by ConsenSys.

the class VoluntaryExitCommand method submitExitForValidator.

private void submitExitForValidator(final BLSPublicKey publicKey, final int validatorIndex) {
    try {
        final ForkInfo forkInfo = new ForkInfo(fork, genesisRoot);
        final VoluntaryExit message = new VoluntaryExit(epoch, UInt64.valueOf(validatorIndex));
        final BLSSignature signature = validators.getValidator(publicKey).orElseThrow().getSigner().signVoluntaryExit(message, forkInfo).join();
        apiClient.sendVoluntaryExit(new SignedVoluntaryExit(message, signature));
        SUB_COMMAND_LOG.display("Exit for validator " + publicKey.toAbbreviatedString() + " submitted.");
    } catch (IllegalArgumentException ex) {
        SUB_COMMAND_LOG.error("Failed to submit exit for validator " + publicKey.toAbbreviatedString());
        SUB_COMMAND_LOG.error(ex.getMessage());
    }
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.api.schema.SignedVoluntaryExit) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) SignedVoluntaryExit(tech.pegasys.teku.api.schema.SignedVoluntaryExit) VoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.VoluntaryExit) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Example 4 with SignedVoluntaryExit

use of tech.pegasys.teku.api.schema.SignedVoluntaryExit in project teku by ConsenSys.

the class PostVoluntaryExitTest method shouldBeAbleToSubmitSlashing.

@Test
void shouldBeAbleToSubmitSlashing() throws Exception {
    final SignedVoluntaryExit exit = new SignedVoluntaryExit(dataStructureUtil.randomSignedVoluntaryExit());
    when(context.body()).thenReturn(jsonProvider.objectToJSON(exit));
    when(provider.postVoluntaryExit(exit)).thenReturn(SafeFuture.completedFuture(InternalValidationResult.ACCEPT));
    handler.handle(context);
    verify(provider).postVoluntaryExit(exit);
    verify(context).status(SC_OK);
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.api.schema.SignedVoluntaryExit) Test(org.junit.jupiter.api.Test)

Example 5 with SignedVoluntaryExit

use of tech.pegasys.teku.api.schema.SignedVoluntaryExit in project teku by ConsenSys.

the class EventSubscriptionManagerTest method shouldPropagateVoluntaryExit.

@Test
void shouldPropagateVoluntaryExit() throws IOException {
    when(req.getQueryString()).thenReturn("&topics=voluntary_exit");
    manager.registerClient(client1);
    triggerVoluntaryExitEvent();
    final String eventString = outputStream.getString();
    assertThat(eventString).contains("event: voluntary_exit\n");
    final SignedVoluntaryExit event = jsonProvider.jsonToObject(eventString.substring(eventString.indexOf("{")), SignedVoluntaryExit.class);
    assertThat(event).isEqualTo(sampleVoluntaryExit);
}
Also used : SignedVoluntaryExit(tech.pegasys.teku.api.schema.SignedVoluntaryExit) Test(org.junit.jupiter.api.Test)

Aggregations

SignedVoluntaryExit (tech.pegasys.teku.api.schema.SignedVoluntaryExit)9 Test (org.junit.jupiter.api.Test)6 Response (okhttp3.Response)2 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)2 Context (io.javalin.http.Context)1 HttpMethod (io.javalin.plugin.openapi.annotations.HttpMethod)1 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)1 OpenApiContent (io.javalin.plugin.openapi.annotations.OpenApiContent)1 OpenApiRequestBody (io.javalin.plugin.openapi.annotations.OpenApiRequestBody)1 OpenApiResponse (io.javalin.plugin.openapi.annotations.OpenApiResponse)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 DataProvider (tech.pegasys.teku.api.DataProvider)1 NodeDataProvider (tech.pegasys.teku.api.NodeDataProvider)1 AbstractHandler (tech.pegasys.teku.beaconrestapi.handlers.AbstractHandler)1 BadRequest (tech.pegasys.teku.beaconrestapi.schema.BadRequest)1 BLSSignature (tech.pegasys.teku.bls.BLSSignature)1 SC_BAD_REQUEST (tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST)1