use of com.hedera.mirror.common.domain.entity.AbstractEntity in project hedera-mirror-node by hashgraph.
the class AbstractTransactionHandlerTest method getUpdateEntityTestSpecsForCreateTransaction.
protected List<UpdateEntityTestSpec> getUpdateEntityTestSpecsForCreateTransaction(FieldDescriptor memoField) {
TransactionBody body = getTransactionBodyForUpdateEntityWithoutMemo();
Message innerBody = getInnerBody(body);
List<UpdateEntityTestSpec> testSpecs = new LinkedList<>();
AbstractEntity expected = getExpectedUpdatedEntity();
// Proto defaults to empty string
expected.setMemo("");
// no memo set, expect empty memo
testSpecs.add(UpdateEntityTestSpec.builder().description("create entity without memo, expect empty memo").expected(expected).recordItem(getRecordItem(body, innerBody)).build());
expected = getExpectedUpdatedEntity();
expected.setMemo("");
// memo set to empty string, expect empty memo
Message updatedInnerBody = innerBody.toBuilder().setField(memoField, "").build();
testSpecs.add(UpdateEntityTestSpec.builder().description("create entity with empty memo, expect empty memo").expected(expected).recordItem(getRecordItem(body, updatedInnerBody)).build());
// memo set to non-empty string, expect memo set
expected = getExpectedUpdatedEntity();
expected.setMemo(DEFAULT_MEMO);
updatedInnerBody = innerBody.toBuilder().setField(memoField, DEFAULT_MEMO).build();
testSpecs.add(UpdateEntityTestSpec.builder().description("create entity with non-empty memo, expect memo set").expected(expected).recordItem(getRecordItem(body, updatedInnerBody)).build());
return testSpecs;
}
use of com.hedera.mirror.common.domain.entity.AbstractEntity in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method updateTreasury.
@Test
void updateTreasury() {
AbstractEntity entity = getExpectedUpdatedEntity();
AccountID previousAccountId = AccountID.newBuilder().setAccountNum(1L).build();
AccountID newAccountId = AccountID.newBuilder().setAccountNum(2L).build();
TokenID tokenID = TokenID.newBuilder().setTokenNum(3L).build();
long consensusTimestamp = DomainUtils.timestampInNanosMax(MODIFIED_TIMESTAMP);
TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(tokenID).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(newAccountId).setSenderAccountID(previousAccountId).setSerialNumber(NftTransferId.WILDCARD_SERIAL_NUMBER).build()).build();
TransactionRecord record = getDefaultTransactionRecord().addTokenTransferLists(tokenTransferList).build();
RecordItem recordItem = getRecordItem(getDefaultTransactionBody().build(), record);
when(entityIdService.lookup(AccountID.newBuilder().setAccountNum(DEFAULT_AUTO_RENEW_ACCOUNT_NUM).build())).thenReturn(EntityIdEndec.decode(DEFAULT_AUTO_RENEW_ACCOUNT_NUM, EntityType.ACCOUNT));
Transaction transaction = new Transaction();
transaction.setEntityId(entity.toEntityId());
transactionHandler.updateTransaction(transaction, recordItem);
TransactionBody body = recordItem.getTransactionBody();
var payerAccount = EntityId.of(body.getTransactionID().getAccountID()).toEntity().getId();
verify(nftRepository).updateTreasury(tokenID.getTokenNum(), previousAccountId.getAccountNum(), newAccountId.getAccountNum(), consensusTimestamp, payerAccount, false);
}
use of com.hedera.mirror.common.domain.entity.AbstractEntity in project hedera-mirror-node by hashgraph.
the class HistoricalAccountInfoMigration method process.
boolean process(AccountInfo accountInfo) {
EntityType entityType = EntityType.ACCOUNT;
long id = EntityId.of(accountInfo.getAccountID()).getId();
if (contractIds.contains(id)) {
entityType = EntityType.CONTRACT;
}
EntityId entityId = EntityIdEndec.decode(id, entityType);
CrudRepository<AbstractEntity, Long> repository = getRepository(entityType);
Optional<AbstractEntity> currentEntity = repository.findById(entityId.getId());
boolean exists = currentEntity.isPresent();
AbstractEntity entity = currentEntity.orElseGet(entityId::toEntity);
boolean updated = !exists;
// All contract accounts don't have to have a key, but luckily in our file they do.
if (exists && ArrayUtils.isNotEmpty(entity.getKey())) {
log.trace("Skipping entity {} that was created after the reset", entityId::entityIdToString);
return false;
}
if (entity.getAutoRenewPeriod() == null && accountInfo.hasAutoRenewPeriod()) {
entity.setAutoRenewPeriod(accountInfo.getAutoRenewPeriod().getSeconds());
updated = true;
}
// Accounts can't be undeleted
if (entity.getDeleted() == null || (entity.getDeleted() != accountInfo.getDeleted() && accountInfo.getDeleted())) {
entity.setDeleted(accountInfo.getDeleted());
updated = true;
}
if (entity.getExpirationTimestamp() == null && accountInfo.hasExpirationTime()) {
entity.setExpirationTimestamp(DomainUtils.timestampInNanosMax(accountInfo.getExpirationTime()));
updated = true;
}
if (entity.getKey() == null && accountInfo.hasKey()) {
entity.setKey(accountInfo.getKey().toByteArray());
updated = true;
}
if (StringUtils.isEmpty(entity.getMemo())) {
entity.setMemo(accountInfo.getMemo());
updated = true;
}
if (entity.getProxyAccountId() == null && accountInfo.hasProxyAccountID()) {
EntityId proxyAccountEntityId = EntityId.of(accountInfo.getProxyAccountID());
// Proxy account should get created separately
entity.setProxyAccountId(proxyAccountEntityId);
updated |= proxyAccountEntityId != null;
}
if (updated) {
log.info("Saving {} entity: {}", exists ? "existing" : "new", entity);
repository.save(entity);
}
return updated;
}
use of com.hedera.mirror.common.domain.entity.AbstractEntity in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTopicTest method createTopicTestExistingAutoRenewAccount.
// https://github.com/hashgraph/hedera-mirror-node/issues/501
@Test
void createTopicTestExistingAutoRenewAccount() {
Long autoRenewAccountId = 100L;
var consensusTimestamp = 2_000_000L;
var responseCode = SUCCESS;
var transaction = createCreateTopicTransaction(null, null, "", autoRenewAccountId, null);
var transactionRecord = createTransactionRecord(TOPIC_ID, null, null, 1, consensusTimestamp, responseCode);
parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));
var entity = getTopicEntity(TOPIC_ID);
assertTransactionInRepository(responseCode, consensusTimestamp, entity.getId());
assertEquals(1L, entityRepository.count());
assertThat(entity).returns("".getBytes(), from(Entity::getKey)).returns("".getBytes(), from(Entity::getSubmitKey)).returns("", from(Entity::getMemo)).returns(false, from(Entity::getDeleted)).returns(EntityType.TOPIC, from(Entity::getType)).returns(autoRenewAccountId, AbstractEntity::getAutoRenewAccountId);
}
use of com.hedera.mirror.common.domain.entity.AbstractEntity in project hedera-mirror-node by hashgraph.
the class AbstractDeleteOrUndeleteTransactionHandlerTest method getUpdateEntityTestSpecs.
@Override
protected List<UpdateEntityTestSpec> getUpdateEntityTestSpecs() {
String description = deleteOrUndelete ? "delete entity transaction, expect entity deleted" : "undelete entity transaction, expect entity undeleted";
AbstractEntity expected = getExpectedEntityWithTimestamp();
expected.setDeleted(deleteOrUndelete);
return List.of(UpdateEntityTestSpec.builder().description(description).expected(expected).recordItem(getRecordItem(getDefaultTransactionBody().build(), getDefaultTransactionRecord().build())).build());
}
Aggregations