Search in sources :

Example 1 with GetStateCommitteesResponse

use of tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse in project teku by ConsenSys.

the class GetStateCommitteesTest method shouldGetCommitteesForNextEpoch.

@Test
public void shouldGetCommitteesForNextEpoch() throws IOException {
    final Response response = get("head", Map.of("epoch", "1"));
    assertThat(response.code()).isEqualTo(SC_OK);
    final GetStateCommitteesResponse body = jsonProvider.jsonToObject(response.body().string(), GetStateCommitteesResponse.class);
    final List<EpochCommitteeResponse> data = body.data;
    data.forEach(committee -> {
        assertThat(committee.slot).isGreaterThanOrEqualTo(UInt64.valueOf(specConfig.getSlotsPerEpoch()));
        assertThat(committee.slot).isLessThan(UInt64.valueOf(specConfig.getSlotsPerEpoch() * 2L));
    });
    assertThat(data.size()).isEqualTo(8);
}
Also used : EpochCommitteeResponse(tech.pegasys.teku.api.response.v1.beacon.EpochCommitteeResponse) GetStateCommitteesResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse) Response(okhttp3.Response) EpochCommitteeResponse(tech.pegasys.teku.api.response.v1.beacon.EpochCommitteeResponse) GetStateCommitteesResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 2 with GetStateCommitteesResponse

use of tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse in project teku by ConsenSys.

the class GetStateCommitteesTest method shouldGetCommitteesWithNoQueryParameters.

@Test
public void shouldGetCommitteesWithNoQueryParameters() throws IOException {
    final Response response = get("head", emptyMap());
    assertThat(response.code()).isEqualTo(SC_OK);
    final GetStateCommitteesResponse body = jsonProvider.jsonToObject(response.body().string(), GetStateCommitteesResponse.class);
    final List<EpochCommitteeResponse> data = body.data;
    assertThat(data).isNotEmpty();
}
Also used : EpochCommitteeResponse(tech.pegasys.teku.api.response.v1.beacon.EpochCommitteeResponse) GetStateCommitteesResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse) Response(okhttp3.Response) EpochCommitteeResponse(tech.pegasys.teku.api.response.v1.beacon.EpochCommitteeResponse) GetStateCommitteesResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 3 with GetStateCommitteesResponse

use of tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse in project teku by ConsenSys.

the class GetStateCommitteesTest method shouldGetCommitteesForSingleIndexAndSlotAndEpoch.

@Test
public void shouldGetCommitteesForSingleIndexAndSlotAndEpoch() throws IOException {
    final Response response = get("head", Map.of("index", "0", "slot", "9", "epoch", "1"));
    assertThat(response.code()).isEqualTo(SC_OK);
    final GetStateCommitteesResponse body = jsonProvider.jsonToObject(response.body().string(), GetStateCommitteesResponse.class);
    final List<EpochCommitteeResponse> data = body.data;
    data.forEach(committee -> {
        assertThat(committee.index).isEqualTo(ZERO);
        assertThat(committee.slot).isEqualTo(UInt64.valueOf(9));
    });
    assertThat(data.size()).isEqualTo(1);
}
Also used : EpochCommitteeResponse(tech.pegasys.teku.api.response.v1.beacon.EpochCommitteeResponse) GetStateCommitteesResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse) Response(okhttp3.Response) EpochCommitteeResponse(tech.pegasys.teku.api.response.v1.beacon.EpochCommitteeResponse) GetStateCommitteesResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 4 with GetStateCommitteesResponse

use of tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse in project teku by ConsenSys.

the class GetStateCommitteesTest method shouldGetCommitteesFromState.

@Test
public void shouldGetCommitteesFromState() throws Exception {
    final UInt64 slot = dataStructureUtil.randomUInt64();
    final UInt64 epoch = spec.computeEpochAtSlot(dataStructureUtil.randomUInt64());
    when(context.pathParamMap()).thenReturn(Map.of("state_id", "head"));
    when(context.queryParamMap()).thenReturn(Map.of("index", List.of("1"), "slot", List.of(slot.toString()), "epoch", List.of(epoch.toString())));
    when(chainDataProvider.getStateCommittees("head", Optional.of(epoch), Optional.of(UInt64.ONE), Optional.of(slot))).thenReturn(SafeFuture.completedFuture(Optional.of(withMetaData(List.of(epochCommitteeResponse)))));
    handler.handle(context);
    GetStateCommitteesResponse response = getResponseFromFuture(GetStateCommitteesResponse.class);
    assertThat(response.data).isEqualTo(List.of(epochCommitteeResponse));
}
Also used : UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) GetStateCommitteesResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse) AbstractBeaconHandlerTest(tech.pegasys.teku.beaconrestapi.AbstractBeaconHandlerTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with GetStateCommitteesResponse

use of tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse in project teku by ConsenSys.

the class GetStateCommitteesTest method shouldGetCommitteesForSingleIndex.

@Test
public void shouldGetCommitteesForSingleIndex() throws IOException {
    final Response response = get("head", Map.of("index", "0"));
    assertThat(response.code()).isEqualTo(SC_OK);
    final GetStateCommitteesResponse body = jsonProvider.jsonToObject(response.body().string(), GetStateCommitteesResponse.class);
    final List<EpochCommitteeResponse> data = body.data;
    data.forEach(committee -> assertThat(committee.index).isEqualTo(ZERO));
    assertThat(data.size()).isEqualTo(8);
}
Also used : EpochCommitteeResponse(tech.pegasys.teku.api.response.v1.beacon.EpochCommitteeResponse) GetStateCommitteesResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse) Response(okhttp3.Response) EpochCommitteeResponse(tech.pegasys.teku.api.response.v1.beacon.EpochCommitteeResponse) GetStateCommitteesResponse(tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Aggregations

GetStateCommitteesResponse (tech.pegasys.teku.api.response.v1.beacon.GetStateCommitteesResponse)6 Response (okhttp3.Response)5 Test (org.junit.jupiter.api.Test)5 EpochCommitteeResponse (tech.pegasys.teku.api.response.v1.beacon.EpochCommitteeResponse)5 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 AbstractBeaconHandlerTest (tech.pegasys.teku.beaconrestapi.AbstractBeaconHandlerTest)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1