Search in sources :

Example 6 with OpProvider

use of com.hedera.services.bdd.spec.infrastructure.OpProvider 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 7 with OpProvider

use of com.hedera.services.bdd.spec.infrastructure.OpProvider 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)

Example 8 with OpProvider

use of com.hedera.services.bdd.spec.infrastructure.OpProvider in project hedera-services by hashgraph.

the class TokenTransferBasicLoadTest method tokenCreatesFactory.

private Function<HapiApiSpec, OpProvider> tokenCreatesFactory(PerfTestLoadSettings settings) {
    int numTotalTokens = settings.getTotalTokens();
    int totalClients = settings.getTotalClients();
    int numActiveTokens = (totalClients >= 1) ? numTotalTokens / totalClients : numTotalTokens;
    AtomicInteger remaining = new AtomicInteger(numActiveTokens - 1);
    return spec -> new OpProvider() {

        @Override
        public List<HapiSpecOperation> suggestedInitializers() {
            return Collections.emptyList();
        }

        @Override
        public Optional<HapiSpecOperation> get() {
            int next;
            if ((next = remaining.getAndDecrement()) < 0) {
                return Optional.empty();
            }
            var payingTreasury = String.format("0.0.%d", settings.getTestTreasureStartAccount() + next);
            var op = tokenCreate(tokenRegistryName(next)).payingWith(DEFAULT_PAYER).signedBy(DEFAULT_PAYER).fee(ONE_HUNDRED_HBARS).initialSupply(100_000_000_000L).treasury(payingTreasury).hasRetryPrecheckFrom(BUSY, PLATFORM_TRANSACTION_NOT_CREATED, DUPLICATE_TRANSACTION, INSUFFICIENT_PAYER_BALANCE).hasPrecheckFrom(DUPLICATE_TRANSACTION, OK).hasKnownStatusFrom(SUCCESS, TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT, TOKENS_PER_ACCOUNT_LIMIT_EXCEEDED, FAIL_INVALID).suppressStats(true).noLogging();
            return Optional.of(op);
        }
    };
}
Also used : TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) INSUFFICIENT_PAYER_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) 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) Function(java.util.function.Function) Supplier(java.util.function.Supplier) EMPTY_TOKEN_TRANSFER_ACCOUNT_AMOUNTS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.EMPTY_TOKEN_TRANSFER_ACCOUNT_AMOUNTS) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) DUPLICATE_TRANSACTION(com.hederahashgraph.api.proto.java.ResponseCodeEnum.DUPLICATE_TRANSACTION) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) INSUFFICIENT_TOKEN_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_TOKEN_BALANCE) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) 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) UNKNOWN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN) TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT) FAIL_INVALID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FAIL_INVALID) INVALID_TOKEN_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID) 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) BUSY(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BUSY) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) PLATFORM_TRANSACTION_NOT_CREATED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PLATFORM_TRANSACTION_NOT_CREATED) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider)

Example 9 with OpProvider

use of com.hedera.services.bdd.spec.infrastructure.OpProvider in project hedera-services by hashgraph.

the class TokenTransfersLoadProvider method tokenTransfersFactory.

private Function<HapiApiSpec, OpProvider> tokenTransfersFactory() {
    var firstDir = new AtomicBoolean(Boolean.TRUE);
    var balanceInit = new AtomicLong();
    var tokensPerTxn = new AtomicInteger();
    var sendingAccountsPerToken = new AtomicInteger();
    var receivingAccountsPerToken = new AtomicInteger();
    List<String> treasuries = new ArrayList<>();
    Map<String, List<String>> senders = new HashMap<>();
    Map<String, List<String>> receivers = new HashMap<>();
    return spec -> new OpProvider() {

        @Override
        public List<HapiSpecOperation> suggestedInitializers() {
            var ciProps = spec.setup().ciPropertiesMap();
            balanceInit.set(ciProps.getLong("balanceInit"));
            tokensPerTxn.set(ciProps.getInteger("tokensPerTxn"));
            sendingAccountsPerToken.set(ciProps.getInteger("sendingAccountsPerToken"));
            receivingAccountsPerToken.set(ciProps.getInteger("receivingAccountsPerToken"));
            var initialSupply = (sendingAccountsPerToken.get() + receivingAccountsPerToken.get()) * balanceInit.get();
            List<HapiSpecOperation> initializers = new ArrayList<>();
            initializers.add(tokenOpsEnablement());
            /* Temporary, can be removed after the public testnet state used in
				   restart tests includes a fee schedule with HTS resource prices. */
            if (spec.setup().defaultNode().equals(asAccount("0.0.3"))) {
                initializers.add(uploadDefaultFeeSchedules(GENESIS));
            } else {
                initializers.add(withOpContext((spec, opLog) -> {
                    log.info("\n\n" + bannerWith("Waiting for a fee schedule with token ops!"));
                    boolean hasKnownHtsFeeSchedules = false;
                    SysFileSerde<String> serde = new FeesJsonToGrpcBytes();
                    while (!hasKnownHtsFeeSchedules) {
                        var query = QueryVerbs.getFileContents(FEE_SCHEDULE).fee(10_000_000_000L);
                        try {
                            allRunFor(spec, query);
                            var contents = query.getResponse().getFileGetContents().getFileContents().getContents();
                            var schedules = serde.fromRawFile(contents.toByteArray());
                            hasKnownHtsFeeSchedules = schedules.contains("TokenCreate");
                        } catch (Exception e) {
                            var msg = e.toString();
                            msg = msg.substring(msg.indexOf(":") + 2);
                            log.info("Couldn't check for HTS fee schedules---'{}'", msg);
                        }
                        TimeUnit.SECONDS.sleep(3);
                    }
                    log.info("\n\n" + bannerWith("A fee schedule with token ops now available!"));
                    spec.tryReinitializingFees();
                }));
            }
            for (int i = 0; i < tokensPerTxn.get(); i++) {
                var token = "token" + i;
                var treasury = "treasury" + i;
                initializers.add(cryptoCreate(treasury));
                initializers.add(tokenCreate(token).treasury(treasury).initialSupply(initialSupply));
                treasuries.add(treasury);
                for (int j = 0; j < sendingAccountsPerToken.get(); j++) {
                    var sender = token + "sender" + j;
                    senders.computeIfAbsent(token, ignore -> new ArrayList<>()).add(sender);
                    initializers.add(cryptoCreate(sender));
                    initializers.add(tokenAssociate(sender, token));
                    initializers.add(cryptoTransfer(moving(balanceInit.get(), token).between(treasury, sender)));
                }
                for (int j = 0; j < receivingAccountsPerToken.get(); j++) {
                    var receiver = token + "receiver" + j;
                    receivers.computeIfAbsent(token, ignore -> new ArrayList<>()).add(receiver);
                    initializers.add(cryptoCreate(receiver));
                    initializers.add(tokenAssociate(receiver, token));
                    initializers.add(cryptoTransfer(moving(balanceInit.get(), token).between(treasury, receiver)));
                }
            }
            for (HapiSpecOperation op : initializers) {
                if (op instanceof HapiTxnOp) {
                    ((HapiTxnOp) op).hasRetryPrecheckFrom(NOISY_RETRY_PRECHECKS);
                }
            }
            return initializers;
        }

        @Override
        public Optional<HapiSpecOperation> get() {
            HapiSpecOperation op;
            var numTokens = tokensPerTxn.get();
            var numSenders = sendingAccountsPerToken.get();
            var numReceivers = receivingAccountsPerToken.get();
            if (firstDir.get()) {
                var xfers = new TokenMovement[numTokens * numSenders];
                for (int i = 0; i < numTokens; i++) {
                    var token = "token" + i;
                    for (int j = 0; j < numSenders; j++) {
                        var receivers = new String[numReceivers];
                        for (int k = 0; k < numReceivers; k++) {
                            receivers[k] = token + "receiver" + k;
                        }
                        xfers[i * numSenders + j] = moving(numReceivers, token).distributing(token + "sender" + j, receivers);
                    }
                }
                op = cryptoTransfer(xfers).hasKnownStatusFrom(OK, DUPLICATE_TRANSACTION, SUCCESS, UNKNOWN, INSUFFICIENT_PAYER_BALANCE).hasRetryPrecheckFrom(NOISY_RETRY_PRECHECKS).hasPrecheckFrom(OK, PLATFORM_NOT_ACTIVE).noLogging().deferStatusResolution();
                firstDir.set(Boolean.FALSE);
            } else {
                var xfers = new TokenMovement[numTokens * numReceivers];
                for (int i = 0; i < numTokens; i++) {
                    var token = "token" + i;
                    for (int j = 0; j < numReceivers; j++) {
                        var senders = new String[numSenders];
                        for (int k = 0; k < numSenders; k++) {
                            senders[k] = token + "sender" + k;
                        }
                        xfers[i * numReceivers + j] = moving(numSenders, token).distributing(token + "receiver" + j, senders);
                    }
                }
                op = cryptoTransfer(xfers).hasKnownStatusFrom(OK, DUPLICATE_TRANSACTION, SUCCESS, UNKNOWN, INSUFFICIENT_PAYER_BALANCE).hasRetryPrecheckFrom(NOISY_RETRY_PRECHECKS).hasPrecheckFrom(OK, PLATFORM_NOT_ACTIVE).noLogging().deferStatusResolution();
                firstDir.set(Boolean.TRUE);
            }
            return Optional.of(op);
        }
    };
}
Also used : TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) INSUFFICIENT_PAYER_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) FeesJsonToGrpcBytes(com.hedera.services.bdd.suites.utils.sysfiles.serdes.FeesJsonToGrpcBytes) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) MINUTES(java.util.concurrent.TimeUnit.MINUTES) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) 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.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) FREEZE_ALREADY_SCHEDULED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FREEZE_ALREADY_SCHEDULED) TokenMovement.moving(com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving) DUPLICATE_TRANSACTION(com.hederahashgraph.api.proto.java.ResponseCodeEnum.DUPLICATE_TRANSACTION) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) HapiPropertySource.asAccount(com.hedera.services.bdd.spec.HapiPropertySource.asAccount) NOISY_RETRY_PRECHECKS(com.hedera.services.bdd.spec.transactions.TxnUtils.NOISY_RETRY_PRECHECKS) UtilVerbs.uploadDefaultFeeSchedules(com.hedera.services.bdd.spec.utilops.UtilVerbs.uploadDefaultFeeSchedules) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) SysFileSerde(com.hedera.services.bdd.suites.utils.sysfiles.serdes.SysFileSerde) PLATFORM_NOT_ACTIVE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PLATFORM_NOT_ACTIVE) UNKNOWN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) QueryVerbs(com.hedera.services.bdd.spec.queries.QueryVerbs) TokenMovement(com.hedera.services.bdd.spec.transactions.token.TokenMovement) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnFactory.bannerWith(com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith) List(java.util.List) Logger(org.apache.logging.log4j.Logger) UtilVerbs.freezeOnly(com.hedera.services.bdd.spec.utilops.UtilVerbs.freezeOnly) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) TokenMovement(com.hedera.services.bdd.spec.transactions.token.TokenMovement) SysFileSerde(com.hedera.services.bdd.suites.utils.sysfiles.serdes.SysFileSerde) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FeesJsonToGrpcBytes(com.hedera.services.bdd.suites.utils.sysfiles.serdes.FeesJsonToGrpcBytes) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with OpProvider

use of com.hedera.services.bdd.spec.infrastructure.OpProvider in project hedera-services by hashgraph.

the class UniqueTokenStateSetup method nftFactory.

private Function<HapiApiSpec, OpProvider> nftFactory() {
    final AtomicInteger uniqueTokensCreated = new AtomicInteger(0);
    final AtomicInteger nftsMintedForCurrentUniqueToken = new AtomicInteger(0);
    final AtomicBoolean done = new AtomicBoolean(false);
    final AtomicReference<String> currentUniqueToken = new AtomicReference<>(uniqueTokenNameFn.apply(0));
    return spec -> new OpProvider() {

        @Override
        public List<HapiSpecOperation> suggestedInitializers() {
            final var numTreasuries = numTokens.get() / UNIQ_TOKENS_PER_TREASURY + Math.min(1, numTokens.get() % UNIQ_TOKENS_PER_TREASURY);
            final List<HapiSpecOperation> inits = new ArrayList<>();
            inits.add(inParallel(IntStream.range(0, numTreasuries).mapToObj(i -> cryptoCreate(treasuryNameFn.apply(i)).payingWith(GENESIS).balance(0L).noLogging().key(GENESIS).hasRetryPrecheckFrom(DUPLICATE_TRANSACTION).hasKnownStatusFrom(SUCCESS, UNKNOWN, TRANSACTION_EXPIRED).deferStatusResolution()).toArray(HapiSpecOperation[]::new)));
            inits.add(sleepFor(5_000L));
            inits.addAll(burstedUniqCreations(UNIQ_TOKENS_BURST_SIZE, numTreasuries, UNIQ_TOKENS_POST_BURST_PAUSE_MS));
            return inits;
        }

        @Override
        public Optional<HapiSpecOperation> get() {
            if (done.get()) {
                return Optional.empty();
            }
            final var currentToken = currentUniqueToken.get();
            if (nftsMintedForCurrentUniqueToken.get() < numNftsPerToken.get()) {
                final List<ByteString> allMeta = new ArrayList<>();
                final int noMoreThan = numNftsPerToken.get() - nftsMintedForCurrentUniqueToken.get();
                for (int i = 0, n = Math.min(noMoreThan, numNftsPerMintOp.get()); i < n; i++) {
                    final var nextSerialNo = nftsMintedForCurrentUniqueToken.incrementAndGet();
                    allMeta.add(metadataFor(currentToken, nextSerialNo));
                }
                final var op = mintToken(currentToken, allMeta).payingWith(GENESIS).rememberingNothing().deferStatusResolution().fee(ONE_HBAR).hasPrecheckFrom(OK, DUPLICATE_TRANSACTION).hasKnownStatusFrom(SUCCESS, UNKNOWN, OK, TRANSACTION_EXPIRED, INVALID_TOKEN_ID).noLogging();
                return Optional.of(op);
            } else {
                nftsMintedForCurrentUniqueToken.set(0);
                final var nextUniqTokenNo = uniqueTokensCreated.incrementAndGet();
                currentUniqueToken.set(uniqueTokenNameFn.apply(nextUniqTokenNo));
                if (nextUniqTokenNo >= numTokens.get()) {
                    System.out.println("Done creating " + nextUniqTokenNo + " unique tokens w/ approximately " + (numNftsPerToken.get() * nextUniqTokenNo) + " NFTs");
                    done.set(true);
                }
                return Optional.empty();
            }
        }
    };
}
Also used : IntStream(java.util.stream.IntStream) 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) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) PerfUtilOps.mgmtOfLongProp(com.hedera.services.bdd.suites.perf.PerfUtilOps.mgmtOfLongProp) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TRANSACTION_EXPIRED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TRANSACTION_EXPIRED) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PerfUtilOps.stdMgmtOf(com.hedera.services.bdd.suites.perf.PerfUtilOps.stdMgmtOf) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) 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) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) IntFunction(java.util.function.IntFunction) UNKNOWN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN) INFINITE(com.hederahashgraph.api.proto.java.TokenSupplyType.INFINITE) INVALID_TOKEN_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_ID) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) ByteString(com.google.protobuf.ByteString) 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) NON_FUNGIBLE_UNIQUE(com.hederahashgraph.api.proto.java.TokenType.NON_FUNGIBLE_UNIQUE) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) PerfUtilOps.mgmtOfIntProp(com.hedera.services.bdd.suites.perf.PerfUtilOps.mgmtOfIntProp) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) ByteString(com.google.protobuf.ByteString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation)

Aggregations

HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)13 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)13 OpProvider (com.hedera.services.bdd.spec.infrastructure.OpProvider)13 Optional (java.util.Optional)13 TimeUnit (java.util.concurrent.TimeUnit)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 Function (java.util.function.Function)13 LogManager (org.apache.logging.log4j.LogManager)13 Logger (org.apache.logging.log4j.Logger)13 UtilVerbs.runWithProvider (com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider)12 List (java.util.List)12 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)9 UtilVerbs.withOpContext (com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext)9 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)9 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)8 TxnVerbs.tokenCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate)8 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)8 ArrayList (java.util.ArrayList)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8