Skip to content

Commit

Permalink
Add test for when management structure already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 18, 2024
1 parent cf19ffb commit 2cb4983
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static tech.pegasys.teku.validator.api.GraffitiManager.GRAFFITI_MANAGEMENT_DIR;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -149,6 +150,21 @@ void deleteGraffiti_shouldThrowExceptionWhenUnableToWriteFile(@TempDir final Pat
.hasValue("java.nio.file.AccessDeniedException: " + file);
}

@Test
void shouldSetAndDeleteGraffitiWhenManagementPreexisting(@TempDir final Path tempDir) {
dataDirLayout = new SimpleDataDirLayout(tempDir);
final Path managementDir = getGraffitiManagementDir();
assertThat(managementDir.toFile().mkdirs()).isTrue();

manager = new GraffitiManager(dataDirLayout);

assertThat(manager.setGraffiti(publicKey, graffiti)).isEmpty();
checkGraffitiFile(publicKey, graffiti);

assertThat(manager.deleteGraffiti(publicKey)).isEmpty();
checkGraffitiFile(publicKey, "");
}

private void checkGraffitiFile(final BLSPublicKey publicKey, final String graffiti) {
final Path filePath = getGraffitiManagementDir().resolve(getFileName(publicKey));
try {
Expand All @@ -161,7 +177,7 @@ private void checkGraffitiFile(final BLSPublicKey publicKey, final String graffi
}

private Path getGraffitiManagementDir() {
return dataDirLayout.getValidatorDataDirectory().resolve("graffiti-management");
return dataDirLayout.getValidatorDataDirectory().resolve(GRAFFITI_MANAGEMENT_DIR);
}

private String getFileName(final BLSPublicKey publicKey) {
Expand Down

0 comments on commit 2cb4983

Please sign in to comment.