Search in sources :

Example 46 with StreamFileData

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;
        }
    });
}
Also used : Path(java.nio.file.Path) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) TestFactory(org.junit.jupiter.api.TestFactory) SneakyThrows(lombok.SneakyThrows)

Example 47 with StreamFileData

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));
    });
}
Also used : Path(java.nio.file.Path) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) TestFactory(org.junit.jupiter.api.TestFactory)

Example 48 with 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();
    });
}
Also used : Path(java.nio.file.Path) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) TestFactory(org.junit.jupiter.api.TestFactory)

Example 49 with StreamFileData

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));
}
Also used : StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) Test(org.junit.jupiter.api.Test)

Example 50 with StreamFileData

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));
}
Also used : SignatureFileParsingException(com.hedera.mirror.importer.exception.SignatureFileParsingException) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

StreamFileData (com.hedera.mirror.importer.domain.StreamFileData)51 Test (org.junit.jupiter.api.Test)40 AccountBalanceFile (com.hedera.mirror.common.domain.balance.AccountBalanceFile)8 Path (java.nio.file.Path)6 TestFactory (org.junit.jupiter.api.TestFactory)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 FileStreamSignature (com.hedera.mirror.importer.domain.FileStreamSignature)4 AllAccountBalances (com.hedera.services.stream.proto.AllAccountBalances)4 UnknownFieldSet (com.google.protobuf.UnknownFieldSet)3 RecordFile (com.hedera.mirror.common.domain.transaction.RecordFile)3 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)3 InvalidStreamFileException (com.hedera.mirror.importer.exception.InvalidStreamFileException)3 Instant (java.time.Instant)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 AccountBalance (com.hedera.mirror.common.domain.balance.AccountBalance)2 TokenBalance (com.hedera.mirror.common.domain.balance.TokenBalance)2 EntityId (com.hedera.mirror.common.domain.entity.EntityId)2 EventFile (com.hedera.mirror.common.domain.event.EventFile)2 DomainUtils (com.hedera.mirror.common.util.DomainUtils)2 StreamFilename (com.hedera.mirror.importer.domain.StreamFilename)2