@Test public void shouldHandleFutureEpoch() throws Exception { final GetCommittees handler = new GetCommittees(provider, jsonProvider); final UInt64 futureEpoch = epoch.plus(UInt64.ONE); final UInt64 epochSlot = compute_start_slot_at_epoch(futureEpoch); when(context.queryParamMap()).thenReturn(Map.of(EPOCH, List.of(futureEpoch.toString()))); when(provider.isStoreAvailable()).thenReturn(true); when(provider.isFinalized(epochSlot)).thenReturn(false); when(provider.getCommitteesAtEpoch(futureEpoch)) .thenReturn(SafeFuture.completedFuture(Optional.empty())); handler.handle(context); verify(context).result(args.capture()); verify(context).header(Header.CACHE_CONTROL, CACHE_NONE); verify(provider).getCommitteesAtEpoch(futureEpoch); SafeFuture<String> future = args.getValue(); verify(context).status(SC_NOT_FOUND); assertThat(future.get()).isNull(); }
@OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get the committee assignments for an epoch.", tags = {TAG_BEACON}, queryParams = { @OpenApiParam(name = EPOCH, description = EPOCH_QUERY_DESCRIPTION, required = true), }, description = "Returns committee assignments for each slot in a specified epoch.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = Committee.class, isArray = true)), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Missing a query parameter"), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_INTERNAL_ERROR) }) @Override public void handle(Context ctx) throws Exception { try { UInt64 epoch = getParameterValueAsEpoch(ctx.queryParamMap(), EPOCH); final SafeFuture<Optional<List<Committee>>> future = provider.getCommitteesAtEpoch(epoch); UInt64 slot = BeaconStateUtil.compute_start_slot_at_epoch(epoch); ctx.header(Header.CACHE_CONTROL, getMaxAgeForSlot(provider, slot)); if (provider.isFinalized(slot)) { handlePossiblyGoneResult(ctx, future); } else { handlePossiblyMissingResult(ctx, future); } } catch (final IllegalArgumentException e) { ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); ctx.status(SC_BAD_REQUEST); } }
GetCommittees extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get the committee assignments for an epoch.", tags = {TAG_BEACON}, queryParams = { @OpenApiParam(name = EPOCH, description = EPOCH_QUERY_DESCRIPTION, required = true), }, description = "Returns committee assignments for each slot in a specified epoch.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = Committee.class, isArray = true)), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Missing a query parameter"), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_INTERNAL_ERROR) }) @Override public void handle(Context ctx) throws Exception { try { UInt64 epoch = getParameterValueAsEpoch(ctx.queryParamMap(), EPOCH); final SafeFuture<Optional<List<Committee>>> future = provider.getCommitteesAtEpoch(epoch); UInt64 slot = BeaconStateUtil.compute_start_slot_at_epoch(epoch); ctx.header(Header.CACHE_CONTROL, getMaxAgeForSlot(provider, slot)); if (provider.isFinalized(slot)) { handlePossiblyGoneResult(ctx, future); } else { handlePossiblyMissingResult(ctx, future); } } catch (final IllegalArgumentException e) { ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); ctx.status(SC_BAD_REQUEST); } } }
GetCommittees extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get the committee assignments for an epoch.", tags = {TAG_BEACON}, queryParams = { @OpenApiParam(name = EPOCH, description = EPOCH_QUERY_DESCRIPTION, required = true), }, description = "Returns committee assignments for each slot in a specified epoch.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = Committee.class, isArray = true)), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Missing a query parameter"), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_INTERNAL_ERROR) }) @Override public void handle(Context ctx) throws Exception { try { UInt64 epoch = getParameterValueAsEpoch(ctx.queryParamMap(), EPOCH); final SafeFuture<Optional<List<Committee>>> future = provider.getCommitteesAtEpoch(epoch); UInt64 slot = BeaconStateUtil.compute_start_slot_at_epoch(epoch); ctx.header(Header.CACHE_CONTROL, getMaxAgeForSlot(provider, slot)); if (provider.isFinalized(slot)) { handlePossiblyGoneResult(ctx, future); } else { handlePossiblyMissingResult(ctx, future); } } catch (final IllegalArgumentException e) { ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); ctx.status(SC_BAD_REQUEST); } } GetCommittees(ChainDataProvider provider, JsonProvider jsonProvider); }
GetCommittees extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get the committee assignments for an epoch.", tags = {TAG_BEACON}, queryParams = { @OpenApiParam(name = EPOCH, description = EPOCH_QUERY_DESCRIPTION, required = true), }, description = "Returns committee assignments for each slot in a specified epoch.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = Committee.class, isArray = true)), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Missing a query parameter"), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_INTERNAL_ERROR) }) @Override public void handle(Context ctx) throws Exception { try { UInt64 epoch = getParameterValueAsEpoch(ctx.queryParamMap(), EPOCH); final SafeFuture<Optional<List<Committee>>> future = provider.getCommitteesAtEpoch(epoch); UInt64 slot = BeaconStateUtil.compute_start_slot_at_epoch(epoch); ctx.header(Header.CACHE_CONTROL, getMaxAgeForSlot(provider, slot)); if (provider.isFinalized(slot)) { handlePossiblyGoneResult(ctx, future); } else { handlePossiblyMissingResult(ctx, future); } } catch (final IllegalArgumentException e) { ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); ctx.status(SC_BAD_REQUEST); } } GetCommittees(ChainDataProvider provider, JsonProvider jsonProvider); @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get the committee assignments for an epoch.", tags = {TAG_BEACON}, queryParams = { @OpenApiParam(name = EPOCH, description = EPOCH_QUERY_DESCRIPTION, required = true), }, description = "Returns committee assignments for each slot in a specified epoch.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = Committee.class, isArray = true)), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Missing a query parameter"), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_INTERNAL_ERROR) }) @Override void handle(Context ctx); }
GetCommittees extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get the committee assignments for an epoch.", tags = {TAG_BEACON}, queryParams = { @OpenApiParam(name = EPOCH, description = EPOCH_QUERY_DESCRIPTION, required = true), }, description = "Returns committee assignments for each slot in a specified epoch.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = Committee.class, isArray = true)), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Missing a query parameter"), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_INTERNAL_ERROR) }) @Override public void handle(Context ctx) throws Exception { try { UInt64 epoch = getParameterValueAsEpoch(ctx.queryParamMap(), EPOCH); final SafeFuture<Optional<List<Committee>>> future = provider.getCommitteesAtEpoch(epoch); UInt64 slot = BeaconStateUtil.compute_start_slot_at_epoch(epoch); ctx.header(Header.CACHE_CONTROL, getMaxAgeForSlot(provider, slot)); if (provider.isFinalized(slot)) { handlePossiblyGoneResult(ctx, future); } else { handlePossiblyMissingResult(ctx, future); } } catch (final IllegalArgumentException e) { ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); ctx.status(SC_BAD_REQUEST); } } GetCommittees(ChainDataProvider provider, JsonProvider jsonProvider); @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get the committee assignments for an epoch.", tags = {TAG_BEACON}, queryParams = { @OpenApiParam(name = EPOCH, description = EPOCH_QUERY_DESCRIPTION, required = true), }, description = "Returns committee assignments for each slot in a specified epoch.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = Committee.class, isArray = true)), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Missing a query parameter"), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_INTERNAL_ERROR) }) @Override void handle(Context ctx); static final String ROUTE; }