Search in sources :

Example 1 with OwnedValidators

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);
}
Also used : OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Test(org.junit.jupiter.api.Test)

Example 2 with OwnedValidators

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);
}
Also used : OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 3 with OwnedValidators

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);
}
Also used : OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators)

Example 4 with OwnedValidators

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();
}
Also used : OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators) DeleteKeysResponse(tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeysResponse) ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) Test(org.junit.jupiter.api.Test)

Example 5 with OwnedValidators

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();
}
Also used : OwnedValidators(tech.pegasys.teku.validator.client.loader.OwnedValidators) DeleteKeysResponse(tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeysResponse) ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator) Test(org.junit.jupiter.api.Test)

Aggregations

OwnedValidators (tech.pegasys.teku.validator.client.loader.OwnedValidators)8 Test (org.junit.jupiter.api.Test)5 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)2 DeleteKeysResponse (tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeysResponse)2 ExternalValidator (tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 MetricsSystem (org.hyperledger.besu.plugin.services.MetricsSystem)1 LocalSlashingProtector (tech.pegasys.teku.core.signatures.LocalSlashingProtector)1 SlashingProtector (tech.pegasys.teku.core.signatures.SlashingProtector)1 AsyncRunner (tech.pegasys.teku.infrastructure.async.AsyncRunner)1 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)1 EventChannels (tech.pegasys.teku.infrastructure.events.EventChannels)1 SyncDataAccessor (tech.pegasys.teku.infrastructure.io.SyncDataAccessor)1