diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/DebugDataDumperTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/DebugDataDumperTest.java index 6e4b4094800..a2e8bfdc6ce 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/DebugDataDumperTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/DebugDataDumperTest.java @@ -17,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.fail; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.NoSuchFileException; @@ -122,13 +123,24 @@ void saveInvalidBlockToFile_shouldNotSaveToFileWhenDisabled(@TempDir Path tempDi } @Test - void saveBytesToFile_shouldNotThrowExceptionWhenUnableToSave(@TempDir Path tempDir) { + void saveBytesToFile_shouldNotThrowExceptionWhenNoDirectory(@TempDir Path tempDir) { final DebugDataDumper manager = new DebugDataDumper(tempDir, true); assertDoesNotThrow( () -> manager.saveBytesToFile("object", Path.of("invalid").resolve("file.ssz"), Bytes.EMPTY)); } + @Test + void saveBytesToFile_shouldNotEscalateWhenIOException(@TempDir Path tempDir) { + final DebugDataDumper manager = new DebugDataDumper(tempDir, true); + final File invalidPath = tempDir.resolve("invalid").toFile(); + assertThat(invalidPath.mkdirs()).isTrue(); + assertThat(invalidPath.setWritable(false)).isTrue(); + assertDoesNotThrow( + () -> + manager.saveBytesToFile("object", Path.of("invalid").resolve("file.ssz"), Bytes.EMPTY)); + } + private void checkBytesSavedToFile(final Path path, final Bytes expectedBytes) { try { final Bytes bytes = Bytes.wrap(Files.readAllBytes(path));