Search in sources :

Example 1 with InterchangeJsonProvider

use of tech.pegasys.web3signer.slashingprotection.interchange.InterchangeJsonProvider 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)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InterchangeV5Format (dsl.InterchangeV5Format)1 SignedArtifacts (dsl.SignedArtifacts)1 Response (io.restassured.response.Response)1 Path (java.nio.file.Path)1 Test (org.junit.jupiter.api.Test)1 Eth2SigningRequestBody (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody)1 Signer (tech.pegasys.web3signer.dsl.signer.Signer)1 SignerConfigurationBuilder (tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder)1 InterchangeJsonProvider (tech.pegasys.web3signer.slashingprotection.interchange.InterchangeJsonProvider)1 SignedAttestation (tech.pegasys.web3signer.slashingprotection.interchange.model.SignedAttestation)1