Search in sources :

Example 1 with Token

use of com.hedera.mirror.common.domain.token.Token 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 Token

use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method onTokenMerge.

@Test
void onTokenMerge() {
    EntityId tokenId = EntityId.of("0.0.3", TOKEN);
    EntityId accountId = EntityId.of("0.0.500", ACCOUNT);
    // save token entities first
    Token token = getToken(tokenId, accountId, 1L, 1L, 1000, false, keyFromString(KEY), 1_000_000_000L, null, "FOO COIN TOKEN", null, "FOOTOK", null, null, TokenPauseStatusEnum.UNPAUSED);
    sqlEntityListener.onToken(token);
    Token tokenUpdated = getToken(tokenId, accountId, null, 5L, null, null, null, null, keyFromString(KEY2), "BAR COIN TOKEN", keyFromString(KEY), "BARTOK", keyFromString(KEY2), keyFromString(KEY2), TokenPauseStatusEnum.UNPAUSED);
    sqlEntityListener.onToken(tokenUpdated);
    completeFileAndCommit();
    // then
    Token tokenMerged = getToken(tokenId, accountId, 1L, 5L, 1000, false, keyFromString(KEY), 1_000_000_000L, keyFromString(KEY2), "BAR COIN TOKEN", keyFromString(KEY), "BARTOK", keyFromString(KEY2), keyFromString(KEY2), TokenPauseStatusEnum.UNPAUSED);
    assertThat(tokenRepository.findAll()).containsExactlyInAnyOrder(tokenMerged);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) 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 Token

use of com.hedera.mirror.common.domain.token.Token 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 4 with Token

use of com.hedera.mirror.common.domain.token.Token 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 5 with Token

use of com.hedera.mirror.common.domain.token.Token in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method onNftTransferOwnershipAndDelete.

@Test
void onNftTransferOwnershipAndDelete() {
    // create token first
    EntityId tokenId1 = EntityId.of("0.0.1", TOKEN);
    EntityId accountId1 = EntityId.of("0.0.2", ACCOUNT);
    EntityId accountId2 = EntityId.of("0.0.3", ACCOUNT);
    EntityId treasury = EntityId.of("0.0.98", ACCOUNT);
    String metadata1 = "nft1";
    String metadata2 = "nft2";
    // save token entities first
    Token token1 = getToken(tokenId1, treasury, 1L, 1L);
    sqlEntityListener.onToken(token1);
    // create nfts
    // mint transfer combined
    Nft nft1Combined = getNft(tokenId1, 1L, accountId1, 3L, false, metadata1, 3L);
    // mint transfer combined
    Nft nft2Combined = getNft(tokenId1, 2L, accountId2, 4L, false, metadata2, 4L);
    sqlEntityListener.onNft(nft1Combined);
    sqlEntityListener.onNft(nft2Combined);
    completeFileAndCommit();
    assertEquals(2, nftRepository.count());
    // mint/burn
    Nft nft1Burn = getNft(tokenId1, 1L, EntityId.EMPTY, null, true, null, 5L);
    // mint/burn transfer
    Nft nft1BurnTransfer = getNft(tokenId1, 1L, null, null, null, null, 5L);
    sqlEntityListener.onNft(nft1Burn);
    sqlEntityListener.onNft(nft1BurnTransfer);
    // mint/burn
    Nft nft2Burn = getNft(tokenId1, 2L, EntityId.EMPTY, null, true, null, 6L);
    // mint/burn transfer
    Nft nft2BurnTransfer = getNft(tokenId1, 2L, null, null, null, null, 6L);
    sqlEntityListener.onNft(nft2Burn);
    sqlEntityListener.onNft(nft2BurnTransfer);
    completeFileAndCommit();
    // expected nfts
    // transfer
    Nft nft1 = getNft(tokenId1, 1L, null, 3L, true, metadata1, 5L);
    // transfer
    Nft nft2 = getNft(tokenId1, 2L, null, 4L, true, metadata2, 6L);
    assertThat(nftRepository.findAll()).containsExactlyInAnyOrder(nft1, nft2);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Token(com.hedera.mirror.common.domain.token.Token) ByteString(com.google.protobuf.ByteString) Nft(com.hedera.mirror.common.domain.token.Nft) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Token (com.hedera.mirror.common.domain.token.Token)33 Test (org.junit.jupiter.api.Test)20 EntityId (com.hedera.mirror.common.domain.entity.EntityId)18 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)9 ByteString (com.google.protobuf.ByteString)6 Nft (com.hedera.mirror.common.domain.token.Nft)6 TokenId (com.hedera.mirror.common.domain.token.TokenId)6 TokenTransfer (com.hedera.mirror.common.domain.token.TokenTransfer)3 SneakyThrows (lombok.SneakyThrows)3 TokenFreezeStatusEnum (com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum)2 TokenKycStatusEnum (com.hedera.mirror.common.domain.token.TokenKycStatusEnum)2 ArrayList (java.util.ArrayList)2 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)1 Contract (com.hedera.mirror.common.domain.contract.Contract)1 CryptoAllowance (com.hedera.mirror.common.domain.entity.CryptoAllowance)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1 EntityType (com.hedera.mirror.common.domain.entity.EntityType)1 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)1