Search in sources :

Example 31 with Token

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

the class SqlEntityListenerTest method onTokenAccount.

@Test
void onTokenAccount() {
    EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
    EntityId tokenId2 = EntityId.of("0.0.5", TOKEN);
    // save token entities first
    Token token1 = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
    Token token2 = getToken(tokenId2, EntityId.of("0.0.110", ACCOUNT), 2L, 2L);
    sqlEntityListener.onToken(token1);
    sqlEntityListener.onToken(token2);
    completeFileAndCommit();
    EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
    EntityId accountId2 = EntityId.of("0.0.11", ACCOUNT);
    TokenAccount tokenAccount1 = getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, TokenFreezeStatusEnum.NOT_APPLICABLE, TokenKycStatusEnum.NOT_APPLICABLE);
    TokenAccount tokenAccount2 = getTokenAccount(tokenId2, accountId2, 6L, 6L, true, false, TokenFreezeStatusEnum.NOT_APPLICABLE, TokenKycStatusEnum.NOT_APPLICABLE);
    // when
    sqlEntityListener.onTokenAccount(tokenAccount1);
    sqlEntityListener.onTokenAccount(tokenAccount1);
    sqlEntityListener.onTokenAccount(tokenAccount2);
    completeFileAndCommit();
    // then
    assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrder(tokenAccount1, tokenAccount2);
}
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 32 with Token

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

the class SqlEntityListenerTest method onTokenMergeNegativeTotalSupply.

@Test
void onTokenMergeNegativeTotalSupply() {
    // given
    EntityId tokenId = EntityId.of("0.0.3", TOKEN);
    EntityId accountId = EntityId.of("0.0.500", ACCOUNT);
    // when
    // create token
    Token token = getToken(tokenId, accountId, 1L, 1L);
    sqlEntityListener.onToken(token);
    // token dissociate of the deleted token
    Token update = getTokenUpdate(tokenId, 5);
    update.setTotalSupply(-10L);
    sqlEntityListener.onToken(update);
    completeFileAndCommit();
    // then
    Token expected = getToken(tokenId, accountId, 1L, 5L);
    expected.setTotalSupply(expected.getTotalSupply() - 10);
    assertThat(tokenRepository.findAll()).containsExactlyInAnyOrder(expected);
}
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 33 with Token

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

the class SqlEntityListenerTest method onNftMintOutOfOrder.

@Test
void onNftMintOutOfOrder() {
    // create token first
    EntityId tokenId1 = EntityId.of("0.0.1", TOKEN);
    EntityId tokenId2 = EntityId.of("0.0.3", TOKEN);
    EntityId accountId1 = EntityId.of("0.0.2", ACCOUNT);
    EntityId accountId2 = EntityId.of("0.0.4", ACCOUNT);
    EntityId treasuryId = EntityId.of("0.0.98", ACCOUNT);
    String metadata1 = "nft1";
    String metadata2 = "nft2";
    // save token entities first
    Token token1 = getToken(tokenId1, treasuryId, 1L, 1L);
    Token token2 = getToken(tokenId2, treasuryId, 2L, 2L);
    sqlEntityListener.onToken(token1);
    sqlEntityListener.onToken(token2);
    // create nft 1 w transfer coming first
    // transfer
    sqlEntityListener.onNft(getNft(tokenId1, 1L, accountId1, null, null, null, 3L));
    // mint
    sqlEntityListener.onNft(getNft(tokenId1, 1L, null, 3L, false, metadata1, 3L));
    // create nft 2 w transfer coming first
    // transfer
    sqlEntityListener.onNft(getNft(tokenId2, 1L, accountId2, null, null, null, 4L));
    // mint
    sqlEntityListener.onNft(getNft(tokenId2, 1L, null, 4L, false, metadata2, 4L));
    completeFileAndCommit();
    // transfer
    Nft nft1 = getNft(tokenId1, 1L, accountId1, 3L, false, metadata1, 3L);
    // transfer
    Nft nft2 = getNft(tokenId2, 1L, accountId2, 4L, false, metadata2, 4L);
    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