Search in sources :

Example 31 with Contract

use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.

the class EntityIdServiceImplTest method lookupContractCreate2EvmAddressNoMatch.

@Test
void lookupContractCreate2EvmAddressNoMatch() {
    Contract contract = domainBuilder.contract().get();
    assertThrows(AliasNotFoundException.class, () -> entityIdService.lookup(getProtoContractId(contract)));
}
Also used : Contract(com.hedera.mirror.common.domain.contract.Contract) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with Contract

use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.

the class ContractRepositoryTest method findByEvmAddress.

@Test
void findByEvmAddress() {
    Contract contract = domainBuilder.contract().persist();
    assertThat(contractRepository.findByEvmAddress(contract.getEvmAddress())).get().isEqualTo(contract.getId());
}
Also used : Contract(com.hedera.mirror.common.domain.contract.Contract) Test(org.junit.jupiter.api.Test)

Example 33 with Contract

use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.

the class ContractRepositoryTest method save.

@Test
void save() {
    Contract contract = domainBuilder.contract().persist();
    assertThat(contractRepository.findById(contract.getId())).get().isEqualTo(contract);
}
Also used : Contract(com.hedera.mirror.common.domain.contract.Contract) Test(org.junit.jupiter.api.Test)

Example 34 with Contract

use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method contractDeleteToExisting.

@ParameterizedTest
@EnumSource(ContractIdType.class)
void contractDeleteToExisting(ContractIdType contractIdType) {
    SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true);
    Transaction transaction = contractDeleteTransaction(setupResult.protoContractId);
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.DELETE);
    RecordItem recordItem = new RecordItem(transaction, record);
    parseRecordItemAndCommit(recordItem);
    Contract dbContractEntity = getTransactionEntity(record.getConsensusTimestamp());
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(setupResult.contract.toEntityId()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertThat(dbContractEntity).isNotNull().returns(true, Contract::getDeleted).returns(recordItem.getConsensusTimestamp(), Contract::getTimestampLower).returns(EntityId.of(PAYER), Contract::getObtainerId).usingRecursiveComparison().ignoringFields("deleted", "obtainerId", "timestampRange").isEqualTo(setupResult.contract));
}
Also used : ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) ContractDeleteTransactionBody(com.hederahashgraph.api.proto.java.ContractDeleteTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) Contract(com.hedera.mirror.common.domain.contract.Contract) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with Contract

use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method assertContractEntity.

private void assertContractEntity(RecordItem recordItem) {
    long createdTimestamp = recordItem.getConsensusTimestamp();
    var transactionBody = recordItem.getTransactionBody().getContractCreateInstance();
    var adminKey = transactionBody.getAdminKey().toByteArray();
    var transaction = transactionRepository.findById(createdTimestamp).get();
    var contractCreateResult = recordItem.getRecord().getContractCreateResult();
    byte[] evmAddress = contractCreateResult.hasEvmAddress() ? DomainUtils.toBytes(contractCreateResult.getEvmAddress().getValue()) : null;
    EntityId entityId = transaction.getEntityId();
    Contract contract = getEntity(entityId);
    Long expectedAutoRenewAccountId = transactionBody.hasAutoRenewAccountId() ? transactionBody.getAutoRenewAccountId().getAccountNum() : null;
    EntityId expectedFileId = transactionBody.hasFileID() ? EntityId.of(transactionBody.getFileID()) : null;
    byte[] expectedInitcode = transactionBody.getInitcode() != ByteString.EMPTY ? DomainUtils.toBytes(transactionBody.getInitcode()) : null;
    assertThat(transaction).isNotNull().returns(transactionBody.getInitialBalance(), t -> t.getInitialBalance());
    assertThat(contract).isNotNull().returns(expectedAutoRenewAccountId, Contract::getAutoRenewAccountId).returns(transactionBody.getAutoRenewPeriod().getSeconds(), Contract::getAutoRenewPeriod).returns(createdTimestamp, Contract::getCreatedTimestamp).returns(false, Contract::getDeleted).returns(evmAddress, Contract::getEvmAddress).returns(null, Contract::getExpirationTimestamp).returns(expectedFileId, Contract::getFileId).returns(entityId.getId(), Contract::getId).returns(expectedInitcode, Contract::getInitcode).returns(adminKey, Contract::getKey).returns(transactionBody.getMaxAutomaticTokenAssociations(), Contract::getMaxAutomaticTokenAssociations).returns(transactionBody.getMemo(), Contract::getMemo).returns(createdTimestamp, Contract::getTimestampLower).returns(null, Contract::getObtainerId).returns(EntityId.of(transactionBody.getProxyAccountID()), Contract::getProxyAccountId).returns(DomainUtils.getPublicKey(adminKey), Contract::getPublicKey).returns(EntityType.CONTRACT, Contract::getType);
    if (entityProperties.getPersist().isContracts()) {
        assertCreatedContract(recordItem);
    }
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Contract(com.hedera.mirror.common.domain.contract.Contract)

Aggregations

Contract (com.hedera.mirror.common.domain.contract.Contract)49 Test (org.junit.jupiter.api.Test)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 EntityId (com.hedera.mirror.common.domain.entity.EntityId)21 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)18 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)18 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)17 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)16 Assertions (org.junit.jupiter.api.Assertions)16 DomainUtils (com.hedera.mirror.common.util.DomainUtils)15 AccountID (com.hederahashgraph.api.proto.java.AccountID)15 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)13 ContractID (com.hederahashgraph.api.proto.java.ContractID)13 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)13 Entity (com.hedera.mirror.common.domain.entity.Entity)12 AliasNotFoundException (com.hedera.mirror.importer.exception.AliasNotFoundException)12 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)12 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12