Search in sources :

Example 21 with Contract

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

the class EntityIdServiceImplTest method lookupContracts.

@Test
void lookupContracts() {
    ContractID nullContractId = null;
    ContractID contractId = ContractID.newBuilder().setContractNum(100).build();
    ContractID contractIdInvalid = ContractID.newBuilder().setRealmNum(1).build();
    Contract contractDeleted = domainBuilder.contract().customize(e -> e.deleted(true)).persist();
    EntityId entityId = entityIdService.lookup(nullContractId, ContractID.getDefaultInstance(), getProtoContractId(contractDeleted), contractIdInvalid, contractId);
    assertThat(entityId).isEqualTo(EntityId.of(contractId));
}
Also used : CsvSource(org.junit.jupiter.params.provider.CsvSource) DomainUtils(com.hedera.mirror.common.util.DomainUtils) Contract(com.hedera.mirror.common.domain.contract.Contract) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) Entity(com.hedera.mirror.common.domain.entity.Entity) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ContractID(com.hederahashgraph.api.proto.java.ContractID) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) Assertions(org.junit.jupiter.api.Assertions) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) AccountID(com.hederahashgraph.api.proto.java.AccountID) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractID(com.hederahashgraph.api.proto.java.ContractID) 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 22 with Contract

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

the class EntityIdServiceImplTest method cache.

@Test
void cache() {
    Contract contract = domainBuilder.contract().persist();
    ContractID contractId = getProtoContractId(contract);
    EntityId expected = contract.toEntityId();
    // db query and cache put
    assertThat(entityIdService.lookup(contractId)).isEqualTo(expected);
    // mark it as deleted
    contract.setDeleted(true);
    contractRepository.save(contract);
    // cache hit
    assertThat(entityIdService.lookup(contractId)).isEqualTo(expected);
    contractRepository.deleteById(contract.getId());
    assertThat(entityIdService.lookup(contractId)).isEqualTo(expected);
    // cache miss
    reset();
    assertThrows(AliasNotFoundException.class, () -> entityIdService.lookup(getProtoContractId(contract)));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractID(com.hederahashgraph.api.proto.java.ContractID) 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 23 with Contract

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

the class EntityIdServiceImplTest method lookupContractsAliasNotFoundActionError.

@Test
void lookupContractsAliasNotFoundActionError() {
    Contract contract1 = domainBuilder.contract().get();
    Contract contract2 = domainBuilder.contract().customize(c -> c.evmAddress(null)).get();
    assertThrows(AliasNotFoundException.class, () -> entityIdService.lookup(AliasNotFoundAction.ERROR, getProtoContractId(contract1), getProtoContractId(contract2)));
}
Also used : CsvSource(org.junit.jupiter.params.provider.CsvSource) DomainUtils(com.hedera.mirror.common.util.DomainUtils) Contract(com.hedera.mirror.common.domain.contract.Contract) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Resource(javax.annotation.Resource) Entity(com.hedera.mirror.common.domain.entity.Entity) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ContractID(com.hederahashgraph.api.proto.java.ContractID) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) Assertions(org.junit.jupiter.api.Assertions) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) AccountID(com.hederahashgraph.api.proto.java.AccountID) InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) 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 24 with Contract

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

the class BatchUpserterTest method contract.

@Test
void contract() {
    Contract contract1 = domainBuilder.contract().get();
    Contract contract2 = domainBuilder.contract().get();
    Contract contract3 = domainBuilder.contract().get();
    var contracts = List.of(contract1, contract2, contract3);
    persist(batchPersister, contracts);
    assertThat(contractRepository.findAll()).containsExactlyInAnyOrderElementsOf(contracts);
    String contract2Memo = contract2.getMemo();
    contract1.setCreatedTimestamp(null);
    contract1.setMemo("updated1");
    contract2.setCreatedTimestamp(null);
    contract2.setMemo(null);
    contract3.setCreatedTimestamp(null);
    contract3.setMemo("");
    persist(batchPersister, contracts);
    assertThat(contractRepository.findAll()).hasSize(3).extracting(Contract::getMemo).containsExactlyInAnyOrder(contract1.getMemo(), contract2Memo, contract3.getMemo());
    assertThat(findHistory(Contract.class)).hasSize(3).extracting(Contract::getId).containsExactlyInAnyOrder(contract1.getId(), contract2.getId(), contract3.getId());
}
Also used : ByteString(com.google.protobuf.ByteString) Contract(com.hedera.mirror.common.domain.contract.Contract) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 25 with Contract

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

the class HistoricalAccountInfoMigrationTest method existingEntitiesFromBeforeReset.

@Test
void existingEntitiesFromBeforeReset() throws Exception {
    Entity entity1 = createEntity(ACCOUNT_ID1, EntityType.ACCOUNT, false);
    Entity entity2 = createEntity(ACCOUNT_ID2, EntityType.ACCOUNT, false);
    Entity entity3 = createEntity(ACCOUNT_ID3, EntityType.ACCOUNT, false);
    Contract contract1 = createEntity(CONTRACT_ID1, EntityType.CONTRACT, false);
    historicalAccountInfoMigration.doMigrate();
    assertThat(contractRepository.findAll()).hasSize(CONTRACT_COUNT).allMatch(e -> e.getAutoRenewPeriod() > 0).allMatch(e -> e.getExpirationTimestamp() > 0).allMatch(e -> e.getKey().length > 0).map(Contract::getNum).containsExactly(contract1.getNum());
    assertThat(entityRepository.findAll()).hasSize(ENTITY_COUNT).allMatch(e -> e.getAutoRenewPeriod() > 0).allMatch(e -> e.getExpirationTimestamp() > 0).allMatch(e -> e.getKey().length > 0).map(Entity::getNum).containsExactlyInAnyOrder(entity1.getNum(), entity2.getNum(), entity3.getNum());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Contract(com.hedera.mirror.common.domain.contract.Contract) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Duration(com.hederahashgraph.api.proto.java.Duration) EntityType(com.hedera.mirror.common.domain.entity.EntityType) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) DomainUtils(com.hedera.mirror.common.util.DomainUtils) Assertions.from(org.assertj.core.api.Assertions.from) Range(com.google.common.collect.Range) Resource(javax.annotation.Resource) Instant(java.time.Instant) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) Key(com.hederahashgraph.api.proto.java.Key) AfterEach(org.junit.jupiter.api.AfterEach) MirrorProperties(com.hedera.mirror.importer.MirrorProperties) AccountInfo(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse.AccountInfo) EntityRepository(com.hedera.mirror.importer.repository.EntityRepository) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) Contract(com.hedera.mirror.common.domain.contract.Contract) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

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