Search in sources :

Example 16 with SUCCESS

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS in project hedera-services by hashgraph.

the class DissociatePrecompileSuite method dissociatePrecompileHasExpectedSemanticsForDeletedTokens.

/* -- Not specifically required in the HTS Precompile Test Plan -- */
public HapiApiSpec dissociatePrecompileHasExpectedSemanticsForDeletedTokens() {
    final String tbdUniqToken = "UniqToBeDeleted";
    final String zeroBalanceFrozen = "0bFrozen";
    final String zeroBalanceUnfrozen = "0bUnfrozen";
    final String nonZeroBalanceFrozen = "1bFrozen";
    final String nonZeroBalanceUnfrozen = "1bUnfrozen";
    final long initialSupply = 100L;
    final long nonZeroXfer = 10L;
    final var firstMeta = ByteString.copyFrom("FIRST".getBytes(StandardCharsets.UTF_8));
    final var secondMeta = ByteString.copyFrom("SECOND".getBytes(StandardCharsets.UTF_8));
    final var thirdMeta = ByteString.copyFrom("THIRD".getBytes(StandardCharsets.UTF_8));
    final AtomicReference<AccountID> accountID = new AtomicReference<>();
    final AtomicReference<AccountID> treasuryID = new AtomicReference<>();
    final AtomicReference<AccountID> zeroBalanceFrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> zeroBalanceUnfrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> nonZeroBalanceFrozenID = new AtomicReference<>();
    final AtomicReference<AccountID> nonZeroBalanceUnfrozenID = new AtomicReference<>();
    final AtomicReference<TokenID> tbdTokenID = new AtomicReference<>();
    final AtomicReference<TokenID> tbdUniqueTokenID = new AtomicReference<>();
    return defaultHapiSpec("DissociatePrecompileHasExpectedSemanticsForDeletedTokens").given(newKeyNamed(MULTI_KEY), cryptoCreate(ACCOUNT).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(accountID::set), fileCreate(THE_CONTRACT), updateLargeFile(ACCOUNT, THE_CONTRACT, extractByteCode(ContractResources.ASSOCIATE_DISSOCIATE_CONTRACT)), cryptoCreate(TOKEN_TREASURY).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(treasuryID::set), tokenCreate(TBD_TOKEN).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).initialSupply(initialSupply).treasury(TOKEN_TREASURY).freezeKey(MULTI_KEY).freezeDefault(true).exposingCreatedIdTo(id -> tbdTokenID.set(asToken(id))), tokenCreate(tbdUniqToken).tokenType(TokenType.NON_FUNGIBLE_UNIQUE).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).initialSupply(0).exposingCreatedIdTo(id -> tbdUniqueTokenID.set(asToken(id))), cryptoCreate(zeroBalanceFrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(zeroBalanceFrozenID::set), cryptoCreate(zeroBalanceUnfrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(zeroBalanceUnfrozenID::set), cryptoCreate(nonZeroBalanceFrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(nonZeroBalanceFrozenID::set), cryptoCreate(nonZeroBalanceUnfrozen).balance(10 * ONE_HUNDRED_HBARS).exposingCreatedIdTo(nonZeroBalanceUnfrozenID::set)).when(withOpContext((spec, opLog) -> allRunFor(spec, contractCreate(THE_CONTRACT).bytecode(THE_CONTRACT).gas(GAS_TO_OFFER), tokenAssociate(zeroBalanceFrozen, TBD_TOKEN), tokenAssociate(zeroBalanceUnfrozen, TBD_TOKEN), tokenAssociate(nonZeroBalanceFrozen, TBD_TOKEN), tokenAssociate(nonZeroBalanceUnfrozen, TBD_TOKEN), mintToken(tbdUniqToken, List.of(firstMeta, secondMeta, thirdMeta)), getAccountInfo(TOKEN_TREASURY).hasOwnedNfts(3), tokenUnfreeze(TBD_TOKEN, zeroBalanceUnfrozen), tokenUnfreeze(TBD_TOKEN, nonZeroBalanceUnfrozen), tokenUnfreeze(TBD_TOKEN, nonZeroBalanceFrozen), cryptoTransfer(moving(nonZeroXfer, TBD_TOKEN).between(TOKEN_TREASURY, nonZeroBalanceFrozen)), cryptoTransfer(moving(nonZeroXfer, TBD_TOKEN).between(TOKEN_TREASURY, nonZeroBalanceUnfrozen)), tokenFreeze(TBD_TOKEN, nonZeroBalanceFrozen), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(TBD_TOKEN, initialSupply - 2 * nonZeroXfer), tokenDelete(TBD_TOKEN), tokenDelete(tbdUniqToken), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(zeroBalanceFrozenID.get()), asAddress(tbdTokenID.get())).payingWith(zeroBalanceFrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateZeroBalanceFrozenTxn"), getTxnRecord("dissociateZeroBalanceFrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(zeroBalanceUnfrozenID.get()), asAddress(tbdTokenID.get())).payingWith(zeroBalanceUnfrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateZeroBalanceUnfrozenTxn"), getTxnRecord("dissociateZeroBalanceUnfrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(nonZeroBalanceFrozenID.get()), asAddress(tbdTokenID.get())).payingWith(nonZeroBalanceFrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateNonZeroBalanceFrozenTxn"), getTxnRecord("dissociateNonZeroBalanceFrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(nonZeroBalanceUnfrozenID.get()), asAddress(tbdTokenID.get())).payingWith(nonZeroBalanceUnfrozen).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).via("dissociateNonZeroBalanceUnfrozenTxn"), getTxnRecord("dissociateNonZeroBalanceUnfrozenTxn").andAllChildRecords().logged(), contractCall(THE_CONTRACT, SINGLE_TOKEN_DISSOCIATE, asAddress(treasuryID.get()), asAddress(tbdUniqueTokenID.get())).alsoSigningWithFullPrefix(MULTI_KEY).gas(GAS_TO_OFFER).payingWith(TOKEN_TREASURY)))).then(childRecordsCheck("dissociateZeroBalanceFrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateZeroBalanceUnfrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateNonZeroBalanceFrozenTxn", SUCCESS, recordWith().status(SUCCESS)), childRecordsCheck("dissociateNonZeroBalanceUnfrozenTxn", SUCCESS, recordWith().status(SUCCESS)), getAccountInfo(zeroBalanceFrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(zeroBalanceUnfrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(nonZeroBalanceFrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(nonZeroBalanceUnfrozen).hasNoTokenRelationship(TBD_TOKEN), getAccountInfo(TOKEN_TREASURY).hasToken(relationshipWith(TBD_TOKEN)).hasNoTokenRelationship(tbdUniqToken).hasOwnedNfts(0), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(TBD_TOKEN, initialSupply - 2 * nonZeroXfer));
}
Also used : SINGLE_TOKEN_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SINGLE_TOKEN_DISSOCIATE) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.tokenDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDelete) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) ExpectedTokenRel.relationshipWith(com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) TBD_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.TBD_TOKEN) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) MULTIPLE_TOKENS_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MULTIPLE_TOKENS_DISSOCIATE) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) StandardCharsets(java.nio.charset.StandardCharsets) Utils.extractByteCode(com.hedera.services.bdd.suites.contract.Utils.extractByteCode) ByteString(com.google.protobuf.ByteString) List(java.util.List) Logger(org.apache.logging.log4j.Logger) NotNull(org.jetbrains.annotations.NotNull) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) FREEZABLE_TOKEN_ON_BY_DEFAULT(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.FREEZABLE_TOKEN_ON_BY_DEFAULT) NESTED_TOKEN_DISSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.NESTED_TOKEN_DISSOCIATE) AtomicReference(java.util.concurrent.atomic.AtomicReference) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) UtilVerbs.childRecordsCheck(com.hedera.services.bdd.spec.utilops.UtilVerbs.childRecordsCheck) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiPropertySource.asDotDelimitedLongArray(com.hedera.services.bdd.spec.HapiPropertySource.asDotDelimitedLongArray) AccountID(com.hederahashgraph.api.proto.java.AccountID) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TxnVerbs.tokenFreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenFreeze) UtilVerbs.updateLargeFile(com.hedera.services.bdd.spec.utilops.UtilVerbs.updateLargeFile) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) VANILLA_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.VANILLA_TOKEN) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TokenType(com.hederahashgraph.api.proto.java.TokenType) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) KNOWABLE_TOKEN(com.hedera.services.bdd.suites.token.TokenAssociationSpecs.KNOWABLE_TOKEN) TokenID(com.hederahashgraph.api.proto.java.TokenID) Utils.asAddress(com.hedera.services.bdd.suites.contract.Utils.asAddress) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) LogManager(org.apache.logging.log4j.LogManager) TxnVerbs.tokenUnfreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnfreeze) AccountID(com.hederahashgraph.api.proto.java.AccountID) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) TokenID(com.hederahashgraph.api.proto.java.TokenID)

Example 17 with SUCCESS

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS in project hedera-services by hashgraph.

the class FileExpansionLoadProvider method fileExpansionsFactory.

private Function<HapiApiSpec, OpProvider> fileExpansionsFactory() {
    final SplittableRandom r = new SplittableRandom();
    final Set<String> usableTargets = ConcurrentHashMap.newKeySet();
    final LongFunction<String> targetNameFn = i -> "expandingFile" + i;
    final AtomicInteger nextTargetNum = new AtomicInteger(numActiveTargets.get());
    final var key = "multi";
    final var waclShape = KeyShape.listOf(SIMPLE, threshOf(1, 3), listOf(2));
    return spec -> new OpProvider() {

        @Override
        public List<HapiSpecOperation> suggestedInitializers() {
            final List<HapiSpecOperation> ops = new ArrayList<>();
            ops.add(newKeyNamed(key).shape(waclShape));
            for (int i = 0, n = numActiveTargets.get(); i < n; i++) {
                ops.add(fileCreate(targetNameFn.apply(i)).key(key).noLogging().contents(DATA_CHUNK).payingWith(GENESIS));
            }
            return ops;
        }

        @Override
        public Optional<HapiSpecOperation> get() {
            HapiSpecOperation op;
            if (usableTargets.size() < numActiveTargets.get()) {
                final var name = targetNameFn.apply(nextTargetNum.getAndIncrement());
                op = fileCreate(name).noLogging().key(key).contents(DATA_CHUNK).payingWith(GENESIS).deferStatusResolution().exposingNumTo(num -> {
                    usableTargets.add(name);
                });
            } else {
                final var skips = r.nextInt(usableTargets.size());
                final var iter = usableTargets.iterator();
                try {
                    for (int i = 0; i < skips; i++) {
                        iter.next();
                    }
                    final var target = iter.next();
                    op = fileAppend(target).noLogging().deferStatusResolution().payingWith(GENESIS).content(DATA_CHUNK).hasKnownStatusFrom(MAX_FILE_SIZE_EXCEEDED, SUCCESS).alertingPost(code -> {
                        if (code == MAX_FILE_SIZE_EXCEEDED) {
                            log.info("File {} reached max size, no longer in rotation", target);
                            usableTargets.remove(target);
                        }
                    });
                } catch (Exception ignore) {
                    op = noOp();
                }
            }
            return Optional.of(op);
        }
    };
}
Also used : UtilVerbs.overriding(com.hedera.services.bdd.spec.utilops.UtilVerbs.overriding) UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) MINUTES(java.util.concurrent.TimeUnit.MINUTES) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) PerfUtilOps.stdMgmtOf(com.hedera.services.bdd.suites.perf.PerfUtilOps.stdMgmtOf) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TxnVerbs.fileAppend(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) SplittableRandom(java.util.SplittableRandom) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) MAX_FILE_SIZE_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_FILE_SIZE_EXCEEDED) LongFunction(java.util.function.LongFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) TimeUnit(java.util.concurrent.TimeUnit) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) AtomicLong(java.util.concurrent.atomic.AtomicLong) UtilVerbs.noOp(com.hedera.services.bdd.spec.utilops.UtilVerbs.noOp) List(java.util.List) HapiSpecSetup.getDefaultNodeProps(com.hedera.services.bdd.spec.HapiSpecSetup.getDefaultNodeProps) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) BYTES_4K(com.hedera.services.bdd.spec.transactions.TxnUtils.BYTES_4K) PerfUtilOps.mgmtOfIntProp(com.hedera.services.bdd.suites.perf.PerfUtilOps.mgmtOfIntProp) ArrayList(java.util.ArrayList) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) SplittableRandom(java.util.SplittableRandom)

Example 18 with SUCCESS

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS in project hedera-services by hashgraph.

the class MixedFileOpsLoadTest method runMixedFileOps.

protected HapiApiSpec runMixedFileOps() {
    PerfTestLoadSettings settings = new PerfTestLoadSettings();
    final AtomicInteger submittedSoFar = new AtomicInteger(0);
    String initialContent = "The initial contents!";
    String targetFile = "targetFile";
    Supplier<HapiSpecOperation[]> mixedFileOpsBurst = () -> new HapiSpecOperation[] { fileCreate(targetFile + submittedSoFar.getAndIncrement()).contents(initialContent).hasKnownStatusFrom(SUCCESS, UNKNOWN), fileUpdate(targetFile).fee(ONE_HUNDRED_HBARS).contents(TxnUtils.randomUtf8Bytes(TxnUtils.BYTES_4K)).noLogging().payingWith(GENESIS).hasAnyPrecheck().hasKnownStatusFrom(SUCCESS, UNKNOWN).deferStatusResolution(), fileAppend(targetFile).content("dummy").hasAnyPrecheck().payingWith(GENESIS).fee(ONE_HUNDRED_HBARS).hasKnownStatusFrom(SUCCESS, UNKNOWN).deferStatusResolution() };
    return defaultHapiSpec("runMixedFileOps").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when(fileCreate(targetFile).contents(initialContent).hasAnyPrecheck().payingWith(GENESIS), getFileInfo(targetFile).logging().payingWith(GENESIS)).then(defaultLoadTest(mixedFileOpsBurst, settings));
}
Also used : LoadTest(com.hedera.services.bdd.spec.utilops.LoadTest) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) UNKNOWN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN) UtilVerbs.logIt(com.hedera.services.bdd.spec.utilops.UtilVerbs.logIt) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Supplier(java.util.function.Supplier) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) TxnVerbs.fileAppend(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation)

Example 19 with SUCCESS

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS in project hedera-services by hashgraph.

the class MixedOpsLoadTest method runMixedOps.

protected HapiApiSpec runMixedOps() {
    PerfTestLoadSettings settings = new PerfTestLoadSettings();
    Random r = new Random();
    AtomicInteger tokenId = new AtomicInteger(0);
    AtomicInteger scheduleId = new AtomicInteger(0);
    Supplier<HapiSpecOperation[]> mixedOpsBurst = () -> new HapiSpecOperation[] { cryptoTransfer(tinyBarsFromTo(sender, receiver, 1L)).noLogging().payingWith(sender).signedBy(GENESIS).suppressStats(true).fee(ONE_HBAR).hasKnownStatusFrom(SUCCESS, OK, INSUFFICIENT_PAYER_BALANCE, UNKNOWN, TRANSACTION_EXPIRED).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED, PAYER_ACCOUNT_NOT_FOUND).deferStatusResolution(), submitMessageTo(topic).message(ArrayUtils.addAll(ByteBuffer.allocate(8).putLong(Instant.now().toEpochMilli()).array(), randomUtf8Bytes(messageSize - 8))).noLogging().payingWith(GENESIS).signedBy(sender, submitKey).fee(ONE_HBAR).suppressStats(true).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED, TOPIC_EXPIRED, INVALID_TOPIC_ID, INSUFFICIENT_PAYER_BALANCE).hasKnownStatusFrom(SUCCESS, OK, INVALID_TOPIC_ID, INSUFFICIENT_PAYER_BALANCE, UNKNOWN, TRANSACTION_EXPIRED).deferStatusResolution(), r.nextInt(100) > 5 ? cryptoTransfer(moving(1, token + r.nextInt(NUM_SUBMISSIONS)).between(sender, receiver)).payingWith(sender).signedBy(GENESIS).fee(ONE_HUNDRED_HBARS).noLogging().suppressStats(true).hasPrecheckFrom(OK, INSUFFICIENT_PAYER_BALANCE, EMPTY_TOKEN_TRANSFER_ACCOUNT_AMOUNTS, DUPLICATE_TRANSACTION).hasRetryPrecheckFrom(permissiblePrechecks).hasKnownStatusFrom(SUCCESS, OK, INSUFFICIENT_TOKEN_BALANCE, TRANSACTION_EXPIRED, INVALID_TOKEN_ID, UNKNOWN, TOKEN_NOT_ASSOCIATED_TO_ACCOUNT).deferStatusResolution() : scheduleSign(schedule + "-" + getHostName() + "-" + r.nextInt(NUM_SUBMISSIONS)).ignoreIfMissing().noLogging().alsoSigningWith(receiver).hasPrecheckFrom(OK, INVALID_SCHEDULE_ID).hasKnownStatusFrom(SUCCESS, OK, TRANSACTION_EXPIRED, INVALID_SCHEDULE_ID, UNKNOWN, SCHEDULE_ALREADY_EXECUTED).fee(ONE_HBAR).deferStatusResolution() };
    return defaultHapiSpec("RunMixedOps").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString()), newKeyNamed("submitKey"), tokenOpsEnablement(), scheduleOpsEnablement(), cryptoCreate("treasury").hasRetryPrecheckFrom(permissiblePrechecks).key(GENESIS)).when(fileUpdate(APP_PROPERTIES).payingWith(GENESIS).overridingProps(Map.of("hapi.throttling.buckets.fastOpBucket.capacity", "1300000.0", "hapi.throttling.ops.consensusUpdateTopic.capacityRequired", "1.0", "hapi.throttling.ops.consensusGetTopicInfo.capacityRequired", "1.0", "hapi.throttling.ops.consensusSubmitMessage.capacityRequired", "1.0", "tokens.maxPerAccount", "10000000")), cryptoCreate(sender).balance(initialBalance.getAsLong()).withRecharging().key(GENESIS).rechargeWindow(3).hasRetryPrecheckFrom(permissiblePrechecks), cryptoCreate(receiver).hasRetryPrecheckFrom(permissiblePrechecks).key(GENESIS), createTopic(topic).submitKeyName("submitKey"), inParallel(IntStream.range(0, NUM_SUBMISSIONS).mapToObj(ignore -> tokenCreate("token" + tokenId.getAndIncrement()).payingWith(GENESIS).signedBy(GENESIS).fee(ONE_HUNDRED_HBARS).initialSupply(ONE_HUNDRED_HBARS).treasury("treasury").hasRetryPrecheckFrom(permissiblePrechecks).hasPrecheckFrom(DUPLICATE_TRANSACTION, OK).deferStatusResolution().noLogging()).toArray(n -> new HapiSpecOperation[n])), sleepFor(10000), inParallel(IntStream.range(0, NUM_SUBMISSIONS).mapToObj(ignore -> scheduleCreate("schedule-" + getHostName() + "-" + scheduleId.getAndIncrement(), cryptoTransfer(tinyBarsFromTo(sender, receiver, 1))).signedBy(DEFAULT_PAYER).fee(ONE_HUNDRED_HBARS).alsoSigningWith(sender).hasPrecheckFrom(STANDARD_PERMISSIBLE_PRECHECKS).hasAnyKnownStatus().deferStatusResolution().adminKey(DEFAULT_PAYER).noLogging()).toArray(n -> new HapiSpecOperation[n])), sleepFor(10000), inParallel(IntStream.range(0, NUM_SUBMISSIONS).mapToObj(i -> tokenAssociate(sender, "token" + i).payingWith(GENESIS).signedBy(GENESIS).hasRetryPrecheckFrom(permissiblePrechecks).hasPrecheckFrom(DUPLICATE_TRANSACTION, OK).hasKnownStatusFrom(SUCCESS, TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT, INVALID_TOKEN_ID, TRANSACTION_EXPIRED, TOKENS_PER_ACCOUNT_LIMIT_EXCEEDED, OK).fee(ONE_HUNDRED_HBARS).suppressStats(true).deferStatusResolution().noLogging()).toArray(n -> new HapiSpecOperation[n])), sleepFor(10000)).then(defaultLoadTest(mixedOpsBurst, settings));
}
Also used : OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) PAYER_ACCOUNT_NOT_FOUND(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PAYER_ACCOUNT_NOT_FOUND) Random(java.util.Random) TRANSACTION_EXPIRED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TRANSACTION_EXPIRED) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) UtilVerbs.inParallel(com.hedera.services.bdd.spec.utilops.UtilVerbs.inParallel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) INVALID_TOPIC_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOPIC_ID) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) SCHEDULE_ALREADY_EXECUTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SCHEDULE_ALREADY_EXECUTED) TxnVerbs.scheduleCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.scheduleCreate) UNKNOWN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN) TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT) UtilVerbs.logIt(com.hedera.services.bdd.spec.utilops.UtilVerbs.logIt) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TxnVerbs.submitMessageTo(com.hedera.services.bdd.spec.transactions.TxnVerbs.submitMessageTo) Instant(java.time.Instant) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) TOKEN_NOT_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) BUSY(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BUSY) TOPIC_EXPIRED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOPIC_EXPIRED) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) PLATFORM_TRANSACTION_NOT_CREATED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PLATFORM_TRANSACTION_NOT_CREATED) IntStream(java.util.stream.IntStream) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) INSUFFICIENT_PAYER_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) ArrayUtils(org.apache.commons.lang3.ArrayUtils) TxnVerbs.createTopic(com.hedera.services.bdd.spec.transactions.TxnVerbs.createTopic) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) Supplier(java.util.function.Supplier) PerfUtilOps.tokenOpsEnablement(com.hedera.services.bdd.suites.perf.PerfUtilOps.tokenOpsEnablement) EMPTY_TOKEN_TRANSFER_ACCOUNT_AMOUNTS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.EMPTY_TOKEN_TRANSFER_ACCOUNT_AMOUNTS) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) DUPLICATE_TRANSACTION(com.hederahashgraph.api.proto.java.ResponseCodeEnum.DUPLICATE_TRANSACTION) INSUFFICIENT_TOKEN_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TOKEN_BALANCE) STANDARD_PERMISSIBLE_PRECHECKS(com.hedera.services.bdd.spec.infrastructure.OpProvider.STANDARD_PERMISSIBLE_PRECHECKS) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) TOKENS_PER_ACCOUNT_LIMIT_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKENS_PER_ACCOUNT_LIMIT_EXCEEDED) LoadTest(com.hedera.services.bdd.spec.utilops.LoadTest) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TxnVerbs.scheduleSign(com.hedera.services.bdd.spec.transactions.TxnVerbs.scheduleSign) INVALID_TOKEN_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID) INVALID_SCHEDULE_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SCHEDULE_ID) TxnUtils.randomUtf8Bytes(com.hedera.services.bdd.spec.transactions.TxnUtils.randomUtf8Bytes) LogManager(org.apache.logging.log4j.LogManager) PerfUtilOps.scheduleOpsEnablement(com.hedera.services.bdd.suites.perf.PerfUtilOps.scheduleOpsEnablement) Random(java.util.Random) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation)

Example 20 with SUCCESS

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS in project hedera-services by hashgraph.

the class TokenRelStatusChanges method statusChangesFactory.

private Function<HapiApiSpec, OpProvider> statusChangesFactory() {
    var nowAssociating = new AtomicBoolean(Boolean.FALSE);
    var relatableTokens = new AtomicInteger();
    var relatableAccounts = new AtomicInteger();
    List<String> tokens = new ArrayList<>();
    List<String> accounts = new ArrayList<>();
    var nextToken = new AtomicInteger(-1);
    var nextAccount = new AtomicInteger(-1);
    return spec -> new OpProvider() {

        @Override
        public List<HapiSpecOperation> suggestedInitializers() {
            var ciProps = spec.setup().ciPropertiesMap();
            relatableTokens.set(ciProps.getInteger("numTokens"));
            relatableAccounts.set(ciProps.getInteger("numAccounts"));
            List<HapiSpecOperation> initializers = new ArrayList<>();
            initializers.add(tokenOpsEnablement().hasRetryPrecheckFrom(NOISY_RETRY_PRECHECKS));
            IntStream.range(0, relatableTokens.get()).mapToObj(i -> "token" + i).forEach(tokens::add);
            initializers.add(inParallel(tokens.stream().map(token -> tokenCreate(token).hasRetryPrecheckFrom(NOISY_RETRY_PRECHECKS)).toArray(HapiSpecOperation[]::new)));
            IntStream.range(0, relatableAccounts.get()).mapToObj(i -> "account" + i).forEach(accounts::add);
            initializers.add(inParallel(accounts.stream().map(account -> cryptoCreate(account).hasRetryPrecheckFrom(NOISY_RETRY_PRECHECKS)).toArray(HapiSpecOperation[]::new)));
            return initializers;
        }

        @Override
        public Optional<HapiSpecOperation> get() {
            HapiSpecOperation op;
            final int numTokens = relatableTokens.get();
            final int numAccounts = relatableAccounts.get();
            int token = nextToken.get() % numTokens;
            int account = nextAccount.incrementAndGet() % numAccounts;
            if (account == 0) {
                token = nextToken.incrementAndGet() % numTokens;
                if (token == 0) {
                    var current = nowAssociating.get();
                    nowAssociating.compareAndSet(current, !current);
                }
            }
            if (nowAssociating.get()) {
                op = tokenAssociate(accounts.get(account), tokens.get(token)).fee(ONE_HUNDRED_HBARS).hasRetryPrecheckFrom(NOISY_RETRY_PRECHECKS).hasKnownStatusFrom(OK, SUCCESS, DUPLICATE_TRANSACTION, TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT).noLogging().deferStatusResolution();
            } else {
                op = tokenDissociate(accounts.get(account), tokens.get(token)).fee(ONE_HUNDRED_HBARS).hasRetryPrecheckFrom(NOISY_RETRY_PRECHECKS).hasKnownStatusFrom(OK, SUCCESS, DUPLICATE_TRANSACTION, TOKEN_NOT_ASSOCIATED_TO_ACCOUNT).noLogging().deferStatusResolution();
            }
            return Optional.of(op);
        }
    };
}
Also used : IntStream(java.util.stream.IntStream) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MINUTES(java.util.concurrent.TimeUnit.MINUTES) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) PerfUtilOps.tokenOpsEnablement(com.hedera.services.bdd.suites.perf.PerfUtilOps.tokenOpsEnablement) ArrayList(java.util.ArrayList) PerfUtilOps.stdMgmtOf(com.hedera.services.bdd.suites.perf.PerfUtilOps.stdMgmtOf) UtilVerbs.inParallel(com.hedera.services.bdd.spec.utilops.UtilVerbs.inParallel) DUPLICATE_TRANSACTION(com.hederahashgraph.api.proto.java.ResponseCodeEnum.DUPLICATE_TRANSACTION) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) NOISY_RETRY_PRECHECKS(com.hedera.services.bdd.spec.transactions.TxnUtils.NOISY_RETRY_PRECHECKS) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) TOKEN_NOT_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Optional(java.util.Optional) TxnVerbs.tokenDissociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenDissociate) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) ArrayList(java.util.ArrayList) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation)

Aggregations

SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)27 List (java.util.List)21 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)20 LogManager (org.apache.logging.log4j.LogManager)20 Logger (org.apache.logging.log4j.Logger)20 UtilVerbs.withOpContext (com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext)18 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)16 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)15 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)15 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)13 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)11 TxnVerbs.tokenCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate)10 CustomSpecAssert.allRunFor (com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor)10 AccountID (com.hederahashgraph.api.proto.java.AccountID)10 OK (com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK)10 ByteString (com.google.protobuf.ByteString)9 TxnVerbs.fileCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate)9 TxnVerbs.tokenAssociate (com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 TokenMovement.moving (com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving)8