Search in sources :

Example 1 with MetadataFileHelpers

use of tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers in project web3signer by ConsenSys.

the class MetricsAcceptanceTest method signMetricIncrementsWhenSecpSignRequestReceived.

@Test
void signMetricIncrementsWhenSecpSignRequestReceived(@TempDir Path testDirectory) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
    final MetadataFileHelpers fileHelpers = new MetadataFileHelpers();
    final ECKeyPair keyPair = Keys.createEcKeyPair();
    fileHelpers.createUnencryptedYamlFileAt(testDirectory.resolve(keyPair.getPublicKey().toString() + ".yaml"), Numeric.toHexStringWithPrefixZeroPadded(keyPair.getPrivateKey(), 64), SECP256K1);
    final SignerConfiguration signerConfiguration = new SignerConfigurationBuilder().withMetricsCategories("SIGNING").withMetricsEnabled(true).withKeyStoreDirectory(testDirectory).withMode("eth1").build();
    startSigner(signerConfiguration);
    final List<String> metricsOfInterest = List.of("signing_" + SECP256K1.name().toLowerCase() + "_signing_duration_count", "signing_" + SECP256K1.name().toLowerCase() + "_missing_identifier_count");
    final Set<String> initialMetrics = signer.getMetricsMatching(metricsOfInterest);
    assertThat(initialMetrics).hasSize(metricsOfInterest.size());
    assertThat(initialMetrics).allMatch(s -> s.endsWith("0.0"));
    signer.eth1Sign(Numeric.toHexStringWithPrefixZeroPadded(keyPair.getPublicKey(), 128), Bytes.fromHexString("1122"));
    final Set<String> metricsAfterSign = signer.getMetricsMatching(metricsOfInterest);
    assertThat(metricsAfterSign).containsOnly("signing_" + SECP256K1.name().toLowerCase() + "_signing_duration_count 1.0", "signing_" + SECP256K1.name().toLowerCase() + "_missing_identifier_count 0.0");
}
Also used : SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) ECKeyPair(org.web3j.crypto.ECKeyPair) SignerConfiguration(tech.pegasys.web3signer.dsl.signer.SignerConfiguration) MetadataFileHelpers(tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with MetadataFileHelpers

use of tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers in project web3signer by ConsenSys.

the class MetricsAcceptanceTest method signMetricIncrementsWhenBlsSignRequestReceived.

@Test
void signMetricIncrementsWhenBlsSignRequestReceived(@TempDir Path testDirectory) throws JsonProcessingException {
    final MetadataFileHelpers fileHelpers = new MetadataFileHelpers();
    final BLSKeyPair keyPair = BLSTestUtil.randomKeyPair(1);
    fileHelpers.createUnencryptedYamlFileAt(testDirectory.resolve(keyPair.getPublicKey().toBytesCompressed().toHexString() + ".yaml"), keyPair.getSecretKey().toBytes().toHexString(), BLS);
    final SignerConfiguration signerConfiguration = new SignerConfigurationBuilder().withMetricsCategories("SIGNING").withMetricsEnabled(true).withKeyStoreDirectory(testDirectory).withMode("eth2").build();
    startSigner(signerConfiguration);
    final List<String> metricsOfInterest = List.of("signing_" + BLS.name().toLowerCase() + "_signing_duration_count", "signing_" + BLS.name().toLowerCase() + "_missing_identifier_count");
    final Set<String> initialMetrics = signer.getMetricsMatching(metricsOfInterest);
    assertThat(initialMetrics).hasSize(metricsOfInterest.size());
    assertThat(initialMetrics).allMatch(s -> s.endsWith("0.0"));
    signer.eth2Sign(keyPair.getPublicKey().toBytesCompressed().toHexString(), Eth2RequestUtils.createBlockRequest(UInt64.valueOf(1), Bytes32.fromHexString("0x1111")));
    final Set<String> metricsAfterSign = signer.getMetricsMatching(metricsOfInterest);
    assertThat(metricsAfterSign).containsOnly("signing_" + BLS.name().toLowerCase() + "_signing_duration_count 1.0", "signing_" + BLS.name().toLowerCase() + "_missing_identifier_count 0.0");
}
Also used : SignerConfigurationBuilder(tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder) SignerConfiguration(tech.pegasys.web3signer.dsl.signer.SignerConfiguration) MetadataFileHelpers(tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 SignerConfiguration (tech.pegasys.web3signer.dsl.signer.SignerConfiguration)2 SignerConfigurationBuilder (tech.pegasys.web3signer.dsl.signer.SignerConfigurationBuilder)2 MetadataFileHelpers (tech.pegasys.web3signer.dsl.utils.MetadataFileHelpers)2 ECKeyPair (org.web3j.crypto.ECKeyPair)1 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)1