Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hbar and token transfer tests #10152

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import com.hedera.mirror.common.domain.balance.AccountBalance;
import com.hedera.mirror.common.domain.balance.TokenBalance;
import com.hedera.mirror.common.domain.entity.Entity;
import com.hedera.mirror.common.domain.entity.EntityId;
import com.hedera.mirror.common.domain.entity.EntityType;
Expand Down Expand Up @@ -273,6 +274,30 @@ protected void tokenAccountPersist(final Entity token, final Long accountId) {
.persist();
}

protected void persistAccountBalance(Entity account, long balance, long timestamp) {
domainBuilder
.accountBalance()
.customize(ab -> ab.id(new AccountBalance.Id(timestamp, account.toEntityId()))
.balance(balance))
.persist();
}

protected void persistAccountBalance(Entity account, long balance) {
domainBuilder
.accountBalance()
.customize(ab -> ab.id(new AccountBalance.Id(account.getCreatedTimestamp(), account.toEntityId()))
.balance(balance))
.persist();
}

protected void persistTokenBalance(Entity account, Entity token, long timestamp) {
domainBuilder
.tokenBalance()
.customize(ab -> ab.id(new TokenBalance.Id(timestamp, account.toEntityId(), token.toEntityId()))
.balance(100))
.persist();
}

protected String getAddressFromEntity(Entity entity) {
return EvmTokenUtils.toAddress(entity.toEntityId()).toHexString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,11 @@ void cryptoTransferHbars() throws Exception {
final var receiver = accountEntityWithEvmAddressPersist();
final var payer = accountEntityWithEvmAddressPersist();

long timestampForBalances = payer.getCreatedTimestamp();
persistAccountBalance(payer, payer.getBalance());
persistAccountBalance(sender, sender.getBalance(), timestampForBalances);
persistAccountBalance(treasuryEntity, treasuryEntity.getBalance(), timestampForBalances);

// When
testWeb3jService.setSender(getAliasFromEntity(payer));
final var transferList = new TransferList(List.of(
Expand All @@ -1241,10 +1246,19 @@ void cryptoTransferToken() throws Exception {
final var receiver = accountEntityWithEvmAddressPersist();
final var payer = accountEntityWithEvmAddressPersist();

tokenAccountPersist(tokenEntity, payer);
long timestampForBalances = payer.getCreatedTimestamp();
persistAccountBalance(payer, payer.getBalance());
persistTokenBalance(payer, tokenEntity, timestampForBalances);

persistAccountBalance(sender, sender.getBalance(), timestampForBalances);
persistTokenBalance(sender, tokenEntity, timestampForBalances);

persistTokenBalance(receiver, tokenEntity, timestampForBalances);
persistAccountBalance(treasuryEntity, treasuryEntity.getBalance(), timestampForBalances);

tokenAccountPersist(tokenEntity, sender);
tokenAccountPersist(tokenEntity, receiver);

tokenAccountPersist(tokenEntity, payer);
// When
testWeb3jService.setSender(getAliasFromEntity(payer));
final var tokenTransferList = new TokenTransferList(
Expand Down Expand Up @@ -1273,9 +1287,20 @@ void cryptoTransferHbarsAndToken() throws Exception {
final var receiver = accountEntityWithEvmAddressPersist();
final var payer = accountEntityWithEvmAddressPersist();

tokenAccountPersist(tokenEntity, payer);
long timestampForBalances = payer.getCreatedTimestamp();
persistAccountBalance(payer, payer.getBalance());
persistTokenBalance(payer, tokenEntity, timestampForBalances);

persistAccountBalance(sender, sender.getBalance(), timestampForBalances);
persistTokenBalance(sender, tokenEntity, timestampForBalances);

persistTokenBalance(receiver, tokenEntity, timestampForBalances);

persistAccountBalance(treasuryEntity, treasuryEntity.getBalance(), timestampForBalances);

tokenAccountPersist(tokenEntity, sender);
tokenAccountPersist(tokenEntity, receiver);
tokenAccountPersist(tokenEntity, payer);

// When
testWeb3jService.setSender(getAliasFromEntity(payer));
Expand Down
Loading