Skip to content

Commit 3f3008e

Browse files
authored
fix: Return REQUIRED_KEY in CryptoCreate if no alias is used (#12595)
Signed-off-by: Michael Heinrichs <[email protected]>
1 parent 9a6a687 commit 3f3008e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/handlers/CryptoCreateHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void pureChecks(@NonNull final TransactionBody txn) throws PreCheckExcept
133133
final var keyIsEmpty = isEmpty(key);
134134
if (!isInternal && keyIsEmpty) {
135135
if (key == null) {
136-
throw new PreCheckException(INVALID_ALIAS_KEY);
136+
throw new PreCheckException(alias.length() > 0 ? INVALID_ALIAS_KEY : KEY_REQUIRED);
137137
} else if (key.hasThresholdKey() || key.hasKeyList()) {
138138
throw new PreCheckException(KEY_REQUIRED);
139139
} else {

hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/handlers/CryptoCreateHandlerTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_RECEIVE_RECORD_THRESHOLD;
2727
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_RENEWAL_PERIOD;
2828
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_SEND_RECORD_THRESHOLD;
29+
import static com.hedera.hapi.node.base.ResponseCodeEnum.KEY_REQUIRED;
2930
import static com.hedera.hapi.node.base.ResponseCodeEnum.MEMO_TOO_LONG;
3031
import static com.hedera.hapi.node.base.ResponseCodeEnum.NOT_SUPPORTED;
3132
import static com.hedera.hapi.node.base.ResponseCodeEnum.PROXY_ACCOUNT_ID_FIELD_IS_DEPRECATED;
@@ -528,6 +529,20 @@ void validateKeyRequired() {
528529
setupConfig();
529530
setupExpiryValidator();
530531

532+
final var msg = assertThrows(PreCheckException.class, () -> subject.pureChecks(txn));
533+
assertEquals(KEY_REQUIRED, msg.responseCode());
534+
}
535+
536+
@Test
537+
void validateKeyRequiredWithAlias() {
538+
txn = new CryptoCreateBuilder()
539+
.withStakedAccountId(3)
540+
.withKey(null)
541+
.withAlias(Bytes.wrap("alias"))
542+
.build();
543+
setupConfig();
544+
setupExpiryValidator();
545+
531546
final var msg = assertThrows(PreCheckException.class, () -> subject.pureChecks(txn));
532547
assertEquals(INVALID_ALIAS_KEY, msg.responseCode());
533548
}

0 commit comments

Comments
 (0)