Search in sources :

Example 1 with SyncCommitteeDuties

use of tech.pegasys.teku.validator.api.SyncCommitteeDuties in project teku by ConsenSys.

the class PostSyncDutiesIntegrationTest method shouldGetSyncCommitteeDuties.

@Test
void shouldGetSyncCommitteeDuties() throws IOException {
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final SafeFuture<Optional<SyncCommitteeDuties>> out = SafeFuture.completedFuture(Optional.of(new SyncCommitteeDuties(List.of(new SyncCommitteeDuty(VALIDATOR_KEYS.get(1).getPublicKey(), 1, IntSet.of(11))))));
    when(syncService.getCurrentSyncState()).thenReturn(SyncState.IN_SYNC);
    when(validatorApiChannel.getSyncCommitteeDuties(ONE, validators)).thenReturn(out);
    Response response = post(PostSyncDuties.ROUTE.replace("{epoch}", "1"), jsonProvider.objectToJSON(validators));
    Assertions.assertThat(response.code()).isEqualTo(SC_OK);
    final PostSyncDutiesResponse dutiesResponse = jsonProvider.jsonToObject(response.body().string(), PostSyncDutiesResponse.class);
    assertThat(dutiesResponse.data.get(0)).isEqualTo(new tech.pegasys.teku.api.response.v1.validator.SyncCommitteeDuty(new BLSPubKey(VALIDATOR_KEYS.get(1).getPublicKey()), ONE, IntSet.of(11)));
}
Also used : PostSyncDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse) Response(okhttp3.Response) PostSyncDutiesResponse(tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse) Optional(java.util.Optional) SyncCommitteeDuty(tech.pegasys.teku.validator.api.SyncCommitteeDuty) SyncCommitteeDuties(tech.pegasys.teku.validator.api.SyncCommitteeDuties) BLSPubKey(tech.pegasys.teku.api.schema.BLSPubKey) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 2 with SyncCommitteeDuties

use of tech.pegasys.teku.validator.api.SyncCommitteeDuties in project teku by ConsenSys.

the class SyncCommitteeDutyLoaderTest method shouldRetrieveDuties.

@Test
void shouldRetrieveDuties() {
    final UInt64 epoch = UInt64.valueOf(56);
    final UInt64 untilEpoch = spec.getSyncCommitteeUtilRequired(UInt64.ZERO).computeFirstEpochOfNextSyncCommitteePeriod(epoch).minusMinZero(1);
    when(validatorApiChannel.getSyncCommitteeDuties(epoch, validatorIndices)).thenReturn(SafeFuture.completedFuture(Optional.of(new SyncCommitteeDuties(List.of(new SyncCommitteeDuty(validator1.getPublicKey(), validator1Index, IntSet.of(1, 6, 25)), new SyncCommitteeDuty(validator2.getPublicKey(), validator2Index, IntSet.of(7, 50, 38)))))));
    final SyncCommitteeScheduledDuties duties = loadDuties(epoch);
    assertThat(duties.countDuties()).isEqualTo(2);
    // And should trigger subscription to subnets
    verify(validatorApiChannel).subscribeToSyncCommitteeSubnets(Set.of(new SyncCommitteeSubnetSubscription(validator1Index, IntSet.of(1, 6, 25), untilEpoch.increment()), new SyncCommitteeSubnetSubscription(validator2Index, IntSet.of(7, 50, 38), untilEpoch.increment())));
}
Also used : SyncCommitteeSubnetSubscription(tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription) SyncCommitteeDuty(tech.pegasys.teku.validator.api.SyncCommitteeDuty) SyncCommitteeDuties(tech.pegasys.teku.validator.api.SyncCommitteeDuties) SyncCommitteeScheduledDuties(tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 SyncCommitteeDuties (tech.pegasys.teku.validator.api.SyncCommitteeDuties)2 SyncCommitteeDuty (tech.pegasys.teku.validator.api.SyncCommitteeDuty)2 Optional (java.util.Optional)1 Response (okhttp3.Response)1 PostSyncDutiesResponse (tech.pegasys.teku.api.response.v1.validator.PostSyncDutiesResponse)1 BLSPubKey (tech.pegasys.teku.api.schema.BLSPubKey)1 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 SyncCommitteeSubnetSubscription (tech.pegasys.teku.validator.api.SyncCommitteeSubnetSubscription)1 SyncCommitteeScheduledDuties (tech.pegasys.teku.validator.client.duties.synccommittee.SyncCommitteeScheduledDuties)1