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;
}
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);
}
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();
}
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();
}
}
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();
}
Aggregations