Search in sources :

Example 1 with TokenAccount

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);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) ArrayList(java.util.ArrayList) Token(com.hedera.mirror.common.domain.token.Token) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TokenAccount

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();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) Token(com.hedera.mirror.common.domain.token.Token) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with TokenAccount

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);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) Token(com.hedera.mirror.common.domain.token.Token) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with TokenAccount

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);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) ArrayList(java.util.ArrayList) Token(com.hedera.mirror.common.domain.token.Token) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with TokenAccount

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);
}
Also used : TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount)

Aggregations

TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)27 EntityId (com.hedera.mirror.common.domain.entity.EntityId)18 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 Token (com.hedera.mirror.common.domain.token.Token)8 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)8 Transaction (com.hederahashgraph.api.proto.java.Transaction)2 ArrayList (java.util.ArrayList)2 ByteString (com.google.protobuf.ByteString)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1 TokenAccountKey (com.hedera.mirror.common.domain.token.TokenAccountKey)1 TokenFreezeStatusEnum (com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum)1 TokenId (com.hedera.mirror.common.domain.token.TokenId)1 TokenKycStatusEnum (com.hedera.mirror.common.domain.token.TokenKycStatusEnum)1 TokenPauseStatusEnum (com.hedera.mirror.common.domain.token.TokenPauseStatusEnum)1 TokenTransfer (com.hedera.mirror.common.domain.token.TokenTransfer)1 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)1 AccountID (com.hederahashgraph.api.proto.java.AccountID)1 ContractFunctionResult (com.hederahashgraph.api.proto.java.ContractFunctionResult)1 TokenAssociateTransactionBody (com.hederahashgraph.api.proto.java.TokenAssociateTransactionBody)1