use of com.hedera.mirror.importer.domain.StreamFileData in project hedera-mirror-node by hashgraph.
the class RecordFileReaderTest method verifyRecordItemLinksInValidFile.
@SneakyThrows
@TestFactory
Stream<DynamicTest> verifyRecordItemLinksInValidFile() {
String template = "read file %s containing eth transactions";
var resourceResolver = new PathMatchingResourcePatternResolver();
return DynamicTest.stream(getFilteredFiles(false), (recordFile) -> String.format(template, recordFile.getVersion(), recordFile.getName()), (recordFile) -> {
// given
Path testFile = getTestFile(recordFile);
StreamFileData streamFileData = StreamFileData.from(testFile.toFile());
// when
RecordFile actual = recordFileReader.read(streamFileData);
// then
RecordItem previousItem = null;
for (var item : actual.getItems().collectList().block()) {
// assert previous link points to previous item
assertThat(item.getPrevious()).isEqualTo(previousItem);
previousItem = item;
}
});
}
use of com.hedera.mirror.importer.domain.StreamFileData in project hedera-mirror-node by hashgraph.
the class RecordFileReaderTest method readInvalidFileWithDataTruncated.
@TestFactory
Stream<DynamicTest> readInvalidFileWithDataTruncated() {
String template = "read incomplete version %d file %s";
return DynamicTest.stream(getFilteredFiles(false), (recordFile) -> String.format(template, recordFile.getVersion(), recordFile.getName()), (recordFile) -> {
// given
Path testFile = getTestFile(recordFile);
byte[] bytes = FileUtils.readFileToByteArray(testFile.toFile());
byte[] bytesTruncated = ArrayUtils.subarray(bytes, 0, bytes.length - 48);
StreamFileData streamFileData = StreamFileData.from(recordFile.getName(), bytesTruncated);
// when
assertThrows(InvalidStreamFileException.class, () -> recordFileReader.read(streamFileData));
});
}
use of com.hedera.mirror.importer.domain.StreamFileData in project hedera-mirror-node by hashgraph.
the class RecordFileReaderTest method readValidFile.
@TestFactory
Stream<DynamicTest> readValidFile() {
String template = "read valid version %d file %s";
return DynamicTest.stream(getFilteredFiles(false), (recordFile) -> String.format(template, recordFile.getVersion(), recordFile.getName()), (recordFile) -> {
// given
Path testFile = getTestFile(recordFile);
StreamFileData streamFileData = StreamFileData.from(testFile.toFile());
// when
RecordFile actual = recordFileReader.read(streamFileData);
// then
assertThat(actual).usingRecursiveComparison().ignoringFields("bytes", "items", "loadStart", "logsBloomAggregator").isEqualTo(recordFile);
assertThat(actual.getBytes()).isNotEmpty().isEqualTo(streamFileData.getBytes());
assertThat(actual.getLoadStart()).isNotNull().isPositive();
List<Long> timestamps = actual.getItems().map(RecordItem::getConsensusTimestamp).collectList().block();
assertThat(timestamps).first().isEqualTo(recordFile.getConsensusStart());
assertThat(timestamps).last().isEqualTo(recordFile.getConsensusEnd());
assertThat(timestamps).doesNotHaveDuplicates().isSorted();
List<Integer> transactionIndexes = actual.getItems().map(RecordItem::getTransactionIndex).collectList().block();
assertThat(transactionIndexes).first().isEqualTo(0);
assertThat(transactionIndexes).isEqualTo(IntStream.range(0, recordFile.getCount().intValue()).boxed().collect(Collectors.toList()));
assertThat(transactionIndexes).doesNotHaveDuplicates().isSorted();
});
}
use of com.hedera.mirror.importer.domain.StreamFileData in project hedera-mirror-node by hashgraph.
the class CompositeSignatureFileReaderTest method testValidV5.
@Test
void testValidV5() throws Exception {
byte[] versionNumber = { SignatureFileReaderV5.SIGNATURE_FILE_FORMAT_VERSION };
byte[] randomExtraBytes = new byte[3];
SecureRandom.getInstanceStrong().nextBytes(randomExtraBytes);
byte[] bytes = Bytes.concat(versionNumber, randomExtraBytes);
StreamFileData streamFileData = StreamFileData.from(SIGNATURE_FILENAME, bytes);
compositeBalanceFileReader.read(streamFileData);
verify(signatureFileReaderV5, times(1)).read(any(StreamFileData.class));
verify(signatureFileReaderV2, times(0)).read(any(StreamFileData.class));
}
use of com.hedera.mirror.importer.domain.StreamFileData in project hedera-mirror-node by hashgraph.
the class CompositeSignatureFileReaderTest method testBlankFile.
@Test
void testBlankFile() {
StreamFileData blankFileData = StreamFileData.from(SIGNATURE_FILENAME, new byte[0]);
SignatureFileParsingException exception = assertThrows(SignatureFileParsingException.class, () -> {
compositeBalanceFileReader.read(blankFileData);
});
assertAll(() -> assertTrue(exception.getMessage().contains("Error reading signature file")), () -> assertTrue(exception.getCause() instanceof IOException));
}
Aggregations