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));
}
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)));
}
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)));
}
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());
}
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());
}
Aggregations