use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenAccountReassociate.
@Test
void onTokenAccountReassociate() {
List<TokenAccount> expected = new ArrayList<>();
EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
// save token entities first
Token token = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
tokenRepository.save(token);
// token account was associated before this record file
EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
TokenAccount associate = getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.REVOKED);
tokenAccountRepository.save(associate);
expected.add(associate);
// when
TokenAccount freeze = getTokenAccount(tokenId1, accountId1, null, 10L, null, null, TokenFreezeStatusEnum.FROZEN, null);
sqlEntityListener.onTokenAccount(freeze);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 10L, true, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.REVOKED));
TokenAccount kycGrant = getTokenAccount(tokenId1, accountId1, null, 15L, null, null, null, TokenKycStatusEnum.GRANTED);
sqlEntityListener.onTokenAccount(kycGrant);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 15L, true, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.GRANTED));
TokenAccount dissociate = getTokenAccount(tokenId1, accountId1, null, 16L, false, null, null, null);
sqlEntityListener.onTokenAccount(dissociate);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 16L, false, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.GRANTED));
// associate after dissociate, the token has freeze key with freezeDefault = false, the token also has kyc key,
// so the new relationship should have UNFROZEN, REVOKED
TokenAccount reassociate = getTokenAccount(tokenId1, accountId1, 20L, 20L, true, false, null, null);
sqlEntityListener.onTokenAccount(reassociate);
expected.add(getTokenAccount(tokenId1, accountId1, 20L, 20L, true, false, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.REVOKED));
completeFileAndCommit();
// then
assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrderElementsOf(expected);
}
use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenAccountMissingLastAssociation.
@Test
void onTokenAccountMissingLastAssociation() {
EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
// given token in db and missing last account token association
Token token = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
tokenRepository.save(token);
// when
TokenAccount freeze = getTokenAccount(tokenId1, accountId1, null, 10L, null, null, TokenFreezeStatusEnum.FROZEN, null);
sqlEntityListener.onTokenAccount(freeze);
TokenAccount kycGrant = getTokenAccount(tokenId1, accountId1, null, 15L, null, null, null, TokenKycStatusEnum.GRANTED);
sqlEntityListener.onTokenAccount(kycGrant);
completeFileAndCommit();
// then
assertThat(tokenAccountRepository.count()).isZero();
}
use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenAccountMerge.
@Test
void onTokenAccountMerge() {
EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
// save token entities first
Token token = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
sqlEntityListener.onToken(token);
// when
EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
TokenAccount tokenAccountAssociate = getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, null, null);
sqlEntityListener.onTokenAccount(tokenAccountAssociate);
TokenAccount tokenAccountKyc = getTokenAccount(tokenId1, accountId1, null, 15L, null, null, null, TokenKycStatusEnum.GRANTED);
sqlEntityListener.onTokenAccount(tokenAccountKyc);
completeFileAndCommit();
// then
TokenAccount tokenAccountMerged = getTokenAccount(tokenId1, accountId1, 5L, 15L, true, false, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.GRANTED);
assertThat(tokenAccountRepository.findAll()).hasSize(2).contains(tokenAccountMerged);
}
use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenAccountSpanningRecordFiles.
@Test
void onTokenAccountSpanningRecordFiles() {
List<TokenAccount> expected = new ArrayList<>();
EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
// given token in db
Token token = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
tokenRepository.save(token);
// given association in a previous record file
TokenAccount associate = getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, null, null);
sqlEntityListener.onTokenAccount(associate);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.REVOKED));
completeFileAndCommit();
// when in the next record file we have freeze, kycGrant, dissociate, associate, kycGrant
TokenAccount freeze = getTokenAccount(tokenId1, accountId1, null, 10L, null, null, TokenFreezeStatusEnum.FROZEN, null);
sqlEntityListener.onTokenAccount(freeze);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 10L, true, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.REVOKED));
TokenAccount kycGrant = getTokenAccount(tokenId1, accountId1, null, 12L, null, null, null, TokenKycStatusEnum.GRANTED);
sqlEntityListener.onTokenAccount(kycGrant);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 12L, true, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.GRANTED));
TokenAccount dissociate = getTokenAccount(tokenId1, accountId1, null, 15L, false, null, null, null);
sqlEntityListener.onTokenAccount(dissociate);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 15L, false, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.GRANTED));
associate = getTokenAccount(tokenId1, accountId1, 20L, 20L, true, true, null, null);
sqlEntityListener.onTokenAccount(associate);
expected.add(getTokenAccount(tokenId1, accountId1, 20L, 20L, true, true, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.REVOKED));
kycGrant = getTokenAccount(tokenId1, accountId1, null, 22L, null, null, null, TokenKycStatusEnum.GRANTED);
sqlEntityListener.onTokenAccount(kycGrant);
expected.add(getTokenAccount(tokenId1, accountId1, 20L, 22L, true, true, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.GRANTED));
completeFileAndCommit();
// then
assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrderElementsOf(expected);
}
use of com.hedera.mirror.common.domain.token.TokenAccount in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTokenTest method assertTokenAccountInRepository.
private void assertTokenAccountInRepository(TokenID tokenID, AccountID accountId, long createdTimestamp, long modifiedTimestamp, boolean associated, TokenFreezeStatusEnum freezeStatus, TokenKycStatusEnum kycStatus) {
TokenAccount expected = new TokenAccount(EntityId.of(tokenID), EntityId.of(accountId), modifiedTimestamp);
expected.setAssociated(associated);
expected.setAutomaticAssociation(false);
expected.setCreatedTimestamp(createdTimestamp);
expected.setFreezeStatus(freezeStatus);
expected.setKycStatus(kycStatus);
assertThat(tokenAccountRepository.findById(expected.getId())).get().isEqualTo(expected);
}
Aggregations