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