Skip to content

Commit

Permalink
test: Schedule Create POSITIVE tests from test plan (#16797)
Browse files Browse the repository at this point in the history
Signed-off-by: ibankov <[email protected]>
  • Loading branch information
ibankov authored Dec 5, 2024
1 parent 1901fc3 commit 54495da
Show file tree
Hide file tree
Showing 6 changed files with 1,419 additions and 1,509 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ public HapiScheduleCreate<T> waitForExpiry(boolean value) {

public HapiScheduleCreate<T> expiringAt(final long expiry) {
this.longTermExpiry = expiry;
return waitForExpiry();
return this;
}

public HapiScheduleCreate<T> expiringIn(final long lifetime) {
this.longTermLifetime = lifetime;
return waitForExpiry();
return this;
}

public HapiScheduleCreate<T> withRelativeExpiry(String txnId, long offsetSeconds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@

package com.hedera.services.bdd.suites.hip423;

import static com.hedera.services.bdd.spec.queries.QueryVerbs.getScheduleInfo;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.randomUppercase;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.scheduleCreate;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.buildUpgradeZipFrom;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.prepareUpgrade;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepForSeconds;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.updateSpecialFile;
import static com.hedera.services.bdd.spec.utilops.upgrade.BuildUpgradeZipOp.FAKE_UPGRADE_ZIP_LOC;
import static com.hedera.services.bdd.suites.HapiSuite.GENESIS;
import static com.hedera.services.bdd.suites.HapiSuite.flattened;
import static com.hedera.services.bdd.suites.freeze.CommonUpgradeResources.DEFAULT_UPGRADE_FILE_ID;
import static com.hedera.services.bdd.suites.freeze.CommonUpgradeResources.FAKE_ASSETS_LOC;
import static com.hedera.services.bdd.suites.freeze.CommonUpgradeResources.upgradeFileAppendsPerBurst;
import static com.hedera.services.bdd.suites.freeze.CommonUpgradeResources.upgradeFileHashAt;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SCHEDULE_ID;

import com.hedera.services.bdd.spec.SpecOperation;
import com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord;
Expand All @@ -39,15 +44,17 @@

public final class LongTermScheduleUtils {

static final String SENDER = "sender";
public static final String SENDER = "sender";
public static final String SENDER_KEY = "senderKey";
public static final String SENDER_TXN = "senderTxn";
public static final String NEW_SENDER_KEY = "newSenderKey";
public static final String RECEIVER = "receiver";
public static final String CREATE_TXN = "createTxn";
static final String PAYER = "payer";
static final String ADMIN = "admin";
static final String EXTRA_KEY = "extraKey";
static final String SHARED_KEY = "sharedKey";
static final String NEW_SENDER_KEY = "newSenderKey";
static final String SENDER_TXN = "senderTxn";
static final String CREATE_TXN = "createTxn";
static final String RECEIVER = "receiver";
static final String TRIGGERING_TXN = "triggeringTxn";
static final String BASIC_XFER = "basicXfer";
static final String TWO_SIG_XFER = "twoSigXfer";
static final String DEFERRED_XFER = "deferredXfer";
Expand Down Expand Up @@ -127,8 +134,23 @@ static SpecOperation[] scheduleFakeUpgrade(
.designatingPayer(GENESIS)
.payingWith(payer)
.recordingScheduledTxn()
.waitForExpiry()
.expiringIn(lifetime)
.via(via)));
return operations.toArray(SpecOperation[]::new);
}

public static SpecOperation[] triggerSchedule(String schedule, long waitForSeconds) {
return flattened(
sleepForSeconds(waitForSeconds),
cryptoCreate("foo").via(TRIGGERING_TXN),
// Pause execution for 1 second to allow time for the scheduled transaction to be
// processed and removed from the state
sleepForSeconds(1),
getScheduleInfo(schedule).hasCostAnswerPrecheck(INVALID_SCHEDULE_ID));
}

public static SpecOperation[] triggerSchedule(String schedule) {
return triggerSchedule(schedule, 5);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.services.bdd.suites.hip423;

import static com.hedera.services.bdd.spec.HapiSpec.hapiTest;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getScheduleInfo;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer;
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.scheduleCreate;
import static com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo;
import static com.hedera.services.bdd.suites.HapiSuite.DEFAULT_PAYER;
import static com.hedera.services.bdd.suites.hip423.LongTermScheduleUtils.RECEIVER;

import com.hedera.services.bdd.junit.HapiTest;
import com.hedera.services.bdd.junit.HapiTestLifecycle;
import com.hedera.services.bdd.junit.support.TestLifecycle;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestMethodOrder;

@HapiTestLifecycle
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class ScheduleLongTermCreateTests {

private static final long MAX_SCHEDULE_EXPIRY_TIME = TimeUnit.DAYS.toSeconds(60);

@BeforeAll
static void beforeAll(@NonNull final TestLifecycle testLifecycle) {
testLifecycle.overrideInClass(Map.of(
"scheduling.longTermEnabled",
"true",
"scheduling.maxExpirationFutureSeconds",
Long.toString(MAX_SCHEDULE_EXPIRY_TIME)));
}

@HapiTest
final Stream<DynamicTest> scheduleCreateDefaultsToMaxValueFromConfig() {
return hapiTest(
cryptoCreate(RECEIVER).balance(0L),
scheduleCreate("one", cryptoTransfer(tinyBarsFromTo(DEFAULT_PAYER, RECEIVER, 1L)))
.via("createTxn"),
getScheduleInfo("one").hasRelativeExpiry("createTxn", MAX_SCHEDULE_EXPIRY_TIME));
}

@HapiTest
final Stream<DynamicTest> scheduleCreateMinimumTime() {
return hapiTest(
cryptoCreate(RECEIVER).balance(0L),
scheduleCreate("one", cryptoTransfer(tinyBarsFromTo(DEFAULT_PAYER, RECEIVER, 1L)))
.waitForExpiry(false)
.expiringIn(1)
.via("createTxn"),
getScheduleInfo("one").isExecuted().hasRelativeExpiry("createTxn", 1));
}
}
Loading

0 comments on commit 54495da

Please sign in to comment.