Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Feb 5, 2025
1 parent 1c0f6eb commit 4690377
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.bls.keystore.KeyStoreLoader;
import tech.pegasys.teku.bls.keystore.model.KeyStoreData;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.async.StubAsyncRunner;
import tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException;
Expand Down Expand Up @@ -748,6 +749,39 @@ void shouldLoadMutableValidatorIfEnabled(@TempDir final Path tempDir) throws Exc
assertThat(validator.get().getGraffitiProvider()).isInstanceOf(UpdatableGraffitiProvider.class);
}

@Test
void shouldCheckKeystorePasswordWhenNotAddingValidatorToOwned(@TempDir final Path tempDir)
throws Exception {
final ValidatorConfig config = ValidatorConfig.builder().build();
final ValidatorLoader validatorLoader =
ValidatorLoader.create(
spec,
config,
disabledInteropConfig,
httpClientFactory,
slashingProtector,
slashingProtectionLogger,
publicKeyLoader,
asyncRunner,
metricsSystem,
Optional.of(new SimpleDataDirLayout(tempDir)),
(publicKey) -> Optional.empty());
validatorLoader.loadValidators();

final String keystoreString =
Resources.toString(Resources.getResource("pbkdf2TestVector.json"), StandardCharsets.UTF_8);
final KeyStoreData keystoreData = KeyStoreLoader.loadFromString(keystoreString);
ValidatorImportResult result =
validatorLoader.loadLocalMutableValidator(
keystoreData, "incorrectPassword", Optional.empty(), false);
assertThat(result.getPostKeyResult().getImportStatus()).isEqualTo(ImportStatus.ERROR);
assertThat(result.getPostKeyResult().getMessage())
.isEqualTo(
Optional.of(
"Invalid keystore password for public key: "
+ keystoreData.getAbbreviatedPubKey()));
}

@Test
void doNotInitializeInteropValidatorsWhenInteropIsDisabled() {
final int ownedValidatorCount = 10;
Expand Down

0 comments on commit 4690377

Please sign in to comment.