use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.
the class ValidatorLoaderTest method shouldNotInitializeMutableValidatorsWithoutDirectoryStructure.
@Test
void shouldNotInitializeMutableValidatorsWithoutDirectoryStructure(@TempDir Path tempDir, @TempDir Path tempDirMutable) throws Exception {
final DataDirLayout dataDirLayout = new SimpleDataDirLayout(tempDirMutable);
writeKeystore(tempDir);
final ValidatorConfig config = ValidatorConfig.builder().validatorKeys(List.of(tempDir.toAbsolutePath() + File.pathSeparator + tempDir.toAbsolutePath())).build();
final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.of(dataDirLayout));
validatorLoader.loadValidators();
final OwnedValidators validators = validatorLoader.getOwnedValidators();
assertThat(validators.getValidatorCount()).isEqualTo(1);
final Validator validator1 = validators.getValidator(PUBLIC_KEY1).orElseThrow();
assertThat(validator1).isNotNull();
assertThat(validator1.getPublicKey()).isEqualTo(PUBLIC_KEY1);
assertThat(validator1.isReadOnly()).isTrue();
}
use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.
the class ValidatorLoaderTest method shouldLoadMutableValidatorIfEnabled.
@Test
void shouldLoadMutableValidatorIfEnabled(@TempDir final Path tempDir) throws Exception {
final ValidatorConfig config = ValidatorConfig.builder().build();
final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.of(new SimpleDataDirLayout(tempDir)));
validatorLoader.loadValidators();
final String keystoreString = Resources.toString(Resources.getResource("pbkdf2TestVector.json"), StandardCharsets.UTF_8);
PostKeyResult result = validatorLoader.loadLocalMutableValidator(KeyStoreLoader.loadFromString(keystoreString), "testpassword", Optional.empty());
assertThat(result.getImportStatus()).isEqualTo(ImportStatus.IMPORTED);
final Optional<Validator> validator = validatorLoader.getOwnedValidators().getValidator(PUBLIC_KEY1);
assertThat(validator).isPresent();
assertThat(validator.orElseThrow().getSigner()).isInstanceOf(DeletableSigner.class);
}
use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.
the class ValidatorLoaderTest method shouldInitializeOnlyLocalValidatorsWhenRestDisabled.
@Test
void shouldInitializeOnlyLocalValidatorsWhenRestDisabled(@TempDir Path tempDir, @TempDir Path tempDirMutable) throws Exception {
final DataDirLayout dataDirLayout = new SimpleDataDirLayout(tempDirMutable);
writeKeystore(tempDir);
writeMutableKeystore(dataDirLayout);
final ValidatorConfig config = ValidatorConfig.builder().validatorKeys(List.of(tempDir.toAbsolutePath() + File.pathSeparator + tempDir.toAbsolutePath())).build();
final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
validatorLoader.loadValidators();
final OwnedValidators validators = validatorLoader.getOwnedValidators();
assertThat(validators.getValidatorCount()).isEqualTo(1);
final Validator validator1 = validators.getValidator(PUBLIC_KEY1).orElseThrow();
assertThat(validator1).isNotNull();
assertThat(validator1.getPublicKey()).isEqualTo(PUBLIC_KEY1);
assertThat(validator1.isReadOnly()).isTrue();
}
use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.
the class ValidatorTypesTest method listKeysResponse_shouldFormatListOfPublicKeys.
@Test
void listKeysResponse_shouldFormatListOfPublicKeys() throws Exception {
final List<Validator> keys = List.of(new Validator(dataStructureUtil.randomPublicKey(), NO_OP_SIGNER, Optional::empty, true), new Validator(dataStructureUtil.randomPublicKey(), NO_OP_SIGNER, Optional::empty, false));
final Map<String, Object> result = JsonTestUtil.parse(JsonUtil.serialize(keys, ValidatorTypes.LIST_KEYS_RESPONSE_TYPE));
assertThat(result).containsOnlyKeys("data");
final List<Map<String, Object>> keysList = JsonTestUtil.getList(result, "data");
assertThat(keysList).hasSize(keys.size());
for (int i = 0; i < keys.size(); i++) {
assertThat(keysList.get(i)).containsOnly(entry("validating_pubkey", keys.get(i).getPublicKey().toBytesCompressed().toHexString()), entry("readonly", keys.get(i).isReadOnly()));
}
}
use of tech.pegasys.teku.validator.client.Validator in project teku by ConsenSys.
the class GetKeysTest method shouldListEmpytValidatorKeys.
@Test
void shouldListEmpytValidatorKeys() throws Exception {
final List<Validator> activeValidatorList = Collections.emptyList();
when(keyManager.getActiveValidatorKeys()).thenReturn(activeValidatorList);
final GetKeys endpoint = new GetKeys(keyManager);
final RestApiRequest request = mock(RestApiRequest.class);
endpoint.handle(request);
verify(request).respondOk(activeValidatorList);
}
Aggregations