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();
}
Aggregations