Search in sources :

Example 76 with EntityId

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

the class ProtoBalanceFileReaderTest method getExpectedAccountBalanceFile.

private AccountBalanceFile getExpectedAccountBalanceFile(StreamFileData streamFileData) {
    Instant instant = Instant.parse(TIMESTAMP.replace("_", ":"));
    long consensusTimestamp = DomainUtils.convertToNanosMax(instant);
    long accountNum = 2000;
    long hbarBalance = 3000;
    long tokenNum = 5000;
    long tokenBalance = 6000;
    List<AccountBalance> accountBalances = IntStream.range(0, 10).mapToObj(i -> {
        EntityId accountId = EntityId.of(0, 0, accountNum + i, EntityType.ACCOUNT);
        List<TokenBalance> tokenBalances = IntStream.range(0, 5).mapToObj(j -> {
            EntityId tokenId = EntityId.of(0, 0, tokenNum + i * 5 + j, EntityType.TOKEN);
            return new TokenBalance(tokenBalance + i * 5 + j, new TokenBalance.Id(consensusTimestamp, accountId, tokenId));
        }).collect(Collectors.toList());
        return new AccountBalance(hbarBalance + i, tokenBalances, new AccountBalance.Id(consensusTimestamp, accountId));
    }).collect(Collectors.toList());
    return AccountBalanceFile.builder().bytes(streamFileData.getBytes()).consensusTimestamp(consensusTimestamp).fileHash("67c2fd054621366dd5a37b6ee36a51bc590361379d539fdac2265af08cb8097729218c7d9ff1f1e354c85b820c5b8cf8").items(Flux.fromIterable(accountBalances)).name(streamFileData.getFilename()).build();
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) EntityType(com.hedera.mirror.common.domain.entity.EntityType) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) TestUtils(com.hedera.mirror.importer.TestUtils) SingleAccountBalances(com.hedera.services.stream.proto.SingleAccountBalances) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) UnknownFieldSet(com.google.protobuf.UnknownFieldSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) DomainUtils(com.hedera.mirror.common.util.DomainUtils) Instant(java.time.Instant) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) Collectors(java.util.stream.Collectors) AllAccountBalances(com.hedera.services.stream.proto.AllAccountBalances) File(java.io.File) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) InvalidStreamFileException(com.hedera.mirror.importer.exception.InvalidStreamFileException) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Paths(java.nio.file.Paths) Assertions(org.junit.jupiter.api.Assertions) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) EntityId(com.hedera.mirror.common.domain.entity.EntityId) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) Instant(java.time.Instant) List(java.util.List) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) EntityId(com.hedera.mirror.common.domain.entity.EntityId)

Example 77 with EntityId

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

the class BalanceReconciliationServiceTest method tokenTransfer.

private void tokenTransfer(long accountNum, long tokenNum, long amount) {
    long timestamp = domainBuilder.timestamp();
    EntityId accountId = EntityId.of(accountNum, EntityType.ACCOUNT);
    EntityId tokenId = EntityId.of(tokenNum, EntityType.TOKEN);
    domainBuilder.tokenTransfer().customize(c -> c.amount(amount).id(new TokenTransfer.Id(timestamp, tokenId, accountId))).persist();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) BeforeEach(org.junit.jupiter.api.BeforeEach) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) EntityType(com.hedera.mirror.common.domain.entity.EntityType) SUCCESS(com.hedera.mirror.importer.reconciliation.BalanceReconciliationService.ReconciliationStatus.SUCCESS) FAILURE_TOKEN_TRANSFERS(com.hedera.mirror.importer.reconciliation.BalanceReconciliationService.ReconciliationStatus.FAILURE_TOKEN_TRANSFERS) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) METRIC(com.hedera.mirror.importer.reconciliation.BalanceReconciliationService.METRIC) FIFTY_BILLION_HBARS(com.hedera.mirror.importer.reconciliation.BalanceReconciliationService.FIFTY_BILLION_HBARS) Map(java.util.Map) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) TokenAccountId(com.hedera.mirror.importer.reconciliation.BalanceReconciliationService.TokenAccountId) Utility(com.hedera.mirror.importer.util.Utility) Gauge(io.micrometer.core.instrument.Gauge) FAILURE_CRYPTO_TRANSFERS(com.hedera.mirror.importer.reconciliation.BalanceReconciliationService.ReconciliationStatus.FAILURE_CRYPTO_TRANSFERS) Instant(java.time.Instant) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) FAILURE_FIFTY_BILLION(com.hedera.mirror.importer.reconciliation.BalanceReconciliationService.ReconciliationStatus.FAILURE_FIFTY_BILLION) ErrataType(com.hedera.mirror.common.domain.transaction.ErrataType) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer) TokenTransfer(com.hedera.mirror.common.domain.token.TokenTransfer)

Example 78 with EntityId

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

the class NftRepositoryTest method updateAccountId.

@Test
void updateAccountId() {
    Nft savedNft = nftRepository.save(nft("0.0.3", 2, 2));
    EntityId accountId = EntityId.of("0.0.10", EntityType.ACCOUNT);
    nftRepository.transferNftOwnership(savedNft.getId(), accountId, 3L);
    savedNft.setAccountId(accountId);
    savedNft.setModifiedTimestamp(3L);
    assertThat(nftRepository.findById(savedNft.getId())).contains(savedNft);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Nft(com.hedera.mirror.common.domain.token.Nft) Test(org.junit.jupiter.api.Test)

Example 79 with EntityId

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

the class NftRepositoryTest method updateTreasury.

@Test
void updateTreasury() {
    long consensusTimestamp = 6L;
    EntityId newAccountId = EntityId.of("0.0.2", EntityType.ACCOUNT);
    Nft nft1 = nft("0.0.100", 1, 1);
    Nft nft2 = nft("0.0.100", 2, 2);
    Nft nft3 = nft("0.0.100", 3, 3);
    // Not updated since wrong token
    Nft nft4 = nft("0.0.101", 1, 4);
    // Not updated since wrong account
    Nft nft5 = nft("0.0.100", 4, 5);
    nft5.setAccountId(newAccountId);
    nftRepository.saveAll(List.of(nft1, nft2, nft3, nft4, nft5));
    EntityId tokenId = nft1.getId().getTokenId();
    EntityId previousAccountId = nft1.getAccountId();
    nftRepository.updateTreasury(tokenId.getId(), previousAccountId.getId(), newAccountId.getId(), consensusTimestamp, EntityId.of("0.0.200", EntityType.ACCOUNT).getId(), false);
    assertAccountUpdated(nft1, newAccountId);
    assertAccountUpdated(nft2, newAccountId);
    assertAccountUpdated(nft3, newAccountId);
    assertThat(nftRepository.findById(nft4.getId())).get().isEqualTo(nft4);
    assertThat(nftRepository.findById(nft5.getId())).get().isEqualTo(nft5);
    IterableAssert<NftTransfer> nftTransfers = assertThat(nftTransferRepository.findAll()).hasSize(3);
    nftTransfers.extracting(NftTransfer::getReceiverAccountId).containsOnly(newAccountId);
    nftTransfers.extracting(NftTransfer::getSenderAccountId).containsOnly(previousAccountId);
    nftTransfers.extracting(n -> n.getId().getTokenId()).containsOnly(tokenId);
    nftTransfers.extracting(n -> n.getId().getConsensusTimestamp()).containsOnly(consensusTimestamp);
    nftTransfers.extracting(n -> n.getId().getSerialNumber()).containsExactlyInAnyOrder(1L, 2L, 3L);
    nftTransfers.extracting(NftTransfer::getIsApproval).containsExactlyInAnyOrder(false, false, false);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Test(org.junit.jupiter.api.Test) NftId(com.hedera.mirror.common.domain.token.NftId) IterableAssert(org.assertj.core.api.IterableAssert) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) Resource(javax.annotation.Resource) AbstractObjectAssert(org.assertj.core.api.AbstractObjectAssert) EntityType(com.hedera.mirror.common.domain.entity.EntityType) NftTransfer(com.hedera.mirror.common.domain.token.NftTransfer) Nft(com.hedera.mirror.common.domain.token.Nft) Test(org.junit.jupiter.api.Test)

Example 80 with EntityId

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

the class TokenUpdateTransactionHandlerTest method updateTransactionSuccessful.

@Test
void updateTransactionSuccessful() {
    RecordItem recordItem = recordItemBuilder.tokenUpdate().build();
    var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
    var timestamp = recordItem.getConsensusTimestamp();
    var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
    when(entityIdService.lookup(any(AccountID.class))).thenReturn(EntityIdEndec.decode(10, EntityType.ACCOUNT));
    transactionHandler.updateTransaction(transaction, recordItem);
    assertTokenUpdate(timestamp, tokenId, id -> assertEquals(10L, id));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) Duration(com.hederahashgraph.api.proto.java.Duration) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) NftRepository(com.hedera.mirror.importer.repository.NftRepository) DomainUtils(com.hedera.mirror.common.util.DomainUtils) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Mockito.when(org.mockito.Mockito.when) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Mockito.verify(org.mockito.Mockito.verify) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) Assertions(org.junit.jupiter.api.Assertions) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AccountID(com.hederahashgraph.api.proto.java.AccountID) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) 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