Search in sources :

Example 6 with Token

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

the class SqlEntityListenerTest method onToken.

@Test
void onToken() {
    Token token1 = getToken(EntityId.of("0.0.3", TOKEN), EntityId.of("0.0.5", ACCOUNT), 1L, 1L);
    Token token2 = getToken(EntityId.of("0.0.7", TOKEN), EntityId.of("0.0.11", ACCOUNT), 2L, 2L);
    // when
    sqlEntityListener.onToken(token1);
    sqlEntityListener.onToken(token2);
    completeFileAndCommit();
    // then
    assertThat(tokenRepository.findAll()).containsExactlyInAnyOrder(token1, token2);
}
Also used : 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 7 with Token

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

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

the class TokenRepositoryTest method nullCharacter.

@Test
void nullCharacter() {
    Token token = token(1);
    token.setName("abc" + (char) 0);
    token.setSymbol("abc" + (char) 0);
    tokenRepository.save(token);
    assertThat(tokenRepository.findById(token.getTokenId())).get().isEqualTo(token);
}
Also used : Token(com.hedera.mirror.common.domain.token.Token) Test(org.junit.jupiter.api.Test)

Example 9 with Token

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

the class TokenRepositoryTest method save.

@Test
void save() {
    Token token = tokenRepository.save(token(1));
    assertThat(tokenRepository.findById(token.getTokenId())).get().isEqualTo(token);
}
Also used : Token(com.hedera.mirror.common.domain.token.Token) Test(org.junit.jupiter.api.Test)

Example 10 with Token

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

the class EntityRecordItemListener method insertTokenUnpause.

private void insertTokenUnpause(RecordItem recordItem) {
    if (entityProperties.getPersist().isTokens()) {
        long consensusTimestamp = recordItem.getConsensusTimestamp();
        TokenUnpauseTransactionBody transactionBody = recordItem.getTransactionBody().getTokenUnpause();
        Token token = Token.of(EntityId.of(transactionBody.getToken()));
        token.setPauseStatus(TokenPauseStatusEnum.UNPAUSED);
        updateToken(token, consensusTimestamp);
    }
}
Also used : TokenUnpauseTransactionBody(com.hederahashgraph.api.proto.java.TokenUnpauseTransactionBody) Token(com.hedera.mirror.common.domain.token.Token)

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