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