Search in sources :

Example 36 with StreamFileData

use of com.hedera.mirror.importer.domain.StreamFileData in project hedera-mirror-node by hashgraph.

the class CsvBalanceFileReaderTest method supportsInvalidWhenExceedsLineSize.

@Test
void supportsInvalidWhenExceedsLineSize() {
    String versionPrefix = balanceFileReader.getVersionHeaderPrefix();
    String prefix = " ".repeat(CsvBalanceFileReader.BUFFER_SIZE + 1);
    StreamFileData streamFileData = StreamFileData.from(balanceFile.getName(), prefix + versionPrefix);
    assertThat(balanceFileReader.supports(streamFileData)).isFalse();
}
Also used : StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) Test(org.junit.jupiter.api.Test)

Example 37 with StreamFileData

use of com.hedera.mirror.importer.domain.StreamFileData in project hedera-mirror-node by hashgraph.

the class ProtoBalanceFileReaderTest method getExpectedAccountBalanceFile.

private AccountBalanceFile getExpectedAccountBalanceFile(StreamFileData streamFileData) {
    Instant instant = Instant.parse(TIMESTAMP.replace("_", ":"));
    long consensusTimestamp = DomainUtils.convertToNanosMax(instant);
    long accountNum = 2000;
    long hbarBalance = 3000;
    long tokenNum = 5000;
    long tokenBalance = 6000;
    List<AccountBalance> accountBalances = IntStream.range(0, 10).mapToObj(i -> {
        EntityId accountId = EntityId.of(0, 0, accountNum + i, EntityType.ACCOUNT);
        List<TokenBalance> tokenBalances = IntStream.range(0, 5).mapToObj(j -> {
            EntityId tokenId = EntityId.of(0, 0, tokenNum + i * 5 + j, EntityType.TOKEN);
            return new TokenBalance(tokenBalance + i * 5 + j, new TokenBalance.Id(consensusTimestamp, accountId, tokenId));
        }).collect(Collectors.toList());
        return new AccountBalance(hbarBalance + i, tokenBalances, new AccountBalance.Id(consensusTimestamp, accountId));
    }).collect(Collectors.toList());
    return AccountBalanceFile.builder().bytes(streamFileData.getBytes()).consensusTimestamp(consensusTimestamp).fileHash("67c2fd054621366dd5a37b6ee36a51bc590361379d539fdac2265af08cb8097729218c7d9ff1f1e354c85b820c5b8cf8").items(Flux.fromIterable(accountBalances)).name(streamFileData.getFilename()).build();
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) EntityType(com.hedera.mirror.common.domain.entity.EntityType) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) TestUtils(com.hedera.mirror.importer.TestUtils) SingleAccountBalances(com.hedera.services.stream.proto.SingleAccountBalances) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) UnknownFieldSet(com.google.protobuf.UnknownFieldSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) DomainUtils(com.hedera.mirror.common.util.DomainUtils) Instant(java.time.Instant) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) Collectors(java.util.stream.Collectors) AllAccountBalances(com.hedera.services.stream.proto.AllAccountBalances) File(java.io.File) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) InvalidStreamFileException(com.hedera.mirror.importer.exception.InvalidStreamFileException) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Paths(java.nio.file.Paths) Assertions(org.junit.jupiter.api.Assertions) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) EntityId(com.hedera.mirror.common.domain.entity.EntityId) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) Instant(java.time.Instant) List(java.util.List) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) EntityId(com.hedera.mirror.common.domain.entity.EntityId)

Example 38 with StreamFileData

use of com.hedera.mirror.importer.domain.StreamFileData in project hedera-mirror-node by hashgraph.

the class ProtoBalanceFileReaderTest method emptyProtobuf.

@Test
void emptyProtobuf() {
    AllAccountBalances allAccountBalances = AllAccountBalances.newBuilder().build();
    byte[] bytes = allAccountBalances.toByteArray();
    StreamFileData streamFileData = StreamFileData.from(TIMESTAMP + "_Balances.pb", bytes);
    assertThrows(InvalidStreamFileException.class, () -> protoBalanceFileReader.read(streamFileData));
}
Also used : AllAccountBalances(com.hedera.services.stream.proto.AllAccountBalances) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with StreamFileData

use of com.hedera.mirror.importer.domain.StreamFileData in project hedera-mirror-node by hashgraph.

the class ProtoBalanceFileReaderTest method unknownFields.

@Test
void unknownFields() {
    UnknownFieldSet.Field field = UnknownFieldSet.Field.newBuilder().addFixed32(11).build();
    AllAccountBalances allAccountBalances = AllAccountBalances.newBuilder().setConsensusTimestamp(Timestamp.newBuilder().setSeconds(1L).build()).mergeUnknownFields(UnknownFieldSet.newBuilder().addField(23, field).build()).addAllAccounts(SingleAccountBalances.newBuilder().build()).build();
    byte[] bytes = allAccountBalances.toByteArray();
    StreamFileData streamFileData = StreamFileData.from(TIMESTAMP + "_Balances.pb", bytes);
    AccountBalanceFile accountBalanceFile = protoBalanceFileReader.read(streamFileData);
    assertThat(accountBalanceFile).isNotNull();
    assertThat(accountBalanceFile.getItems().count().block()).isEqualTo(1L);
}
Also used : AllAccountBalances(com.hedera.services.stream.proto.AllAccountBalances) AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) UnknownFieldSet(com.google.protobuf.UnknownFieldSet) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with StreamFileData

use of com.hedera.mirror.importer.domain.StreamFileData in project hedera-mirror-node by hashgraph.

the class EventFileReaderV3Test method readInvalidFileWithIncompletePrevHash.

@Test
void readInvalidFileWithIncompletePrevHash() {
    byte[] incompletePrevHash = new byte[EventFileReaderV3.EVENT_PREV_HASH_LENGTH - 2];
    StreamFileData invalidFile = createEventFile(EventFileReaderV3.EVENT_STREAM_FILE_VERSION_3, EventFileReaderV3.EVENT_TYPE_PREV_HASH, incompletePrevHash, null);
    assertThrows(InvalidEventFileException.class, () -> eventFileReader.read(invalidFile));
}
Also used : StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) 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