Search in sources :

Example 1 with PostAttesterDutiesResponse

use of tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse in project teku by ConsenSys.

the class PostAttesterDutiesTest method shouldGetAttesterDuties.

@Test
public void shouldGetAttesterDuties() throws Exception {
    when(validatorDataProvider.isStoreAvailable()).thenReturn(true);
    when(syncService.getCurrentSyncState()).thenReturn(SyncState.IN_SYNC);
    when(context.pathParamMap()).thenReturn(Map.of("epoch", "100"));
    when(context.body()).thenReturn("[\"2\"]");
    final UInt64 epoch = UInt64.valueOf(100);
    final UInt64 startSlot = spec.computeStartSlotAtEpoch(epoch);
    PostAttesterDutiesResponse duties = new PostAttesterDutiesResponse(Bytes32.fromHexString("0x1234"), List.of(getDuty(2, 1, 2, 10, 3, startSlot)));
    when(validatorDataProvider.getAttesterDuties(eq(UInt64.valueOf(100)), any())).thenReturn(SafeFuture.completedFuture(Optional.of(duties)));
    handler.handle(context);
    PostAttesterDutiesResponse response = getResponseFromFuture(PostAttesterDutiesResponse.class);
    assertThat(response).isEqualTo(duties);
}
Also used : PostAttesterDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 2 with PostAttesterDutiesResponse

use of tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse in project teku by ConsenSys.

the class ValidatorDataProviderTest method getAttesterDuties_shouldHandleEmptyIndicesList.

@TestTemplate
public void getAttesterDuties_shouldHandleEmptyIndicesList() {
    final Bytes32 previousTargetRoot = dataStructureUtil.randomBytes32();
    when(validatorApiChannel.getAttestationDuties(eq(ONE), any())).thenReturn(completedFuture(Optional.of(new tech.pegasys.teku.validator.api.AttesterDuties(previousTargetRoot, emptyList()))));
    final SafeFuture<Optional<PostAttesterDutiesResponse>> future = provider.getAttesterDuties(UInt64.ONE, IntList.of());
    assertThat(future).isCompleted();
    Optional<PostAttesterDutiesResponse> maybeData = future.join();
    assertThat(maybeData.isPresent()).isTrue();
    assertThat(maybeData.get().data).isEmpty();
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Optional(java.util.Optional) PostAttesterDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse) Bytes32(org.apache.tuweni.bytes.Bytes32) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 3 with PostAttesterDutiesResponse

use of tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse in project teku by ConsenSys.

the class ValidatorDataProviderTest method getAttesterDuties_shouldReturnDutiesForKnownValidator.

@TestTemplate
public void getAttesterDuties_shouldReturnDutiesForKnownValidator() {
    AttesterDuty v1 = new AttesterDuty(BLSTestUtil.randomPublicKey(0), 1, 2, 3, 15, 4, ONE);
    AttesterDuty v2 = new AttesterDuty(BLSTestUtil.randomPublicKey(1), 11, 12, 13, 15, 14, ZERO);
    when(validatorApiChannel.getAttestationDuties(eq(ONE), any())).thenReturn(completedFuture(Optional.of(new AttesterDuties(dataStructureUtil.randomBytes32(), List.of(v1, v2)))));
    final SafeFuture<Optional<PostAttesterDutiesResponse>> future = provider.getAttesterDuties(ONE, IntList.of(1, 11));
    assertThat(future).isCompleted();
    final Optional<PostAttesterDutiesResponse> maybeList = future.join();
    final PostAttesterDutiesResponse list = maybeList.orElseThrow();
    assertThat(list.data).containsExactlyInAnyOrder(asAttesterDuty(v1), asAttesterDuty(v2));
}
Also used : AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) Optional(java.util.Optional) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) PostAttesterDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 4 with PostAttesterDutiesResponse

use of tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse in project teku by ConsenSys.

the class RemoteValidatorApiHandlerTest method getAttestationDuties_WhenFound_ReturnsDuties.

@Test
public void getAttestationDuties_WhenFound_ReturnsDuties() {
    final BLSPublicKey blsPublicKey = dataStructureUtil.randomPublicKey();
    final int validatorIndex = 472;
    final int committeeLength = 2;
    final int committeeIndex = 1;
    final int validatorCommitteeIndex = 3;
    final int committeesAtSlot = 15;
    final tech.pegasys.teku.api.response.v1.validator.AttesterDuty schemaValidatorDuties = new tech.pegasys.teku.api.response.v1.validator.AttesterDuty(new BLSPubKey(blsPublicKey), UInt64.valueOf(validatorIndex), UInt64.valueOf(committeeIndex), UInt64.valueOf(committeeLength), UInt64.valueOf(committeesAtSlot), UInt64.valueOf(validatorCommitteeIndex), UInt64.ZERO);
    final AttesterDuty expectedValidatorDuties = new AttesterDuty(blsPublicKey, validatorIndex, committeeLength, committeeIndex, committeesAtSlot, validatorCommitteeIndex, UInt64.ZERO);
    when(apiClient.getAttestationDuties(UInt64.ONE, IntList.of(validatorIndex))).thenReturn(Optional.of(new PostAttesterDutiesResponse(dataStructureUtil.randomBytes32(), List.of(schemaValidatorDuties))));
    SafeFuture<Optional<AttesterDuties>> future = apiHandler.getAttestationDuties(UInt64.ONE, IntList.of(validatorIndex));
    AttesterDuties validatorDuties = unwrapToValue(future);
    assertThat(validatorDuties.getDuties().get(0)).isEqualTo(expectedValidatorDuties);
}
Also used : Optional(java.util.Optional) BLSPubKey(tech.pegasys.teku.api.schema.BLSPubKey) AttesterDuties(tech.pegasys.teku.validator.api.AttesterDuties) AttesterDuty(tech.pegasys.teku.validator.api.AttesterDuty) PostAttesterDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Test(org.junit.jupiter.api.Test)

Aggregations

PostAttesterDutiesResponse (tech.pegasys.teku.api.response.v1.validator.PostAttesterDutiesResponse)4 Optional (java.util.Optional)3 AttesterDuties (tech.pegasys.teku.validator.api.AttesterDuties)3 Test (org.junit.jupiter.api.Test)2 TestTemplate (org.junit.jupiter.api.TestTemplate)2 AttesterDuty (tech.pegasys.teku.validator.api.AttesterDuty)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 BLSPubKey (tech.pegasys.teku.api.schema.BLSPubKey)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1