use of com.hedera.mirror.common.domain.balance.TokenBalance 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.TokenBalance 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();
}
use of com.hedera.mirror.common.domain.balance.TokenBalance in project hedera-mirror-node by hashgraph.
the class AccountBalanceLineParserV2Test method parse.
@DisplayName("Parse account balance line")
@ParameterizedTest(name = "from \"{0}\"")
@CsvSource(value = { "'0,0,123,700,CggKAxjsBxCEBwoHCgMY7QcQGQoKCgMY7gcQwKilBAoICgMY8gcQhAcKBwoDGPMHEBkKCgoDGPQHEMCopQQ';false;" + "0;123;700;1004=900,1005=25,1006=9000000,1010=900,1011=25,1012=9000000", "'0,0,123,700,';false;" + "0;123;700;;", "'0,0,123,700,CggKAxjsBxCEBwoHCgMY7QcQGQoKCgMY7gcQwKilBAoICgMY8gcQhAcKBwoDGPMHEBkKCgo';true;;;;", "' 0,0,123,700,CggKAxjsBxCEBwoHCgMY7QcQGQoKCgMY7gcQwKilBAoICgMY8gcQhAcKBwoDGPMHEBkKCgoDGPQHEMCopQQ';" + "false;0;123;700;1004=900,1005=25,1006=9000000,1010=900,1011=25,1012=9000000", "'0, 0,123,700,CggKAxjsBxCEBwoHCgMY7QcQGQoKCgMY7gcQwKilBAoICgMY8gcQhAcKBwoDGPMHEBkKCgoDGPQHEMCopQQ';" + "false;0;123;700;1004=900,1005=25,1006=9000000,1010=900,1011=25,1012=9000000", "'0,0, 123,700,CggKAxjsBxCEBwoHCgMY7QcQGQoKCgMY7gcQwKilBAoICgMY8gcQhAcKBwoDGPMHEBkKCgoDGPQHEMCopQQ';" + "false;0;123;700;1004=900,1005=25,1006=9000000,1010=900,1011=25,1012=9000000", "'0,0,123, 700,CggKAxjsBxCEBwoHCgMY7QcQGQoKCgMY7gcQwKilBAoICgMY8gcQhAcKBwoDGPMHEBkKCgoDGPQHEMCopQQ';" + "false;0;123;700;1004=900,1005=25,1006=9000000,1010=900,1011=25,1012=9000000", "'0,0,123,700, CggKAxjsBxCEBwoHCgMY7QcQGQoKCgMY7gcQwKilBAoICgMY8gcQhAcKBwoDGPMHEBkKCgoDGPQHEMCopQQ';" + "false;0;123;700;1004=900,1005=25,1006=9000000,1010=900,1011=25,1012=9000000", "'0,0,123,700,CggKAxjsBxCEBwoHCgMY7QcQGQoKCgMY7gcQwKilBAoICgMY8gcQhAcKBwoDGPMHEBkKCgoDGPQHEMCopQQ ';" + "false;0;123;700;1004=900,1005=25,1006=9000000,1010=900,1011=25,1012=9000000", "'1,0,123,700,';true;;;;", "'x,0,123,700,';true;;;;", "'0,x,123,700,';true;;;;", "'0,0,x,700,';true;;;;", "'0,0,123,a00,';true;;;;", "'1000000000000000000000000000,0,123,700,';true;;;;", "'0,1000000000000000000000000000,123,700,';true;;;;", "'0,0,1000000000000000000000000000,700,';true;;;;", "'0,0,123,1000000000000000000000000000,';true;;;;", "'-1,0,123,700,';true;;;;", "'0,-1,123,700,';true;;;;", "'0,0,-1,700,';true;;;;", "'0,0,123,-1,';true;;;;", "'foobar';true;;;;", "'';true;;;;", ";true;;;;" }, delimiter = ';')
void parse(String line, boolean expectThrow, Long expectedRealm, Long expectedAccount, Long expectedBalance, String tokenBalances) throws IOException {
if (!expectThrow) {
AccountBalance accountBalance = parser.parse(line, timestamp);
var id = accountBalance.getId();
assertThat(accountBalance.getBalance()).isEqualTo(expectedBalance);
assertThat(id).isNotNull();
assertThat(id.getAccountId().getRealmNum()).isEqualTo(expectedRealm);
assertThat(id.getAccountId().getEntityNum()).isEqualTo(expectedAccount);
assertThat(id.getConsensusTimestamp()).isEqualTo(timestamp);
List<TokenBalance> actualTokenBalanceList = accountBalance.getTokenBalances();
if (StringUtils.isNotBlank(tokenBalances)) {
Map<Long, Long> expectedTokenBalances = Splitter.on(',').withKeyValueSeparator('=').split(tokenBalances).entrySet().stream().collect(Collectors.toMap(entry -> Long.parseLong(entry.getKey()), entry -> Long.parseLong(entry.getValue())));
assertThat(actualTokenBalanceList.size()).isEqualTo(expectedTokenBalances.size());
for (int i = 0; i < actualTokenBalanceList.size(); i++) {
TokenBalance actualTokenBalance = actualTokenBalanceList.get(i);
TokenBalance.Id actualId = actualTokenBalance.getId();
assertThat(expectedTokenBalances).containsKey(actualId.getTokenId().getEntityNum());
assertThat(actualTokenBalance.getBalance()).isEqualTo(expectedTokenBalances.get(actualId.getTokenId().getEntityNum()));
assertThat(actualId).isNotNull();
assertThat(actualId.getConsensusTimestamp()).isEqualTo(timestamp);
assertThat(actualId.getAccountId().getShardNum()).isEqualTo(mirrorProperties.getShard());
assertThat(actualId.getAccountId().getRealmNum()).isEqualTo(expectedRealm);
assertThat(actualId.getAccountId().getEntityNum()).isEqualTo(expectedAccount);
assertThat(actualId.getTokenId().getShardNum()).isEqualTo(mirrorProperties.getShard());
assertThat(actualId.getTokenId().getRealmNum()).isEqualTo(expectedRealm);
assertThat(actualId.getTokenId().getType()).isEqualTo(EntityType.TOKEN);
}
} else {
assertThat(actualTokenBalanceList.size()).isEqualTo(0);
}
} else {
assertThrows(InvalidDatasetException.class, () -> {
parser.parse(line, timestamp);
});
}
}
use of com.hedera.mirror.common.domain.balance.TokenBalance in project hedera-mirror-node by hashgraph.
the class AccountBalanceRepositoryTest method createTokenBalances.
private List<TokenBalance> createTokenBalances(long consensusTimestamp, int accountNum, long balance, int numberOfBalances) {
List<TokenBalance> tokenBalanceList = new ArrayList<>();
for (int i = 1; i <= numberOfBalances; i++) {
TokenBalance tokenBalance = new TokenBalance();
TokenBalance.Id id = new TokenBalance.Id();
id.setAccountId(EntityId.of(0, 0, accountNum, EntityType.ACCOUNT));
id.setConsensusTimestamp(consensusTimestamp);
id.setTokenId(EntityId.of(0, 1, i, EntityType.TOKEN));
tokenBalance.setBalance(balance);
tokenBalance.setId(id);
tokenBalanceList.add(tokenBalance);
}
return tokenBalanceList;
}
use of com.hedera.mirror.common.domain.balance.TokenBalance in project hedera-mirror-node by hashgraph.
the class TokenBalanceRepositoryTest method create.
private TokenBalance create(long consensusTimestamp, int accountNum, int tokenNum, long balance) {
TokenBalance tokenBalance = new TokenBalance();
TokenBalance.Id id = new TokenBalance.Id();
id.setAccountId(EntityId.of(0, 0, accountNum, EntityType.ACCOUNT));
id.setConsensusTimestamp(consensusTimestamp);
id.setTokenId(EntityId.of(0, 0, tokenNum, EntityType.TOKEN));
tokenBalance.setBalance(balance);
tokenBalance.setId(id);
return tokenBalanceRepository.save(tokenBalance);
}
Aggregations