use of tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout in project teku by ConsenSys.
the class DatabaseMigraterTest method makeDatabaseStructure.
private DataDirLayout makeDatabaseStructure(final Path beaconFolder, final String dbVersionString) throws IOException {
final Path dbFolder = beaconFolder.resolve("db");
final Path dbVersionFile = beaconFolder.resolve("db.version");
FileUtils.write(dbVersionFile.toFile(), dbVersionString, Charset.defaultCharset());
assertThat(dbFolder.toFile().mkdir()).isTrue();
assertThat(dbVersionFile.toFile().isFile()).isTrue();
return new SimpleDataDirLayout(beaconFolder);
}
use of tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout in project teku by ConsenSys.
the class ExternalValidatorSourceTest method shouldReturnErrorWhenDeleteNonExistentValidator.
@Test
void shouldReturnErrorWhenDeleteNonExistentValidator(@TempDir Path tempDir) {
final BLSPublicKey publicKey = dataStructureUtil.randomPublicKey();
final ExternalValidatorSource externalValidatorSource = newExternalValidatorSource(tempDir, false);
final DeleteKeyResult result = externalValidatorSource.deleteValidator(publicKey);
assertThat(result.getStatus()).isEqualTo(DeletionStatus.NOT_FOUND);
assertThat(result.getMessage()).isEqualTo(Optional.empty());
final Path path = ValidatorClientService.getManagedRemoteKeyPath(new SimpleDataDirLayout(tempDir)).resolve(publicKey.toBytesCompressed().toUnprefixedHexString() + ".json");
assertThat(path.toFile()).doesNotExist();
}
use of tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout in project teku by ConsenSys.
the class ExternalValidatorSourceTest method shouldLoadExternalValidators.
@Test
void shouldLoadExternalValidators(@TempDir Path tempDir) throws IOException {
final DataDirLayout dataDirLayout = new SimpleDataDirLayout(tempDir);
final ExternalValidatorSource externalValidatorSource = newExternalValidatorSource(tempDir, false);
final BLSPublicKey publicKey1 = dataStructureUtil.randomPublicKey();
createRemoteKeyFile(dataDirLayout, publicKey1, Optional.of(new URL("http://host.com")));
final BLSPublicKey publicKey2 = dataStructureUtil.randomPublicKey();
createRemoteKeyFile(dataDirLayout, publicKey2, Optional.empty());
final List<ValidatorSource.ValidatorProvider> validators = externalValidatorSource.getAvailableValidators();
final List<ValidatorProviderInfo> result = validators.stream().map(v -> {
assertThat(v).isInstanceOf(ExternalValidatorProvider.class);
ExternalValidatorProvider provider = (ExternalValidatorProvider) v;
return new ValidatorProviderInfo(provider.getPublicKey(), provider.getExternalSignerUrl());
}).collect(Collectors.toList());
assertThat(result).containsExactlyInAnyOrder(new ValidatorProviderInfo(publicKey1, new URL("http://host.com")), new ValidatorProviderInfo(publicKey2, new URL("http://localhost:9000")));
}
use of tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout 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.techu.service.serviceutils.layout.SimpleDataDirLayout 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);
}
Aggregations