Search in sources :

Example 26 with ValidatorConfig

use of tech.pegasys.teku.validator.api.ValidatorConfig in project teku by ConsenSys.

the class ValidatorLoaderTest method initializeValidatorsWithExternalSignerAndNoSlashingProtection.

@Test
void initializeValidatorsWithExternalSignerAndNoSlashingProtection() {
    final ValidatorConfig config = ValidatorConfig.builder().validatorExternalSignerUrl(SIGNER_URL).validatorExternalSignerPublicKeySources(Collections.singletonList(PUBLIC_KEY1.toString())).validatorExternalSignerSlashingProtectionEnabled(false).build();
    final ValidatorLoader validatorLoader = ValidatorLoader.create(spec, config, disabledInteropConfig, httpClientFactory, slashingProtector, slashingProtectionLogger, publicKeyLoader, asyncRunner, metricsSystem, Optional.empty());
    validatorLoader.loadValidators();
    final OwnedValidators validators = validatorLoader.getOwnedValidators();
    assertThat(validators.getValidatorCount()).isEqualTo(1);
    final Validator validator = validators.getValidator(PUBLIC_KEY1).orElseThrow();
    assertThat(validator).isNotNull();
    assertThat(validator.getPublicKey()).isEqualTo(PUBLIC_KEY1);
    assertThat(validator.getSigner().isLocal()).isFalse();
    final BeaconBlock block = dataStructureUtil.randomBeaconBlock(10);
    final ForkInfo forkInfo = dataStructureUtil.randomForkInfo();
    when(slashingProtector.maySignBlock(PUBLIC_KEY1, forkInfo.getGenesisValidatorsRoot(), block.getSlot())).thenReturn(SafeFuture.completedFuture(true));
    when(httpClient.sendAsync(any(), any())).thenReturn(new SafeFuture<>());
    final SafeFuture<BLSSignature> result = validator.getSigner().signBlock(block, forkInfo);
    assertThat(result).isNotDone();
    // Confirm request was sent without checking with the slashing protector
    verifyNoInteractions(slashingProtector);
    verify(httpClient).sendAsync(any(), any());
}
Also used : ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) Validator(tech.pegasys.teku.validator.client.Validator) BLSSignature(tech.pegasys.teku.bls.BLSSignature) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ValidatorConfig (tech.pegasys.teku.validator.api.ValidatorConfig)26 Test (org.junit.jupiter.api.Test)23 Validator (tech.pegasys.teku.validator.client.Validator)10 AbstractBeaconNodeCommandTest (tech.pegasys.teku.cli.AbstractBeaconNodeCommandTest)6 SimpleDataDirLayout (tech.pegasys.techu.service.serviceutils.layout.SimpleDataDirLayout)4 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)4 URL (java.net.URL)3 DataDirLayout (tech.pegasys.teku.service.serviceutils.layout.DataDirLayout)3 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)3 ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)3 HttpClientExternalSignerFactory (tech.pegasys.teku.validator.client.loader.HttpClientExternalSignerFactory)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 InteropConfig (tech.pegasys.teku.validator.api.InteropConfig)2 PostKeyResult (tech.pegasys.teku.validator.client.restapi.apis.schema.PostKeyResult)2 DeleteKeyResult (tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult)1