Skip to content

Commit

Permalink
Feat/return empty assets (#246)
Browse files Browse the repository at this point in the history
* feat: added empty response if no amount is found

* feat: added empty response if no amount is found

* feat: fixed tests
  • Loading branch information
Kammerlo authored Sep 30, 2024
1 parent b71e335 commit c8b79b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ public List<Amount> mapAddressBalancesToAmounts(List<AddressBalance> balances) {
.findFirst()
.orElse(BigInteger.ZERO);
List<Amount> amounts = new ArrayList<>();
if (lovelaceAmount.compareTo(BigInteger.ZERO) > 0) {
amounts.add(DataMapper.mapAmount(String.valueOf(lovelaceAmount), null, null, null));
}
// always adding lovelace amount to the beginning of the list. Even if lovelace amount is 0
amounts.add(DataMapper.mapAmount(String.valueOf(lovelaceAmount), null, null, null));
balances.stream()
.filter(b -> !Constants.LOVELACE.equals(b.unit()))
.forEach(b -> amounts.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void getAccountBalanceStakeAddressPositiveTest() {
AccountBalanceResponse actual = accountService.getAccountBalance(accountBalanceRequest);

assertNotNull(actual);
assertEquals("1000", actual.getBalances().getFirst().getValue());
assertEquals("1000", actual.getBalances().get(1).getValue());
assertNotNull(actual.getBalances().getFirst().getCurrency().getSymbol());
assertEquals(blockIdentifier.getIndex(), actual.getBlockIdentifier().getIndex());
assertEquals(blockIdentifier.getHash(), actual.getBlockIdentifier().getHash());
Expand Down Expand Up @@ -180,8 +180,8 @@ void getAccountBalanceStakeAddressWithEmptyBalancesThrowTest() {

assertEquals(block.getHash(), actual.getBlockIdentifier().getHash());
assertEquals(block.getNumber(), actual.getBlockIdentifier().getIndex());
assertEquals("1000", actual.getBalances().getFirst().getValue());
assertEquals("4c4943454e5345", actual.getBalances().getFirst().getCurrency().getSymbol());
assertEquals("1000", actual.getBalances().get(1).getValue());
assertEquals("4c4943454e5345", actual.getBalances().get(1).getCurrency().getSymbol());
verify(ledgerBlockService).findBlockIdentifier(1L, HASH);
verify(ledgerAccountService)
.findBalanceByStakeAddressAndBlock(accountAddress, 1L);
Expand Down Expand Up @@ -249,8 +249,8 @@ void getAccountBalanceWithStakeAddressAndNullBalanceThrowTest() {

assertEquals(block.getHash(), actual.getBlockIdentifier().getHash());
assertEquals(block.getNumber(), actual.getBlockIdentifier().getIndex());
assertEquals("1000", actual.getBalances().getFirst().getValue());
assertEquals("4c4943454e5345", actual.getBalances().getFirst().getCurrency().getSymbol());
assertEquals("1000", actual.getBalances().get(1).getValue());
assertEquals("4c4943454e5345", actual.getBalances().get(1).getCurrency().getSymbol());
verify(ledgerBlockService).findBlockIdentifier(1L, HASH);
verify(ledgerAccountService)
.findBalanceByStakeAddressAndBlock(accountAddress, 1L);
Expand Down

0 comments on commit c8b79b2

Please sign in to comment.