use of tech.pegasys.web3signer.slashingprotection.dao.Validator in project web3signer by ConsenSys.
the class InterchangeV5Importer method parseValidator.
private void parseValidator(final Handle handle, final JsonNode node, final Optional<List<String>> pubkeys) throws JsonProcessingException {
if (node.isArray()) {
throw new IllegalStateException("Element of 'data' was not an object");
}
final ObjectNode parentNode = (ObjectNode) node;
final String pubKey = parentNode.required("pubkey").textValue();
if (pubkeys.isPresent() && !pubkeys.get().contains(pubKey)) {
LOG.info("Skipping data import for validator " + pubKey);
return;
}
final List<Validator> validators = validatorsDao.registerValidators(handle, List.of(Bytes.fromHexString(pubKey)));
if (validators.isEmpty()) {
throw new IllegalStateException("Unable to register validator " + pubKey);
}
final Validator validator = validators.get(0);
final ArrayNode signedBlocksNode = parentNode.withArray("signed_blocks");
importBlocks(handle, validator, signedBlocksNode);
final ArrayNode signedAttestationNode = parentNode.withArray("signed_attestations");
importAttestations(handle, validator, signedAttestationNode);
}
use of tech.pegasys.web3signer.slashingprotection.dao.Validator in project web3signer by ConsenSys.
the class InterchangeV5ExporterTest method populateInterchangeDataThrowsUncheckedIOException.
@Test
public void populateInterchangeDataThrowsUncheckedIOException() {
final DatabaseUtil.TestDatabaseInfo testDatabaseInfo = DatabaseUtil.createWithoutMigration();
final Jdbi jdbi = testDatabaseInfo.getJdbi();
final InterchangeV5Exporter exporter = new InterchangeV5Exporter(jdbi, validatorsDao, signedBlocksDao, signedAttestationsDao, metadataDao, lowWatermarkDao);
final Validator validator = new Validator(1, Bytes.fromHexString(PUBLIC_KEY));
when(validatorsDao.retrieveValidators(any(), any())).thenReturn(List.of(validator));
when(lowWatermarkDao.findLowWatermarkForValidator(any(), eq(1))).thenReturn(Optional.of(new SigningWatermark()));
// throw exception as the defaultAnswer as we don't care which json method is the cause
final JsonGenerator mockJsonGenerator = mock(JsonGenerator.class, __ -> {
throw new IOException("fake json error");
});
assertThatThrownBy(() -> exporter.populateInterchangeData(mockJsonGenerator, PUBLIC_KEY)).isInstanceOf(UncheckedIOException.class).hasMessage("Failed to construct a validator entry in json").hasRootCauseMessage("fake json error");
}
Aggregations