Search in sources :

Example 6 with Signer

use of tech.pegasys.web3signer.dsl.signer.Signer in project web3signer by ConsenSys.

the class KeyManagerTestBase method setupSignerWithKeyManagerApi.

protected void setupSignerWithKeyManagerApi(final SlashingProtectionDataChoice slashingProtectionDataChoice) throws URISyntaxException {
    final SignerConfigurationBuilder builder = new SignerConfigurationBuilder();
    builder.withKeyStoreDirectory(testDirectory).withNetwork("minimal").withMode("eth2").withAltairForkEpoch(MINIMAL_ALTAIR_FORK).withSlashingEnabled(true).withSlashingProtectionDbUsername(DB_USERNAME).withSlashingProtectionDbPassword(DB_PASSWORD).withKeyManagerApiEnabled(true);
    startSigner(builder.build());
    if (slashingProtectionDataChoice == WITHOUT_SLASHING_PROTECTION_DATA) {
        return;
    }
    final SignerConfigurationBuilder importBuilder = new SignerConfigurationBuilder();
    importBuilder.withMode("eth2").withSlashingEnabled(true).withSlashingProtectionDbUrl(signer.getSlashingDbUrl()).withSlashingProtectionDbUsername(DB_USERNAME).withSlashingProtectionDbPassword(DB_PASSWORD).withKeyStoreDirectory(testDirectory).withSlashingImportPath(getResourcePath("slashing/slashingImport_two_entries.json")).withHttpPort(// prevent wait for Ports file in AT
    12345);
    final Signer importSigner = new Signer(importBuilder.build(), null);
    importSigner.start();
    waitFor(() -> assertThat(importSigner.isRunning()).isFalse());
}
Also used : Signer(tech.pegasys.web3signer.dsl.signer.Signer) SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder)

Example 7 with Signer

use of tech.pegasys.web3signer.dsl.signer.Signer in project web3signer by ConsenSys.

the class AcceptanceTestBase method startSigner.

protected void startSigner(final SignerConfiguration config) {
    signer = new Signer(config, null);
    signer.start();
    signer.awaitStartupCompletion();
}
Also used : Signer(tech.pegasys.web3signer.dsl.signer.Signer)

Example 8 with Signer

use of tech.pegasys.web3signer.dsl.signer.Signer in project web3signer by ConsenSys.

the class SlashingExportAcceptanceTest method slashingDataIsExported.

@Test
void slashingDataIsExported(@TempDir Path testDirectory) throws IOException {
    setupSigner(testDirectory, true);
    final Eth2SigningRequestBody request = createAttestationRequest(5, 6, UInt64.ZERO);
    final Response initialResponse = signer.eth2Sign(keyPair.getPublicKey().toString(), request);
    assertThat(initialResponse.getStatusCode()).isEqualTo(200);
    assertThat(signer.getMetricsMatching(blockSlashingMetrics)).containsOnly(blockSlashingMetrics.get(0) + " 1.0", blockSlashingMetrics.get(1) + " 0.0");
    final Path exportFile = testDirectory.resolve("dbExport.json");
    final SignerConfigurationBuilder builder = new SignerConfigurationBuilder();
    builder.withMode("eth2");
    builder.withSlashingEnabled(true);
    builder.withSlashingProtectionDbUrl(signer.getSlashingDbUrl());
    builder.withSlashingProtectionDbUsername("postgres");
    builder.withSlashingProtectionDbPassword("postgres");
    builder.withKeyStoreDirectory(testDirectory);
    builder.withSlashingExportPath(exportFile);
    // prevent wait for Ports file in AT
    builder.withHttpPort(12345);
    final Signer exportSigner = new Signer(builder.build(), null);
    exportSigner.start();
    waitFor(() -> assertThat(exportSigner.isRunning()).isFalse());
    final ObjectMapper mapper = new InterchangeJsonProvider().getJsonMapper();
    final InterchangeV5Format mappedData = mapper.readValue(exportFile.toFile(), InterchangeV5Format.class);
    assertThat(mappedData.getMetadata().getFormatVersion()).isEqualTo("5");
    assertThat(mappedData.getMetadata().getGenesisValidatorsRoot()).isEqualTo(Bytes.fromHexString(GENESIS_VALIDATORS_ROOT));
    assertThat(mappedData.getSignedArtifacts()).hasSize(1);
    final SignedArtifacts artifacts = mappedData.getSignedArtifacts().get(0);
    assertThat(artifacts.getSignedBlocks()).hasSize(0);
    assertThat(artifacts.getSignedAttestations()).hasSize(1);
    final SignedAttestation attestation = artifacts.getSignedAttestations().get(0);
    assertThat(attestation.getSourceEpoch().toLong()).isEqualTo(request.getAttestation().source.epoch.longValue());
    assertThat(attestation.getTargetEpoch().toLong()).isEqualTo(request.getAttestation().target.epoch.longValue());
    assertThat(attestation.getSigningRoot()).isNotNull();
}
Also used : Response(io.restassured.response.Response) Path(java.nio.file.Path) Signer(tech.pegasys.web3signer.dsl.signer.Signer) SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) InterchangeV5Format(dsl.InterchangeV5Format) SignedArtifacts(dsl.SignedArtifacts) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) InterchangeJsonProvider(tech.pegasys.web3signer.slashingprotection.interchange.InterchangeJsonProvider) SignedAttestation(tech.pegasys.web3signer.slashingprotection.interchange.model.SignedAttestation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 9 with Signer

use of tech.pegasys.web3signer.dsl.signer.Signer in project web3signer by ConsenSys.

the class SlashingImportAcceptanceTest method slashingDataIsImported.

@Test
void slashingDataIsImported(@TempDir Path testDirectory) throws URISyntaxException, IOException {
    setupSigner(testDirectory, true);
    final Path importFile = new File(Resources.getResource("slashing/slashingImport.json").toURI()).toPath();
    final SignerConfigurationBuilder builder = new SignerConfigurationBuilder();
    builder.withMode("eth2");
    builder.withSlashingEnabled(true);
    builder.withSlashingProtectionDbUrl(signer.getSlashingDbUrl());
    builder.withSlashingProtectionDbUsername("postgres");
    builder.withSlashingProtectionDbPassword("postgres");
    builder.withKeyStoreDirectory(testDirectory);
    builder.withSlashingImportPath(importFile);
    // prevent wait for Ports file in AT
    builder.withHttpPort(12345);
    final Signer importSigner = new Signer(builder.build(), null);
    importSigner.start();
    waitFor(() -> assertThat(importSigner.isRunning()).isFalse());
    final InterchangeV5Format interchangeData = objectMapper.readValue(importFile.toFile(), InterchangeV5Format.class);
    final Jdbi jdbi = Jdbi.create(signer.getSlashingDbUrl(), DB_USERNAME, DB_PASSWORD);
    final int validatorId = 1;
    final Map<String, Object> metadata = jdbi.withHandle(h -> h.select("SELECT * from metadata").mapToMap().one());
    assertThat(metadata.get("id")).isEqualTo(validatorId);
    assertThat(metadata.get("genesis_validators_root")).isEqualTo(interchangeData.getMetadata().getGenesisValidatorsRoot().toArray());
    final SignedArtifacts artifacts = interchangeData.getSignedArtifacts().get(0);
    final List<Map<String, Object>> validators = jdbi.withHandle(h -> h.select("SELECT * from validators").mapToMap().list());
    assertThat(validators).hasSize(1);
    assertThat(validators.get(0).get("id")).isEqualTo(validatorId);
    assertThat(validators.get(0).get("public_key")).isEqualTo(Bytes.fromHexString(artifacts.getPublicKey()).toArray());
    final List<Map<String, Object>> signedAttestations = jdbi.withHandle(h -> h.select("SELECT * from signed_attestations").mapToMap().list());
    final SignedAttestation attestation = artifacts.getSignedAttestations().get(0);
    assertThat(signedAttestations).hasSize(1);
    assertThat(signedAttestations.get(0).get("validator_id")).isEqualTo(validatorId);
    assertThat(signedAttestations.get(0).get("source_epoch")).isEqualTo(BigDecimal.valueOf(attestation.getSourceEpoch().toLong()));
    assertThat(signedAttestations.get(0).get("target_epoch")).isEqualTo(BigDecimal.valueOf(attestation.getTargetEpoch().toLong()));
    assertThat(signedAttestations.get(0).get("signing_root")).isEqualTo(attestation.getSigningRoot().toArray());
    final List<Map<String, Object>> signedBlocks = jdbi.withHandle(h -> h.select("SELECT * from signed_blocks").mapToMap().list());
    final SignedBlock block = artifacts.getSignedBlocks().get(0);
    assertThat(signedBlocks).hasSize(1);
    assertThat(signedBlocks.get(0).get("validator_id")).isEqualTo(validatorId);
    assertThat(signedBlocks.get(0).get("slot")).isEqualTo(BigDecimal.valueOf(block.getSlot().toLong()));
    assertThat(signedBlocks.get(0).get("signing_root")).isEqualTo(block.getSigningRoot().toArray());
}
Also used : Path(java.nio.file.Path) Jdbi(org.jdbi.v3.core.Jdbi) SignedArtifacts(dsl.SignedArtifacts) SignedBlock(tech.pegasys.web3signer.slashingprotection.interchange.model.SignedBlock) Signer(tech.pegasys.web3signer.dsl.signer.Signer) SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) InterchangeV5Format(dsl.InterchangeV5Format) SignedAttestation(tech.pegasys.web3signer.slashingprotection.interchange.model.SignedAttestation) File(java.io.File) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 10 with Signer

use of tech.pegasys.web3signer.dsl.signer.Signer in project web3signer by ConsenSys.

the class SlashingProtectionDatabaseVersionAcceptanceTest method missingOrWrongVersionCauseAppToHaltOnStartup.

@Test
void missingOrWrongVersionCauseAppToHaltOnStartup(@TempDir Path testDirectory) {
    // NB: This test fails when running with a ThreadRunner (i.e. in IDE) due to the
    // System.exit() call in the Web3signerApp (which exits the test, rather than terminating
    // the app (thus it work as expected with a ProcessRunner (i.e. when run from gradle)).
    final String dbUrl = DatabaseUtil.create().databaseUrl();
    final Jdbi jdbi = Jdbi.create(dbUrl, DB_USERNAME, DB_PASSWORD);
    jdbi.useHandle(h -> h.execute("DROP TABLE database_version"));
    final SignerConfigurationBuilder builder = new SignerConfigurationBuilder().withMode("eth2").withSlashingEnabled(true).withSlashingProtectionDbUsername(DB_USERNAME).withSlashingProtectionDbPassword(DB_PASSWORD).withMetricsEnabled(true).withSlashingProtectionDbUrl(dbUrl).withKeyStoreDirectory(testDirectory).withHttpPort(// to ensure
    9000);
    final Signer signer = new Signer(builder.build(), null);
    signer.start();
    waitFor(30, () -> assertThat(signer.isRunning()).isTrue());
    waitFor(30, () -> assertThat(signer.isRunning()).isFalse());
}
Also used : Signer(tech.pegasys.web3signer.dsl.signer.Signer) Jdbi(org.jdbi.v3.core.Jdbi) SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Signer (tech.pegasys.web3signer.dsl.signer.Signer)13 SignerConfigurationBuilder (tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder)12 Test (org.junit.jupiter.api.Test)7 Path (java.nio.file.Path)5 Jdbi (org.jdbi.v3.core.Jdbi)3 TlsOptions (tech.pegasys.web3signer.core.config.TlsOptions)3 BasicTlsOptions (tech.pegasys.web3signer.dsl.tls.BasicTlsOptions)3 InterchangeV5Format (dsl.InterchangeV5Format)2 SignedArtifacts (dsl.SignedArtifacts)2 Map (java.util.Map)2 Eth2SigningRequestBody (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody)2 ClientTlsConfig (tech.pegasys.web3signer.dsl.tls.ClientTlsConfig)2 DefaultAzureKeyVaultParameters (tech.pegasys.web3signer.dsl.utils.DefaultAzureKeyVaultParameters)2 SignedAttestation (tech.pegasys.web3signer.slashingprotection.interchange.model.SignedAttestation)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Response (io.restassured.response.Response)1 File (java.io.File)1 IOException (java.io.IOException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1