Search in sources :

Example 1 with EntityId

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

the class SqlEntityListenerTest method makeTransaction.

private Transaction makeTransaction() {
    EntityId entityId = EntityId.of(10, 10, 10, ACCOUNT);
    Transaction transaction = new Transaction();
    transaction.setConsensusTimestamp(101L);
    transaction.setEntityId(entityId);
    transaction.setNodeAccountId(entityId);
    transaction.setMemo("memo".getBytes());
    transaction.setNonce(0);
    transaction.setType(14);
    transaction.setResult(22);
    transaction.setTransactionHash("transaction hash".getBytes());
    transaction.setTransactionBytes("transaction bytes".getBytes());
    transaction.setPayerAccountId(entityId);
    transaction.setValidStartNs(1L);
    transaction.setValidDurationSeconds(1L);
    transaction.setMaxFee(1L);
    transaction.setChargedTxFee(1L);
    transaction.setInitialBalance(0L);
    transaction.setScheduled(true);
    return transaction;
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Transaction(com.hedera.mirror.common.domain.transaction.Transaction)

Example 2 with EntityId

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

the class SqlEntityListenerTest method onSchedule.

@Test
void onSchedule() {
    EntityId entityId1 = EntityId.of("0.0.100", EntityType.SCHEDULE);
    EntityId entityId2 = EntityId.of("0.0.200", EntityType.SCHEDULE);
    Schedule schedule1 = domainBuilder.schedule().get();
    Schedule schedule2 = domainBuilder.schedule().get();
    // when
    sqlEntityListener.onSchedule(schedule1);
    sqlEntityListener.onSchedule(schedule2);
    completeFileAndCommit();
    // then
    assertThat(scheduleRepository.findAll()).containsExactlyInAnyOrder(schedule1, schedule2);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Schedule(com.hedera.mirror.common.domain.schedule.Schedule) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with EntityId

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

the class SqlEntityListenerTest method onEntityMerge.

@Test
void onEntityMerge() {
    // given
    Entity entity = getEntity(1, 1L, 1L, 0, "memo", keyFromString(KEY));
    sqlEntityListener.onEntity(entity);
    Entity entityAutoUpdated = getEntity(1, 5L);
    EntityId autoRenewAccountId = EntityId.of("0.0.10", ACCOUNT);
    entityAutoUpdated.setAutoRenewAccountId(autoRenewAccountId);
    entityAutoUpdated.setAutoRenewPeriod(360L);
    sqlEntityListener.onEntity(entityAutoUpdated);
    Entity entityExpirationUpdated = getEntity(1, 10L);
    entityExpirationUpdated.setExpirationTimestamp(720L);
    sqlEntityListener.onEntity(entityExpirationUpdated);
    Entity entitySubmitKeyUpdated = getEntity(1, 15L);
    entitySubmitKeyUpdated.setSubmitKey(keyFromString(KEY2).toByteArray());
    sqlEntityListener.onEntity(entitySubmitKeyUpdated);
    Entity entityMemoUpdated = getEntity(1, 20L);
    entityMemoUpdated.setMemo("memo-updated");
    sqlEntityListener.onEntity(entityMemoUpdated);
    Entity entityMaxAutomaticTokenAssociationsUpdated = getEntity(1, 25L);
    entityMaxAutomaticTokenAssociationsUpdated.setMaxAutomaticTokenAssociations(10);
    sqlEntityListener.onEntity(entityMaxAutomaticTokenAssociationsUpdated);
    Entity entityReceiverSigRequired = getEntity(1, 30L);
    entityReceiverSigRequired.setReceiverSigRequired(true);
    sqlEntityListener.onEntity(entityReceiverSigRequired);
    // when
    completeFileAndCommit();
    // then
    Entity expected = getEntity(1, 1L, 30L, "memo-updated", keyFromString(KEY), autoRenewAccountId, 360L, null, 720L, 10, true, keyFromString(KEY2));
    assertThat(entityRepository.findAll()).containsExactlyInAnyOrder(expected);
    assertThat(contractRepository.count()).isZero();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with EntityId

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

the class EntityRecordItemListenerTokenTest method assertNftTransferInRepository.

private void assertNftTransferInRepository(long consensusTimestamp, long serialNumber, TokenID tokenID, AccountID receiverId, AccountID senderId) {
    EntityId receiver = receiverId != null ? EntityId.of(receiverId) : null;
    EntityId sender = senderId != null ? EntityId.of(senderId) : null;
    var id = new NftTransferId(consensusTimestamp, serialNumber, EntityId.of(tokenID));
    assertThat(nftTransferRepository.findById(id)).get().returns(receiver, from(com.hedera.mirror.common.domain.token.NftTransfer::getReceiverAccountId)).returns(sender, from(com.hedera.mirror.common.domain.token.NftTransfer::getSenderAccountId));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId)

Example 5 with EntityId

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

the class EntityRecordItemListenerContractTest method assertCreatedContract.

private void assertCreatedContract(RecordItem recordItem) {
    var contractCreateResult = recordItem.getRecord().getContractCreateResult();
    byte[] evmAddress = contractCreateResult.hasEvmAddress() ? DomainUtils.toBytes(contractCreateResult.getEvmAddress().getValue()) : null;
    EntityId createdId = EntityId.of(recordItem.getRecord().getReceipt().getContractID());
    var contractAssert = assertThat(contractRepository.findById(createdId.getId())).get().returns(recordItem.getConsensusTimestamp(), Contract::getCreatedTimestamp).returns(false, Contract::getDeleted).returns(evmAddress, Contract::getEvmAddress).returns(createdId.getId(), Contract::getId).returns(recordItem.getConsensusTimestamp(), Contract::getTimestampLower).returns(createdId.getEntityNum(), Contract::getNum).returns(createdId.getShardNum(), Contract::getShard).returns(createdId.getType(), Contract::getType);
    var contractCreateInstance = recordItem.getTransactionBody().getContractCreateInstance();
    contractAssert.returns(contractCreateInstance.getDeclineReward(), Contract::isDeclineReward);
    if (contractCreateInstance.getStakedIdCase() == ContractCreateTransactionBody.StakedIdCase.STAKEDID_NOT_SET) {
        return;
    }
    contractAssert.returns(Utility.getEpochDay(recordItem.getConsensusTimestamp()), Contract::getStakePeriodStart);
    if (contractCreateInstance.hasStakedAccountId()) {
        long accountId = AccountIdConverter.INSTANCE.convertToDatabaseColumn(EntityId.of(contractCreateInstance.getStakedAccountId()));
        contractAssert.returns(accountId, Contract::getStakedAccountId).returns(-1L, Contract::getStakedNodeId);
    } else {
        contractAssert.returns(contractCreateInstance.getStakedNodeId(), Contract::getStakedNodeId).returns(-1L, Contract::getStakedAccountId);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Contract(com.hedera.mirror.common.domain.contract.Contract)

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