Search in sources :

Example 6 with UNKNOWN

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN 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)

Example 7 with UNKNOWN

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

the class CryptoTransferLoadTest method runCryptoTransfers.

protected HapiApiSpec runCryptoTransfers() {
    PerfTestLoadSettings settings = new PerfTestLoadSettings();
    Supplier<HapiSpecOperation[]> transferBurst = () -> {
        String sender = "sender";
        String receiver = "receiver";
        if (settings.getTotalAccounts() > 2) {
            int s = r.nextInt(settings.getTotalAccounts());
            int re = 0;
            do {
                re = r.nextInt(settings.getTotalAccounts());
            } while (re == s);
            sender = String.format("0.0.%d", TEST_ACCOUNT_STARTS_FROM + s);
            receiver = String.format("0.0.%d", TEST_ACCOUNT_STARTS_FROM + re);
        }
        return new HapiSpecOperation[] { cryptoTransfer(tinyBarsFromTo(sender, receiver, 1L)).noLogging().payingWith(sender).signedBy(GENESIS).suppressStats(true).fee(100_000_000L).hasKnownStatusFrom(SUCCESS, OK, INSUFFICIENT_PAYER_BALANCE, UNKNOWN, TRANSACTION_EXPIRED, INSUFFICIENT_ACCOUNT_BALANCE).hasRetryPrecheckFrom(BUSY, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution() };
    };
    return defaultHapiSpec("RunCryptoTransfers").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when(cryptoCreate("sender").balance(ignore -> settings.getInitialBalance()).payingWith(GENESIS).withRecharging().key(GENESIS).rechargeWindow(3).logging().hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED), cryptoCreate("receiver").payingWith(GENESIS).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).key(GENESIS).logging()).then(defaultLoadTest(transferBurst, settings), getAccountBalance("sender").logged());
}
Also used : INSUFFICIENT_PAYER_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) INSUFFICIENT_ACCOUNT_BALANCE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_ACCOUNT_BALANCE) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) 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) Supplier(java.util.function.Supplier) DUPLICATE_TRANSACTION(com.hederahashgraph.api.proto.java.ResponseCodeEnum.DUPLICATE_TRANSACTION) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) LoadTest(com.hedera.services.bdd.spec.utilops.LoadTest) UNKNOWN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN) UtilVerbs.logIt(com.hedera.services.bdd.spec.utilops.UtilVerbs.logIt) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) 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) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) PLATFORM_TRANSACTION_NOT_CREATED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PLATFORM_TRANSACTION_NOT_CREATED) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings)

Aggregations

HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)7 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)7 UtilVerbs.withOpContext (com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext)7 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)7 UNKNOWN (com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN)7 List (java.util.List)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)6 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)6 DUPLICATE_TRANSACTION (com.hederahashgraph.api.proto.java.ResponseCodeEnum.DUPLICATE_TRANSACTION)6 LoadTest (com.hedera.services.bdd.spec.utilops.LoadTest)5 UtilVerbs.logIt (com.hedera.services.bdd.spec.utilops.UtilVerbs.logIt)5 PerfTestLoadSettings (com.hedera.services.bdd.suites.perf.PerfTestLoadSettings)5 OK (com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Supplier (java.util.function.Supplier)5 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)4 BUSY (com.hederahashgraph.api.proto.java.ResponseCodeEnum.BUSY)4 INSUFFICIENT_PAYER_BALANCE (com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE)4