Search in sources :

Example 1 with SlashingProtectionInterchangeFormat

use of tech.pegasys.teku.data.slashinginterchange.SlashingProtectionInterchangeFormat in project teku by ConsenSys.

the class SlashingProtectionExporterTest method shouldReadSlashingProtectionFile_withGenesisValidatorsRoot.

@Test
public void shouldReadSlashingProtectionFile_withGenesisValidatorsRoot(@TempDir Path tempDir) throws IOException, URISyntaxException {
    final SlashingProtectionExporter exporter = new SlashingProtectionExporter(tempDir);
    Optional<String> error = exporter.readSlashProtectionFile(usingResourceFile("slashProtectionWithGenesisRoot.yml", tempDir), log::add);
    assertThat(log).containsExactly("Exporting " + pubkey);
    assertThat(error).isEmpty();
    final SlashingProtectionInterchangeFormat parsedData = jsonProvider.jsonToObject(exporter.getPrettyJson(), SlashingProtectionInterchangeFormat.class);
    final SlashingProtectionInterchangeFormat expectedData = getExportData(validatorsRoot, 327, 51, 1741);
    assertThat(parsedData).isEqualTo(expectedData);
}
Also used : SlashingProtectionInterchangeFormat(tech.pegasys.teku.data.slashinginterchange.SlashingProtectionInterchangeFormat) Test(org.junit.jupiter.api.Test)

Example 2 with SlashingProtectionInterchangeFormat

use of tech.pegasys.teku.data.slashinginterchange.SlashingProtectionInterchangeFormat in project teku by ConsenSys.

the class SlashingProtectionExporterTest method shouldHaveNoSignedAttestationsWhenNoAttestationsSigned.

@Test
void shouldHaveNoSignedAttestationsWhenNoAttestationsSigned(@TempDir Path tempDir) throws Exception {
    final Path exportedFile = tempDir.resolve("exportedFile.json").toAbsolutePath();
    final SlashingProtectionExporter exporter = new SlashingProtectionExporter(tempDir);
    final UInt64 blockSlot = UInt64.ONE;
    final ValidatorSigningRecord signingRecord = new ValidatorSigningRecord(validatorsRoot).maySignBlock(validatorsRoot, blockSlot).orElseThrow();
    final Path recordFile = tempDir.resolve(pubkey + ".yml");
    Files.write(recordFile, signingRecord.toBytes().toArrayUnsafe());
    final Optional<String> error = exporter.readSlashProtectionFile(recordFile.toFile(), LOG::debug);
    assertThat(error).isEmpty();
    assertThat(exportedFile).doesNotExist();
    exporter.saveToFile(exportedFile.toString(), LOG::debug);
    assertThat(exportedFile).exists();
    final SlashingProtectionInterchangeFormat exportedRecords = jsonProvider.jsonToObject(Files.readString(exportedFile), SlashingProtectionInterchangeFormat.class);
    assertThat(exportedRecords.data).hasSize(1);
    final SigningHistory signingHistory = exportedRecords.data.get(0);
    assertThat(signingHistory.signedBlocks).containsExactly(new SignedBlock(blockSlot, null));
    assertThat(signingHistory.signedAttestations).isEmpty();
}
Also used : Path(java.nio.file.Path) SigningHistory(tech.pegasys.teku.data.slashinginterchange.SigningHistory) SlashingProtectionInterchangeFormat(tech.pegasys.teku.data.slashinginterchange.SlashingProtectionInterchangeFormat) ValidatorSigningRecord(tech.pegasys.teku.data.signingrecord.ValidatorSigningRecord) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) SignedBlock(tech.pegasys.teku.data.slashinginterchange.SignedBlock) Test(org.junit.jupiter.api.Test)

Example 3 with SlashingProtectionInterchangeFormat

use of tech.pegasys.teku.data.slashinginterchange.SlashingProtectionInterchangeFormat in project teku by ConsenSys.

the class SlashingProtectionExporterTest method shouldReadSlashingProtectionFile_withEmptyGenesisValidatorsRoot.

@Test
public void shouldReadSlashingProtectionFile_withEmptyGenesisValidatorsRoot(@TempDir Path tempDir) throws IOException, URISyntaxException {
    final SlashingProtectionExporter exporter = new SlashingProtectionExporter(tempDir);
    Optional<String> error = exporter.readSlashProtectionFile(usingResourceFile("slashProtection.yml", tempDir), log::add);
    assertThat(log).containsExactly("Exporting " + pubkey);
    assertThat(error).isEmpty();
    final SlashingProtectionInterchangeFormat parsedData = jsonProvider.jsonToObject(exporter.getPrettyJson(), SlashingProtectionInterchangeFormat.class);
    final SlashingProtectionInterchangeFormat expectedData = getExportData(null, 327, 51, 1741);
    assertThat(parsedData).isEqualTo(expectedData);
}
Also used : SlashingProtectionInterchangeFormat(tech.pegasys.teku.data.slashinginterchange.SlashingProtectionInterchangeFormat) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 SlashingProtectionInterchangeFormat (tech.pegasys.teku.data.slashinginterchange.SlashingProtectionInterchangeFormat)3 Path (java.nio.file.Path)1 ValidatorSigningRecord (tech.pegasys.teku.data.signingrecord.ValidatorSigningRecord)1 SignedBlock (tech.pegasys.teku.data.slashinginterchange.SignedBlock)1 SigningHistory (tech.pegasys.teku.data.slashinginterchange.SigningHistory)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1