Skip to content

Commit

Permalink
refactor: remove duplicated response codes (#16925)
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Tronkov <99957253+vtronkov@users.noreply.github.com>
  • Loading branch information
vtronkov authored Dec 5, 2024
1 parent 1b7439f commit 1901fc3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
20 changes: 3 additions & 17 deletions hapi/hedera-protobufs/services/response_code.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1594,35 +1594,21 @@ enum ResponseCodeEnum {
*/
INVALID_TOKEN_IN_PENDING_AIRDROP = 369;

/**
* A scheduled transaction configured to wait for expiry to execute was given
* an expiry time not strictly after the time at which its creation reached
* consensus.
*/
SCHEDULE_EXPIRY_MUST_BE_FUTURE = 370;

/**
* A scheduled transaction configured to wait for expiry to execute was given
* an expiry time too far in the future after the time at which its creation
* reached consensus.
*/
SCHEDULE_EXPIRY_TOO_LONG = 371;

/**
* A scheduled transaction configured to wait for expiry to execute was given
* an expiry time at which there is already too many transactions scheduled to
* expire; its creation must be retried with a different expiry.
*/
SCHEDULE_EXPIRY_IS_BUSY = 372;
SCHEDULE_EXPIRY_IS_BUSY = 370;

/**
* The provided gRPC certificate hash is invalid.
*/
INVALID_GRPC_CERTIFICATE_HASH = 373;
INVALID_GRPC_CERTIFICATE_HASH = 371;

/**
* A scheduled transaction configured to wait for expiry to execute was not
* given an explicit expiration time.
*/
MISSING_EXPIRY_TIME = 374;
MISSING_EXPIRY_TIME = 372;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import static com.hedera.hapi.node.base.ResponseCodeEnum.MEMO_TOO_LONG;
import static com.hedera.hapi.node.base.ResponseCodeEnum.MISSING_EXPIRY_TIME;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SCHEDULED_TRANSACTION_NOT_IN_WHITELIST;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SCHEDULE_EXPIRATION_TIME_MUST_BE_HIGHER_THAN_CONSENSUS_TIME;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SCHEDULE_EXPIRATION_TIME_TOO_FAR_IN_FUTURE;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SCHEDULE_EXPIRY_IS_BUSY;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SCHEDULE_EXPIRY_MUST_BE_FUTURE;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SCHEDULE_EXPIRY_TOO_LONG;
import static com.hedera.hapi.node.base.SubType.DEFAULT;
import static com.hedera.hapi.node.base.SubType.SCHEDULE_CREATE_CONTRACT_CALL;
import static com.hedera.node.app.hapi.utils.CommonPbjConverters.fromPbj;
Expand Down Expand Up @@ -159,8 +159,8 @@ public void handle(@NonNull final HandleContext context) throws HandleException
createProvisionalSchedule(context.body(), consensusNow, maxLifetime, isLongTermEnabled);
final var now = consensusNow.getEpochSecond();
final var then = provisionalSchedule.calculatedExpirationSecond();
validateTrue(then > now, SCHEDULE_EXPIRY_MUST_BE_FUTURE);
validateTrue(then <= now + maxLifetime, SCHEDULE_EXPIRY_TOO_LONG);
validateTrue(then > now, SCHEDULE_EXPIRATION_TIME_MUST_BE_HIGHER_THAN_CONSENSUS_TIME);
validateTrue(then <= now + maxLifetime, SCHEDULE_EXPIRATION_TIME_TOO_FAR_IN_FUTURE);
validateTrue(
isAllowedFunction(provisionalSchedule.scheduledTransactionOrThrow(), schedulingConfig),
SCHEDULED_TRANSACTION_NOT_IN_WHITELIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
import static com.hederahashgraph.api.proto.java.HederaFunctionality.ConsensusCreateTopic;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.BUSY;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.MISSING_EXPIRY_TIME;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SCHEDULE_EXPIRATION_TIME_MUST_BE_HIGHER_THAN_CONSENSUS_TIME;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SCHEDULE_EXPIRATION_TIME_TOO_FAR_IN_FUTURE;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SCHEDULE_EXPIRY_IS_BUSY;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SCHEDULE_EXPIRY_MUST_BE_FUTURE;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SCHEDULE_EXPIRY_TOO_LONG;
import static java.util.Objects.requireNonNull;
import static java.util.Spliterator.DISTINCT;
import static java.util.Spliterator.NONNULL;
Expand Down Expand Up @@ -184,11 +184,11 @@ final Stream<DynamicTest> expiryMustBeValid() {
exposeSpecSecondTo(lastSecond::set),
sourcing(() -> scheduleCreate("tooSoon", cryptoTransfer(tinyBarsFromTo(DEFAULT_PAYER, FUNDING, 12L)))
.expiringAt(lastSecond.get())
.hasKnownStatus(SCHEDULE_EXPIRY_MUST_BE_FUTURE)),
.hasKnownStatus(SCHEDULE_EXPIRATION_TIME_MUST_BE_HIGHER_THAN_CONSENSUS_TIME)),
exposeSpecSecondTo(lastSecond::set),
sourcing(() -> scheduleCreate("tooLate", cryptoTransfer(tinyBarsFromTo(DEFAULT_PAYER, FUNDING, 34L)))
.expiringAt(lastSecond.get() + 1 + ONE_MINUTE + 1)
.hasKnownStatus(SCHEDULE_EXPIRY_TOO_LONG)),
.hasKnownStatus(SCHEDULE_EXPIRATION_TIME_TOO_FAR_IN_FUTURE)),
scheduleCreate("unspecified", cryptoTransfer(tinyBarsFromTo(DEFAULT_PAYER, FUNDING, 56L)))
.waitForExpiry()
.hasPrecheck(MISSING_EXPIRY_TIME));
Expand Down

0 comments on commit 1901fc3

Please sign in to comment.