use of tech.pegasys.teku.validator.client.loader.OwnedValidators in project teku by ConsenSys.
the class ValidatorIndexProviderTest method shouldLoadValidatorKeys.
@Test
void shouldLoadValidatorKeys() {
final BLSPublicKey key2 = dataStructureUtil.randomPublicKey();
final BLSPublicKey key3 = dataStructureUtil.randomPublicKey();
final OwnedValidators validators = ownedValidatorsWithKeys(key1, key2, key3);
final ValidatorIndexProvider provider = new ValidatorIndexProvider(validators, validatorApiChannel, asyncRunner);
when(validatorApiChannel.getValidatorIndices(validators.getPublicKeys())).thenReturn(SafeFuture.completedFuture(Map.of(key1, 1, key2, 20, key3, 300)));
provider.lookupValidators();
assertThat(provider.getValidatorIndex(key1)).contains(1);
assertThat(provider.getValidatorIndex(key2)).contains(20);
assertThat(provider.getValidatorIndex(key3)).contains(300);
}
use of tech.pegasys.teku.validator.client.loader.OwnedValidators in project teku by ConsenSys.
the class ValidatorIndexProviderTest method shouldRetryWhenLoadRequestFails.
@Test
void shouldRetryWhenLoadRequestFails() {
final OwnedValidators validators = ownedValidatorsWithKeys(key1);
final ValidatorIndexProvider provider = new ValidatorIndexProvider(validators, validatorApiChannel, asyncRunner);
when(validatorApiChannel.getValidatorIndices(validators.getPublicKeys())).thenReturn(SafeFuture.failedFuture(new IOException("Server not available"))).thenReturn(SafeFuture.completedFuture(Map.of(key1, 1)));
provider.lookupValidators();
assertThat(provider.getValidatorIndex(key1)).isEmpty();
assertThat(asyncRunner.hasDelayedActions()).isTrue();
asyncRunner.executeQueuedActions();
assertThat(provider.getValidatorIndex(key1)).contains(1);
}
use of tech.pegasys.teku.validator.client.loader.OwnedValidators in project teku by ConsenSys.
the class AttestationDutySchedulerTest method createDutySchedulerWithMockDuties.
private void createDutySchedulerWithMockDuties() {
final AttestationDutyLoader attestationDutyLoader = new AttestationDutyLoader(validatorApiChannel, forkProvider, dependentRoot -> scheduledDuties, new OwnedValidators(Map.of(VALIDATOR1_KEY, validator1, VALIDATOR2_KEY, validator2)), validatorIndexProvider, beaconCommitteeSubscriptions, spec);
dutyScheduler = new AttestationDutyScheduler(metricsSystem2, new RetryingDutyLoader<>(asyncRunner, attestationDutyLoader), spec);
}
use of tech.pegasys.teku.validator.client.loader.OwnedValidators in project teku by ConsenSys.
the class ActiveKeyManagerTest method deleteValidators_shouldRejectRequestToDeleteReadOnlyValidator.
@Test
void deleteValidators_shouldRejectRequestToDeleteReadOnlyValidator(@TempDir final Path tempDir) {
final Validator activeValidator = mock(Validator.class);
when(activeValidator.isReadOnly()).thenReturn(true);
when(validatorLoader.getOwnedValidators()).thenReturn(new OwnedValidators(Map.of(publicKey, activeValidator)));
when(activeValidator.getPublicKey()).thenReturn(publicKey);
final DeleteKeysResponse response = keyManager.deleteValidators(List.of(publicKey), tempDir);
assertThat(response.getData()).hasSize(1);
assertThat(response.getData().get(0).getStatus()).isEqualTo(DeletionStatus.ERROR);
assertThat(response.getData().get(0).getMessage().orElse("")).contains("read-only");
assertThat(response.getSlashingProtection()).isNotEmpty();
verify(channel, never()).onValidatorsAdded();
}
use of tech.pegasys.teku.validator.client.loader.OwnedValidators in project teku by ConsenSys.
the class ActiveKeyManagerTest method deleteValidators_shouldStopAndDeleteValidator.
@Test
void deleteValidators_shouldStopAndDeleteValidator(@TempDir final Path tempDir) {
final Validator activeValidator = mock(Validator.class);
when(activeValidator.getPublicKey()).thenReturn(publicKey);
when(activeValidator.isReadOnly()).thenReturn(false);
when(activeValidator.getSigner()).thenReturn(signer);
when(validatorLoader.getOwnedValidators()).thenReturn(new OwnedValidators(Map.of(publicKey, activeValidator)));
when(exporter.addPublicKeyToExport(eq(publicKey), any())).thenReturn(Optional.empty());
when(validatorLoader.deleteLocalMutableValidator(publicKey)).thenReturn(DeleteKeyResult.success());
final DeleteKeysResponse response = keyManager.deleteValidators(List.of(publicKey), tempDir);
verify(signer).delete();
verify(validatorLoader).deleteLocalMutableValidator(publicKey);
assertThat(response.getData().get(0).getStatus()).isEqualTo(DeletionStatus.DELETED);
assertThat(response.getData()).hasSize(1);
assertThat(response.getSlashingProtection()).isNotEmpty();
verify(channel, never()).onValidatorsAdded();
}
Aggregations