use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class UpdateAllProtectedFilesDuringReconnect method updateAllProtectedFilesDuringReconnect.
private HapiApiSpec updateAllProtectedFilesDuringReconnect() {
final String fileInfoRegistry = "apiPermissionsReconnect";
final String nonUpdatableFile = "nonUpdatableFile";
return customHapiSpec("UpdateAllProtectedFilesDuringReconnect").withProperties(Map.of("txn.start.offset.secs", "-5")).given(saveFileToRegistry(APP_PROPERTIES, APP_FILE_REGISTRY), saveFileToRegistry(API_PERMISSIONS, API_FILE_REGISTRY), saveFileToRegistry(EXCHANGE_RATES, RATES_FILE_REGISTRY), saveFileToRegistry(FEE_SCHEDULE, FEES_FILE_REGISTRY), sleepFor(Duration.ofSeconds(25).toMillis()), getAccountBalance(GENESIS).setNode("0.0.8").unavailableNode()).when(fileUpdate(APP_PROPERTIES).payingWith(GENESIS).overridingProps(Map.of("ledger.autoRenewPeriod.minDuration", "20")).erasingProps(Set.of("minimumAutoRenewDuration")), fileUpdate(API_PERMISSIONS).payingWith(GENESIS).overridingProps(Map.of("updateFile", "2-50")), fileCreate(nonUpdatableFile).contents("Cannot update file because of the new api permissions"), fileUpdate(EXCHANGE_RATES).contents(spec -> {
ByteString newRates = spec.ratesProvider().rateSetWith(100, 1).toByteString();
spec.registry().saveBytes("newRates", newRates);
return newRates;
}).payingWith(GENESIS), makeFree(CryptoGetInfo), getAccountBalance(GENESIS).setNode("0.0.8").unavailableNode()).then(withLiveNode("0.0.8").within(5 * 60, TimeUnit.SECONDS).loggingAvailabilityEvery(30).sleepingBetweenRetriesFor(10), UtilVerbs.sleepFor(30 * 1000), withLiveNode("0.0.8").within(5 * 60, TimeUnit.SECONDS).loggingAvailabilityEvery(30).sleepingBetweenRetriesFor(10), getFileContents(API_PERMISSIONS).logged().setNode("0.0.3").payingWith(GENESIS).saveToRegistry(fileInfoRegistry), getFileContents(API_PERMISSIONS).logged().setNode("0.0.8").payingWith(GENESIS).hasContents(fileInfoRegistry), fileUpdate(nonUpdatableFile).setNode("0.0.8").fee(ONE_MILLION_HBARS).hasPrecheck(NOT_SUPPORTED), fileCreate("contractFile").setNode("0.0.8").payingWith(GENESIS).path(ContractResources.VALID_BYTECODE_PATH), contractCreate("testContract").bytecode("contractFile").autoRenewSecs(15).setNode("0.0.8").hasPrecheck(AUTORENEW_DURATION_NOT_IN_RANGE), cryptoCreate("civilian").setNode("0.0.8").fee(ONE_HUNDRED_HBARS).hasPrecheck(INSUFFICIENT_TX_FEE), cryptoCreate("civilian").setNode("0.0.8"), getAccountInfo("0.0.2").payingWith("civilian").nodePayment(0L).setNode("0.0.8").hasAnswerOnlyPrecheck(OK), restoreFileFromRegistry(APP_PROPERTIES, APP_FILE_REGISTRY), restoreFileFromRegistry(API_PERMISSIONS, API_FILE_REGISTRY), restoreFileFromRegistry(EXCHANGE_RATES, RATES_FILE_REGISTRY), restoreFileFromRegistry(FEE_SCHEDULE, FEES_FILE_REGISTRY));
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ScheduleExecutionSpecs method scheduledSubmitFailedWithInvalidChunkTxnIdStillPaysServiceFeeButHasNoImpact.
private HapiApiSpec scheduledSubmitFailedWithInvalidChunkTxnIdStillPaysServiceFeeButHasNoImpact() {
String immutableTopic = "XXX";
String validSchedule = "withValidChunkTxnId";
String invalidSchedule = "withInvalidChunkTxnId";
String schedulePayer = "somebody";
String successTxn = "good", failedTxn = "bad";
AtomicReference<Map<AccountID, Long>> successFeesObs = new AtomicReference<>();
AtomicReference<Map<AccountID, Long>> failureFeesObs = new AtomicReference<>();
AtomicReference<TransactionID> initialTxnId = new AtomicReference<>();
AtomicReference<TransactionID> irrelevantTxnId = new AtomicReference<>();
return defaultHapiSpec("ScheduledSubmitFailedWithInvalidChunkTxnIdStillPaysServiceFeeButHasNoImpact").given(createTopic(immutableTopic), cryptoCreate(schedulePayer)).when(withOpContext((spec, opLog) -> {
var subOp = usableTxnIdNamed(successTxn).payerId(schedulePayer);
var secondSubOp = usableTxnIdNamed("wontWork").payerId(schedulePayer);
allRunFor(spec, subOp, secondSubOp);
initialTxnId.set(spec.registry().getTxnId(successTxn));
irrelevantTxnId.set(spec.registry().getTxnId("wontWork"));
}), sourcing(() -> scheduleCreate(validSchedule, submitMessageTo(immutableTopic).chunkInfo(3, 1, scheduledVersionOf(initialTxnId.get()))).txnId(successTxn).logged().signedBy(schedulePayer)), getTopicInfo(immutableTopic).hasSeqNo(1L), getTxnRecord(successTxn).scheduled().logged().revealingDebitsTo(successFeesObs::set), sourcing(() -> scheduleCreate(invalidSchedule, submitMessageTo(immutableTopic).chunkInfo(3, 1, scheduledVersionOf(irrelevantTxnId.get()))).designatingPayer(schedulePayer).via(failedTxn).logged().signedBy(DEFAULT_PAYER, schedulePayer))).then(getTopicInfo(immutableTopic).hasSeqNo(1L), getTxnRecord(failedTxn).scheduled().hasPriority(recordWith().status(INVALID_CHUNK_TRANSACTION_ID)).revealingDebitsTo(failureFeesObs::set), assertionsHold((spec, opLog) -> Assertions.assertEquals(successFeesObs.get(), failureFeesObs.get())));
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class ScheduleExecutionSpecs method scheduledXferFailingWithNonNetZeroTokenTransferPaysServiceFeeButNoImpact.
private HapiApiSpec scheduledXferFailingWithNonNetZeroTokenTransferPaysServiceFeeButNoImpact() {
String xToken = "XXX", yToken = "YYY";
String validSchedule = "withZeroNetTokenChange";
String invalidSchedule = "withNonZeroNetTokenChange";
String schedulePayer = "somebody", xTreasury = "xt", xCivilian = "xc";
String successTxn = "good", failedTxn = "bad";
AtomicReference<Map<AccountID, Long>> successFeesObs = new AtomicReference<>();
AtomicReference<Map<AccountID, Long>> failureFeesObs = new AtomicReference<>();
return defaultHapiSpec("ScheduledXferFailingWithRepeatedTokenIdPaysServiceFeeButNoImpact").given(cryptoCreate(schedulePayer), cryptoCreate(xTreasury), cryptoCreate(xCivilian), tokenCreate(xToken).treasury(xTreasury).initialSupply(101), tokenAssociate(xCivilian, xToken)).when(scheduleCreate(validSchedule, cryptoTransfer(moving(1, xToken).between(xTreasury, xCivilian))).via(successTxn).alsoSigningWith(xTreasury, schedulePayer).designatingPayer(schedulePayer), getAccountBalance(xTreasury).hasTokenBalance(xToken, 100), getAccountBalance(xCivilian).hasTokenBalance(xToken, 1), getTxnRecord(successTxn).scheduled().logged().revealingDebitsTo(successFeesObs::set), scheduleCreate(invalidSchedule, cryptoTransfer(moving(1, xToken).between(xTreasury, xCivilian)).breakingNetZeroInvariant()).via(failedTxn).alsoSigningWith(xTreasury, schedulePayer).designatingPayer(schedulePayer)).then(getTxnRecord(failedTxn).scheduled().hasPriority(recordWith().status(TRANSFERS_NOT_ZERO_SUM_FOR_TOKEN)).revealingDebitsTo(failureFeesObs::set), getAccountBalance(xTreasury).hasTokenBalance(xToken, 100), getAccountBalance(xCivilian).hasTokenBalance(xToken, 1), assertionsHold((spec, opLog) -> assertBasicallyIdentical(successFeesObs.get(), failureFeesObs.get(), 1.0)));
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class TokenAssociationSpecs method expiredAndDeletedTokensStillAppearInContractInfo.
public HapiApiSpec expiredAndDeletedTokensStillAppearInContractInfo() {
final String contract = "nothingMattersAnymore";
final String treasury = "something";
final String expiringToken = "expiringToken";
final long lifetimeSecs = 10;
final long xfer = 123L;
AtomicLong now = new AtomicLong();
return defaultHapiSpec("ExpiredAndDeletedTokensStillAppearInContractInfo").given(newKeyNamed("admin"), cryptoCreate(treasury), fileCreate("bytecode").path(ContractResources.FUSE_BYTECODE_PATH), contractCreate(contract).bytecode("bytecode").gas(300_000).via("creation"), withOpContext((spec, opLog) -> {
var subOp = getTxnRecord("creation");
allRunFor(spec, subOp);
var record = subOp.getResponseRecord();
now.set(record.getConsensusTimestamp().getSeconds());
}), sourcing(() -> tokenCreate(expiringToken).decimals(666).adminKey("admin").treasury(treasury).expiry(now.get() + lifetimeSecs))).when(tokenAssociate(contract, expiringToken), cryptoTransfer(moving(xfer, expiringToken).between(treasury, contract))).then(getAccountBalance(contract).hasTokenBalance(expiringToken, xfer), getContractInfo(contract).hasToken(relationshipWith(expiringToken).freeze(FreezeNotApplicable)), sleepFor(lifetimeSecs * 1_000L), getAccountBalance(contract).hasTokenBalance(expiringToken, xfer, 666), getContractInfo(contract).hasToken(relationshipWith(expiringToken).freeze(FreezeNotApplicable)), tokenDelete(expiringToken), getAccountBalance(contract).hasTokenBalance(expiringToken, xfer), getContractInfo(contract).hasToken(relationshipWith(expiringToken).decimals(666).freeze(FreezeNotApplicable)));
}
use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.
the class CreateTopicPerfSuite method createTopicPerf.
private HapiApiSpec createTopicPerf() {
final int NUM_TOPICS = 100000;
KeyShape submitKeyShape = threshOf(2, SIMPLE, SIMPLE, listOf(2));
return defaultHapiSpec("createTopicPerf").given().when(startThroughputObs("createTopicThroughput").msToSaturateQueues(50L), inParallel(// only ask for record for the last transaction
asOpArray(NUM_TOPICS, i -> (i == (NUM_TOPICS - 1)) ? createTopic("testTopic" + i).submitKeyShape(submitKeyShape) : createTopic("testTopic" + i).submitKeyShape(submitKeyShape).deferStatusResolution()))).then(// wait until the record of the last transaction are ready
finishThroughputObs("createTopicThroughput").gatedByQuery(() -> getTopicInfo("testTopic" + (NUM_TOPICS - 1))).sleepMs(1_000L).expiryMs(300_000L));
}
Aggregations