Search in sources :

Example 6 with AccountBalance

use of com.hedera.mirror.common.domain.balance.AccountBalance in project hedera-mirror-node by hashgraph.

the class AccountBalanceFileParserTest method accountBalance.

private AccountBalance accountBalance(long timestamp, int offset) {
    EntityId accountId = EntityId.of(0, 0, offset + 1000, EntityType.ACCOUNT);
    EntityId tokenId = EntityId.of(0, 0, offset + 2000, EntityType.ACCOUNT);
    TokenBalance tokenBalance = new TokenBalance();
    tokenBalance.setBalance(offset);
    tokenBalance.setId(new TokenBalance.Id(timestamp, accountId, tokenId));
    AccountBalance accountBalance = new AccountBalance();
    accountBalance.setBalance(offset);
    accountBalance.setId(new AccountBalance.Id(timestamp, accountId));
    accountBalance.setTokenBalances(List.of(tokenBalance, tokenBalance));
    return accountBalance;
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance)

Example 7 with AccountBalance

use of com.hedera.mirror.common.domain.balance.AccountBalance in project hedera-mirror-node by hashgraph.

the class AccountBalanceFileParserTest method multipleBatches.

@Test
void multipleBatches() {
    // given
    int batchSize = parserProperties.getBatchSize();
    parserProperties.setBatchSize(2);
    AccountBalanceFile accountBalanceFile = accountBalanceFile(1);
    List<AccountBalance> items = accountBalanceFile.getItems().collectList().block();
    // when
    accountBalanceFileParser.parse(accountBalanceFile);
    // then
    assertAccountBalanceFile(accountBalanceFile, items);
    parserProperties.setBatchSize(batchSize);
}
Also used : AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 8 with AccountBalance

use of com.hedera.mirror.common.domain.balance.AccountBalance in project hedera-mirror-node by hashgraph.

the class AccountBalanceFileParserTest method success.

@Test
void success() {
    // given
    AccountBalanceFile accountBalanceFile = accountBalanceFile(1);
    List<AccountBalance> items = accountBalanceFile.getItems().collectList().block();
    // when
    accountBalanceFileParser.parse(accountBalanceFile);
    // then
    assertAccountBalanceFile(accountBalanceFile, items);
    assertThat(accountBalanceFile.getTimeOffset()).isZero();
}
Also used : AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 9 with AccountBalance

use of com.hedera.mirror.common.domain.balance.AccountBalance in project hedera-mirror-node by hashgraph.

the class CsvBalanceFileReaderTest method verifySuccess.

protected void verifySuccess(File file, AccountBalanceFile accountBalanceFile, int skipLines) throws IOException {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), CsvBalanceFileReader.CHARSET))) {
        while (skipLines > 0) {
            reader.readLine();
            skipLines--;
        }
        List<AccountBalance> accountBalances = accountBalanceFile.getItems().collectList().block();
        var lineIter = reader.lines().iterator();
        var accountBalanceIter = accountBalances.iterator();
        while (lineIter.hasNext()) {
            String line = lineIter.next();
            line = line.trim();
            if (line.isEmpty()) {
                continue;
            }
            try {
                AccountBalance expectedItem = parser.parse(line, consensusTimestamp);
                AccountBalance actualItem = accountBalanceIter.next();
                assertThat(actualItem).isEqualTo(expectedItem);
            } catch (InvalidDatasetException ex) {
            }
        }
        assertThat(accountBalanceIter.hasNext()).isFalse();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) BufferedReader(java.io.BufferedReader) FileInputStream(java.io.FileInputStream)

Example 10 with AccountBalance

use of com.hedera.mirror.common.domain.balance.AccountBalance 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)

Aggregations

AccountBalance (com.hedera.mirror.common.domain.balance.AccountBalance)18 AccountBalanceFile (com.hedera.mirror.common.domain.balance.AccountBalanceFile)10 TokenBalance (com.hedera.mirror.common.domain.balance.TokenBalance)7 Test (org.junit.jupiter.api.Test)7 EntityId (com.hedera.mirror.common.domain.entity.EntityId)6 InvalidDatasetException (com.hedera.mirror.importer.exception.InvalidDatasetException)5 IOException (java.io.IOException)5 Instant (java.time.Instant)5 List (java.util.List)5 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)4 InputStream (java.io.InputStream)4 Collectors (java.util.stream.Collectors)4 CodedInputStream (com.google.protobuf.CodedInputStream)3 UnknownFieldSet (com.google.protobuf.UnknownFieldSet)3 DomainUtils (com.hedera.mirror.common.util.DomainUtils)3 StreamFileData (com.hedera.mirror.importer.domain.StreamFileData)3 InvalidStreamFileException (com.hedera.mirror.importer.exception.InvalidStreamFileException)3 StreamFileReaderException (com.hedera.mirror.importer.exception.StreamFileReaderException)3 SingleAccountBalances (com.hedera.services.stream.proto.SingleAccountBalances)3 Timestamp (com.hederahashgraph.api.proto.java.Timestamp)3