Search in sources :

Example 11 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId 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 12 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId 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 13 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId 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)

Example 14 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method onNonFeeTransfer.

@Test
void onNonFeeTransfer() {
    // given
    NonFeeTransfer nonFeeTransfer1 = domainBuilder.nonFeeTransfer().customize(n -> n.amount(1L).consensusTimestamp(1L).entityId(EntityId.of(1L, ACCOUNT)).payerAccountId(TRANSACTION_PAYER)).get();
    NonFeeTransfer nonFeeTransfer2 = domainBuilder.nonFeeTransfer().customize(n -> n.amount(2L).consensusTimestamp(2L).entityId(EntityId.of(2L, ACCOUNT)).payerAccountId(TRANSACTION_PAYER)).get();
    // when
    sqlEntityListener.onNonFeeTransfer(nonFeeTransfer1);
    sqlEntityListener.onNonFeeTransfer(nonFeeTransfer2);
    completeFileAndCommit();
    // then
    assertThat(findNonFeeTransfers()).containsExactlyInAnyOrder(nonFeeTransfer1, nonFeeTransfer2);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SCHEDULE(com.hedera.mirror.common.domain.entity.EntityType.SCHEDULE) CryptoAllowanceRepository(com.hedera.mirror.importer.repository.CryptoAllowanceRepository) SneakyThrows(lombok.SneakyThrows) EntityId(com.hedera.mirror.common.domain.entity.EntityId) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) ContractResultRepository(com.hedera.mirror.importer.repository.ContractResultRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) NodeStakeRepository(com.hedera.mirror.importer.repository.NodeStakeRepository) ScheduleRepository(com.hedera.mirror.importer.repository.ScheduleRepository) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TOKEN(com.hedera.mirror.common.domain.entity.EntityType.TOKEN) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) TokenSupplyTypeEnum(com.hedera.mirror.common.domain.token.TokenSupplyTypeEnum) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) NftAllowanceRepository(com.hedera.mirror.importer.repository.NftAllowanceRepository) Token(com.hedera.mirror.common.domain.token.Token) TokenId(com.hedera.mirror.common.domain.token.TokenId) TestUtils(com.hedera.mirror.importer.TestUtils) TransactionSignatureRepository(com.hedera.mirror.importer.repository.TransactionSignatureRepository) FileDataRepository(com.hedera.mirror.importer.repository.FileDataRepository) MethodSource(org.junit.jupiter.params.provider.MethodSource) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) TokenRepository(com.hedera.mirror.importer.repository.TokenRepository) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) TokenFreezeStatusEnum(com.hedera.mirror.common.domain.token.TokenFreezeStatusEnum) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) CryptoAllowance(com.hedera.mirror.common.domain.entity.CryptoAllowance) TokenPauseStatusEnum(com.hedera.mirror.common.domain.token.TokenPauseStatusEnum) StakingRewardTransferRepository(com.hedera.mirror.importer.repository.StakingRewardTransferRepository) Arguments(org.junit.jupiter.params.provider.Arguments) StandardCharsets(java.nio.charset.StandardCharsets) NftAllowance(com.hedera.mirror.common.domain.entity.NftAllowance) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) Stream(java.util.stream.Stream) EntityRepository(com.hedera.mirror.importer.repository.EntityRepository) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) CryptoTransferRepository(com.hedera.mirror.importer.repository.CryptoTransferRepository) TokenAccountRepository(com.hedera.mirror.importer.repository.TokenAccountRepository) EthereumTransactionRepository(com.hedera.mirror.importer.repository.EthereumTransactionRepository) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) Schedule(com.hedera.mirror.common.domain.schedule.Schedule) TokenTypeEnum(com.hedera.mirror.common.domain.token.TokenTypeEnum) NftId(com.hedera.mirror.common.domain.token.NftId) Contract(com.hedera.mirror.common.domain.contract.Contract) TransactionRepository(com.hedera.mirror.importer.repository.TransactionRepository) Hex(org.apache.commons.codec.binary.Hex) ArrayList(java.util.ArrayList) LiveHashRepository(com.hedera.mirror.importer.repository.LiveHashRepository) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) TransactionSignature(com.hedera.mirror.common.domain.transaction.TransactionSignature) NftTransferRepository(com.hedera.mirror.importer.repository.NftTransferRepository) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) LiveHash(com.hedera.mirror.common.domain.transaction.LiveHash) ValueSource(org.junit.jupiter.params.provider.ValueSource) NftRepository(com.hedera.mirror.importer.repository.NftRepository) TokenAllowanceRepository(com.hedera.mirror.importer.repository.TokenAllowanceRepository) TopicMessageRepository(com.hedera.mirror.importer.repository.TopicMessageRepository) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) TokenTransferRepository(com.hedera.mirror.importer.repository.TokenTransferRepository) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) Key(com.hederahashgraph.api.proto.java.Key) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecordFileRepository(com.hedera.mirror.importer.repository.RecordFileRepository) TokenKycStatusEnum(com.hedera.mirror.common.domain.token.TokenKycStatusEnum) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Assertions(org.junit.jupiter.api.Assertions) TokenAllowance(com.hedera.mirror.common.domain.entity.TokenAllowance) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with EntityId

use of com.hedera.mirror.common.domain.entity.EntityId 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)

Aggregations

EntityId (com.hedera.mirror.common.domain.entity.EntityId)134 Test (org.junit.jupiter.api.Test)64 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)33 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)22 EntityType (com.hedera.mirror.common.domain.entity.EntityType)21 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)21 Token (com.hedera.mirror.common.domain.token.Token)20 Entity (com.hedera.mirror.common.domain.entity.Entity)17 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)17 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)16 Assertions (org.junit.jupiter.api.Assertions)16 Contract (com.hedera.mirror.common.domain.contract.Contract)15 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)15 DomainUtils (com.hedera.mirror.common.util.DomainUtils)15 ByteString (com.google.protobuf.ByteString)14 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)14 AccountID (com.hederahashgraph.api.proto.java.AccountID)14 ContractID (com.hederahashgraph.api.proto.java.ContractID)14 Consumer (java.util.function.Consumer)13