use of tech.pegasys.teku.api.schema.BLSPubKey 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.api.schema.BLSPubKey in project teku by ConsenSys.
the class SlashingProtectionRepairer method readSlashProtectionFile.
private void readSlashProtectionFile(final File file) {
final String filePrefix = file.getName().substring(0, file.getName().length() - ".yml".length());
try {
BLSPubKey pubkey = BLSPubKey.fromHexString(filePrefix);
Optional<ValidatorSigningRecord> maybeRecord = syncDataAccessor.read(file.toPath()).map(ValidatorSigningRecord::fromBytes);
if (maybeRecord.isEmpty() && invalidRecords.add(filePrefix)) {
log.display(filePrefix + ": Empty slashing protection record");
return;
}
if (updateAllEnabled) {
log.display(filePrefix + ": looks valid");
}
ValidatorSigningRecord validatorSigningRecord = maybeRecord.get();
signingHistoryList.add(new SigningHistory(pubkey, validatorSigningRecord));
} catch (PublicKeyException e) {
log.display(" --- " + file.getName() + " - invalid public key - ignoring file");
} catch (Exception e) {
if (invalidRecords.add(filePrefix)) {
log.display(filePrefix + ": Incomplete or invalid slashing protection data");
}
}
}
use of tech.pegasys.teku.api.schema.BLSPubKey in project teku by ConsenSys.
the class RemoteValidatorApiHandlerTest method getProposerDuties_WhenFound_ReturnsDuties.
@Test
public void getProposerDuties_WhenFound_ReturnsDuties() {
final BLSPublicKey blsPublicKey = dataStructureUtil.randomPublicKey();
final int validatorIndex = 472;
final tech.pegasys.teku.api.response.v1.validator.ProposerDuty schemaValidatorDuties = new tech.pegasys.teku.api.response.v1.validator.ProposerDuty(new BLSPubKey(blsPublicKey), validatorIndex, UInt64.ZERO);
final ProposerDuty expectedValidatorDuties = new ProposerDuty(blsPublicKey, validatorIndex, UInt64.ZERO);
final GetProposerDutiesResponse response = new GetProposerDutiesResponse(Bytes32.fromHexString("0x1234"), List.of(schemaValidatorDuties));
when(apiClient.getProposerDuties(UInt64.ONE)).thenReturn(Optional.of(response));
SafeFuture<Optional<ProposerDuties>> future = apiHandler.getProposerDuties(UInt64.ONE);
ProposerDuties validatorDuties = unwrapToValue(future);
assertThat(validatorDuties.getDuties().get(0)).isEqualTo(expectedValidatorDuties);
assertThat(validatorDuties.getDependentRoot()).isEqualTo(response.dependentRoot);
}
use of tech.pegasys.teku.api.schema.BLSPubKey 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