use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTokenTest method tokenCreate.
void tokenCreate(List<CustomFee> customFees, boolean freezeDefault, boolean freezeKey, boolean kycKey, boolean pauseKey, List<TokenAccount> expectedTokenAccounts, List<EntityId> autoAssociatedAccounts) {
// given
Entity expected = createEntity(DOMAIN_TOKEN_ID, TOKEN_REF_KEY, PAYER.getAccountNum(), AUTO_RENEW_PERIOD, false, EXPIRY_NS, TOKEN_CREATE_MEMO, null, CREATE_TIMESTAMP, CREATE_TIMESTAMP);
// when
createTokenEntity(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, freezeDefault, freezeKey, kycKey, pauseKey, customFees, autoAssociatedAccounts);
// then
assertEquals(1L, entityRepository.count());
assertEntity(expected);
// verify token
TokenPauseStatusEnum pauseStatus = pauseKey ? TokenPauseStatusEnum.UNPAUSED : TokenPauseStatusEnum.NOT_APPLICABLE;
assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, CREATE_TIMESTAMP, SYMBOL, INITIAL_SUPPLY, pauseStatus);
assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrderElementsOf(expectedTokenAccounts);
assertTokenTransferInRepository(TOKEN_ID, PAYER, CREATE_TIMESTAMP, INITIAL_SUPPLY);
assertCustomFeesInDb(customFees);
assertThat(tokenTransferRepository.count()).isEqualTo(1L);
}
use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTopicTest method createTopicEntity.
private Entity createTopicEntity(TopicID topicId, Long expirationTimeSeconds, Integer expirationTimeNanos, Key adminKey, Key submitKey, String memo, Long autoRenewAccountNum, Long autoRenewPeriod) {
Entity topic = EntityId.of(topicId).toEntity();
if (autoRenewAccountNum != null) {
topic.setAutoRenewAccountId(autoRenewAccountNum);
}
if (autoRenewPeriod != null) {
topic.setAutoRenewPeriod(autoRenewPeriod);
}
if (expirationTimeSeconds != null && expirationTimeNanos != null) {
topic.setExpirationTimestamp(DomainUtils.convertToNanosMax(expirationTimeSeconds, expirationTimeNanos));
}
if (null != adminKey) {
topic.setKey(adminKey.toByteArray());
}
if (null != submitKey) {
topic.setSubmitKey(submitKey.toByteArray());
}
topic.setEthereumNonce(0L);
topic.setMemo(memo);
topic.setType(EntityType.TOPIC);
topic.setStakedAccountId(-1L);
topic.setStakedNodeId(-1L);
topic.setStakePeriodStart(-1L);
return topic;
}
use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.
the class CryptoCreateTransactionHandlerTest method updateTransactionStakedAccountId.
@Test
void updateTransactionStakedAccountId() {
// given
final AccountID accountId = AccountID.newBuilder().setAccountNum(1L).build();
var recordItem = recordItemBuilder.cryptoCreate().transactionBody(b -> b.setDeclineReward(false).setStakedAccountId(accountId)).build();
// when
transactionHandler.updateTransaction(transaction(recordItem), recordItem);
// then
verify(entityListener).onEntity(entities.capture());
assertThat(entities.getValue()).isNotNull().returns(false, Entity::isDeclineReward).returns(accountId.getAccountNum(), Entity::getStakedAccountId).returns(Utility.getEpochDay(recordItem.getConsensusTimestamp()), Entity::getStakePeriodStart);
}
use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.
the class AbstractTransactionHandlerTest method getUpdateEntityTestSpecsForUpdateTransaction.
private List<UpdateEntityTestSpec> getUpdateEntityTestSpecsForUpdateTransaction(FieldDescriptor memoField, FieldDescriptor memoWrapperField, FieldDescriptor maxAutomaticTokenAssociationsField, FieldDescriptor receiverSigRequiredWrapperField) {
TransactionBody body = getTransactionBodyForUpdateEntityWithoutMemo();
Message innerBody = getInnerBody(body);
List<UpdateEntityTestSpec> testSpecs = new LinkedList<>();
if (receiverSigRequiredWrapperField != null) {
innerBody = innerBody.toBuilder().setField(receiverSigRequiredWrapperField, UPDATED_RECEIVER_SIG_REQUIRED).build();
}
AbstractEntity expected = getExpectedUpdatedEntity();
Message unchangedMemoInnerBody = innerBody;
if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
}
testSpecs.add(UpdateEntityTestSpec.builder().description("update entity without memo").expected(expected).recordItem(getRecordItem(body, unchangedMemoInnerBody)).build());
Message updatedMemoInnerBody = innerBody;
if (memoWrapperField != null) {
// memo is of string type
// non-empty string, expect memo set to non-empty string
expected = getExpectedUpdatedEntity();
expected.setMemo(UPDATED_MEMO);
updatedMemoInnerBody = innerBody.toBuilder().setField(memoField, UPDATED_MEMO).build();
}
if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
}
testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with non-empty String").expected(expected).recordItem(getRecordItem(body, updatedMemoInnerBody)).build());
// memo is set through the StringValue field
// there is always a StringValue field, either "memo" or "memoWrapper"
FieldDescriptor field = memoWrapperField;
if (field == null) {
field = memoField;
}
expected = getExpectedUpdatedEntity();
expected.setMemo("");
Message clearedMemoInnerBody = innerBody.toBuilder().setField(field, StringValue.of("")).build();
if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
}
testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with empty StringValue memo, expect memo cleared").expected(expected).recordItem(getRecordItem(body, clearedMemoInnerBody)).build());
// non-empty StringValue, expect memo in entity updated
expected = getExpectedUpdatedEntity();
expected.setMemo(UPDATED_MEMO);
Message memoStringValueUpdatedInnerBody = innerBody.toBuilder().setField(field, StringValue.of(UPDATED_MEMO)).build();
if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
}
testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with non-empty StringValue memo, expect memo updated").expected(expected).recordItem(getRecordItem(body, memoStringValueUpdatedInnerBody)).build());
if (maxAutomaticTokenAssociationsField != null) {
expected = getExpectedUpdatedEntity();
expected.setMaxAutomaticTokenAssociations(500);
if (expected instanceof Entity) {
((Entity) expected).setReceiverSigRequired(true);
}
Message updatedInnerBody = innerBody.toBuilder().setField(maxAutomaticTokenAssociationsField, Int32Value.of(500)).build();
testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with max_automatic_token_associations").expected(expected).recordItem(getRecordItem(body, updatedInnerBody)).build());
}
return testSpecs;
}
use of com.hedera.mirror.common.domain.entity.Entity in project hedera-mirror-node by hashgraph.
the class CryptoUpdateTransactionHandlerTest method updateTransactionStakedNodeId.
@Test
void updateTransactionStakedNodeId() {
RecordItem withStakedNodeIdSet = recordItemBuilder.cryptoUpdate().transactionBody(body -> body.setStakedNodeId(1L)).build();
setupForCrytoUpdateTransactionTest(withStakedNodeIdSet, t -> assertThat(t).returns(1L, Entity::getStakedNodeId).returns(-1L, Entity::getStakedAccountId).returns(true, Entity::isDeclineReward).extracting(Entity::getStakePeriodStart).isNotNull());
}
Aggregations