Search in sources :

Example 1 with SimpleDataDirLayout

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);
}
Also used : Path(java.nio.file.Path) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)

Example 2 with SimpleDataDirLayout

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();
}
Also used : Path(java.nio.file.Path) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) DeleteKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Test(org.junit.jupiter.api.Test)

Example 3 with SimpleDataDirLayout

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")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) DeleteKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult) ArgumentMatchers(org.mockito.ArgumentMatchers) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) ValidatorClientService(tech.pegasys.teku.validator.client.ValidatorClientService) Supplier(java.util.function.Supplier) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) StubAsyncRunner(tech.pegasys.teku.infrastructure.async.StubAsyncRunner) HttpClient(java.net.http.HttpClient) Spec(tech.pegasys.teku.spec.Spec) Path(java.nio.file.Path) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) HttpResponse(java.net.http.HttpResponse) Charsets(com.google.common.base.Charsets) AsyncRunner(tech.pegasys.teku.infrastructure.async.AsyncRunner) Files(java.nio.file.Files) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ThrottlingTaskQueue(tech.pegasys.teku.infrastructure.async.ThrottlingTaskQueue) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) ImportStatus(tech.pegasys.teku.validator.client.restapi.apis.schema.ImportStatus) List(java.util.List) Files.createTempFile(java.nio.file.Files.createTempFile) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) TempDir(org.junit.jupiter.api.io.TempDir) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) DeletionStatus(tech.pegasys.teku.validator.client.restapi.apis.schema.DeletionStatus) SC_OK(tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK) Mockito.mock(org.mockito.Mockito.mock) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 4 with SimpleDataDirLayout

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();
}
Also used : SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) DataDirLayout(tech.pegasys.teku.service.serviceutils.layout.DataDirLayout) SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Example 5 with SimpleDataDirLayout

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);
}
Also used : SimpleDataDirLayout(tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout) PostKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult) Validator(tech.pegasys.teku.validator.client.Validator) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleDataDirLayout (tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)11 Test (org.junit.jupiter.api.Test)8 Path (java.nio.file.Path)5 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)5 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)5 ValidatorConfig (tech.pegasys.teku.validator.api.ValidatorConfig)5 Validator (tech.pegasys.teku.validator.client.Validator)4 DeleteKeyResult (tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult)3 URL (java.net.URL)2 Charsets (com.google.common.base.Charsets)1 IOException (java.io.IOException)1 HttpClient (java.net.http.HttpClient)1 HttpResponse (java.net.http.HttpResponse)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Files.createTempFile (java.nio.file.Files.createTempFile)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1