use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method updateTransactionWithAliasNotFoundAndPartialDataActionSkip.
@Test
void updateTransactionWithAliasNotFoundAndPartialDataActionSkip() {
recordParserProperties.setPartialDataAction(PartialDataAction.SKIP);
var alias = DomainUtils.fromBytes(domainBuilder.key());
var recordItem = recordItemBuilder.tokenUpdate().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).build();
var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
var timestamp = recordItem.getConsensusTimestamp();
var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
transactionHandler.updateTransaction(transaction, recordItem);
assertTokenUpdate(timestamp, tokenId, Assertions::assertNull);
}
use of com.hederahashgraph.api.proto.java.TransactionBody in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method updateTransactionThrowsWithAliasNotFound.
@ParameterizedTest(name = "{0}")
@EnumSource(value = PartialDataAction.class, names = { "DEFAULT", "ERROR" })
void updateTransactionThrowsWithAliasNotFound(PartialDataAction partialDataAction) {
// given
recordParserProperties.setPartialDataAction(partialDataAction);
var alias = DomainUtils.fromBytes(domainBuilder.key());
var recordItem = recordItemBuilder.tokenUpdate().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).build();
var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
var timestamp = recordItem.getConsensusTimestamp();
var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
// when, then
assertThrows(AliasNotFoundException.class, () -> transactionHandler.updateTransaction(transaction, recordItem));
}
use of com.hederahashgraph.api.proto.java.TransactionBody 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.hederahashgraph.api.proto.java.TransactionBody 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.hederahashgraph.api.proto.java.TransactionBody 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