use of tech.pegasys.teku.validator.api.SyncCommitteeDuty 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)));
}
use of tech.pegasys.teku.validator.api.SyncCommitteeDuty 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())));
}
use of tech.pegasys.teku.validator.api.SyncCommitteeDuty in project teku by ConsenSys.
the class ValidatorApiHandler method getSyncCommitteeDuty.
private Optional<SyncCommitteeDuty> getSyncCommitteeDuty(final BeaconState state, final UInt64 epoch, final int validatorIndex) {
final Optional<SyncCommitteeUtil> syncCommitteeUtil = spec.atEpoch(epoch).getSyncCommitteeUtil();
final IntSet duties = syncCommitteeUtil.map(util -> util.getCommitteeIndices(state, epoch, UInt64.valueOf(validatorIndex))).orElse(IntSets.emptySet());
if (duties.isEmpty()) {
return Optional.empty();
}
return Optional.of(new SyncCommitteeDuty(state.getValidators().get(validatorIndex).getPublicKey(), validatorIndex, duties));
}
Aggregations