Search in sources :

Example 1 with SUCCESS

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

the class ContractKeysHTSSuite method callForMintWithDelegateContractKey.

private HapiApiSpec callForMintWithDelegateContractKey() {
    final var theAccount = "anybody";
    final var mintContractByteCode = "mintContractByteCode";
    final var amount = 10L;
    final var fungibleToken = "fungibleToken";
    final var theContract = "mintContract";
    final var firstMintTxn = "firstMintTxn";
    final AtomicLong fungibleNum = new AtomicLong();
    return defaultHapiSpec("callForMintWithDelegateContractKey").given(newKeyNamed(MULTI_KEY), cryptoCreate(theAccount).balance(10 * ONE_HUNDRED_HBARS), cryptoCreate(TOKEN_TREASURY), fileCreate(mintContractByteCode).payingWith(theAccount), updateLargeFile(theAccount, mintContractByteCode, extractByteCode(ContractResources.ORDINARY_CALLS_CONTRACT)), tokenCreate(fungibleToken).tokenType(FUNGIBLE_COMMON).initialSupply(0).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(theContract).bytecode(mintContractByteCode).payingWith(theAccount).gas(GAS_TO_OFFER))).then(withOpContext((spec, opLog) -> allRunFor(spec, newKeyNamed("delegateContractKey").shape(DELEGATE_CONTRACT_KEY_SHAPE.signedWith(sigs(ON, theContract))), tokenUpdate(fungibleToken).supplyKey("delegateContractKey"), contractCall(theContract, MINT_TOKEN_ORDINARY_CALL, asAddress(spec.registry().getTokenID(fungibleToken)), amount, new byte[] {}).via(firstMintTxn).payingWith(theAccount))), childRecordsCheck(firstMintTxn, SUCCESS, recordWith().status(SUCCESS).tokenTransfers(changingFungibleBalances().including(fungibleToken, TOKEN_TREASURY, 10)).newTotalSupply(10)), getTokenInfo(fungibleToken).hasTotalSupply(amount), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(fungibleToken, amount));
}
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) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES) ON(com.hedera.services.bdd.spec.keys.SigControl.ON) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) BURN_TOKEN_ORDINARY_CALL(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.BURN_TOKEN_ORDINARY_CALL) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) ACCOUNT_IS_TREASURY(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_IS_TREASURY) DELEGATE_BURN_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DELEGATE_BURN_CALL_ABI) ExpectedTokenRel.relationshipWith(com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) STATIC_ASSOCIATE_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.STATIC_ASSOCIATE_CALL_ABI) Frozen(com.hederahashgraph.api.proto.java.TokenFreezeStatus.Frozen) SomeFungibleTransfers.changingFungibleBalances(com.hedera.services.bdd.spec.assertions.SomeFungibleTransfers.changingFungibleBalances) DELEGATE_ASSOCIATE_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DELEGATE_ASSOCIATE_CALL_ABI) ACCOUNT_STILL_OWNS_NFTS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_STILL_OWNS_NFTS) STATIC_DISSOCIATE_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.STATIC_DISSOCIATE_CALL_ABI) STATIC_MINT_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.STATIC_MINT_CALL_ABI) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) TOKEN_NOT_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT) TRANSFER_NFT_ORDINARY_CALL(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.TRANSFER_NFT_ORDINARY_CALL) Utils.extractByteCode(com.hedera.services.bdd.suites.contract.Utils.extractByteCode) NonFungibleTransfers(com.hedera.services.bdd.spec.assertions.NonFungibleTransfers) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TxnVerbs.tokenUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUpdate) NotNull(org.jetbrains.annotations.NotNull) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) STATIC_TRANSFER_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.STATIC_TRANSFER_CALL_ABI) KeyShape.sigs(com.hedera.services.bdd.spec.keys.KeyShape.sigs) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) MiscEETUtils.metadata(com.hedera.services.bdd.suites.utils.MiscEETUtils.metadata) ByteString.copyFromUtf8(com.google.protobuf.ByteString.copyFromUtf8) DELEGATE_MINT_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DELEGATE_MINT_CALL_ABI) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) QueryVerbs.getTokenInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenInfo) Revoked(com.hederahashgraph.api.proto.java.TokenKycStatus.Revoked) HapiPropertySource.asToken(com.hedera.services.bdd.spec.HapiPropertySource.asToken) SINGLE_TOKEN_ASSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SINGLE_TOKEN_ASSOCIATE) AtomicReference(java.util.concurrent.atomic.AtomicReference) DELEGATE_CONTRACT(com.hedera.services.bdd.spec.keys.KeyShape.DELEGATE_CONTRACT) INVALID_SIGNATURE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) ArrayList(java.util.ArrayList) UtilVerbs.emptyChildRecordsCheck(com.hedera.services.bdd.spec.utilops.UtilVerbs.emptyChildRecordsCheck) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) 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) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) AccountID(com.hederahashgraph.api.proto.java.AccountID) MINT_TOKEN_ORDINARY_CALL(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_TOKEN_ORDINARY_CALL) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) ACCOUNT_FROZEN_FOR_TOKEN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_FROZEN_FOR_TOKEN) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) DELEGATE_DISSOCIATE_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DELEGATE_DISSOCIATE_CALL_ABI) 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) BURN_TOKEN_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.BURN_TOKEN_ABI) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) TokenType(com.hederahashgraph.api.proto.java.TokenType) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) TokenID(com.hederahashgraph.api.proto.java.TokenID) STATIC_BURN_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.STATIC_BURN_CALL_ABI) Utils.asAddress(com.hedera.services.bdd.suites.contract.Utils.asAddress) CONTRACT_REVERT_EXECUTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED) NON_FUNGIBLE_UNIQUE(com.hederahashgraph.api.proto.java.TokenType.NON_FUNGIBLE_UNIQUE) 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) DELEGATE_TRANSFER_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DELEGATE_TRANSFER_CALL_ABI) TokenMovement.movingUnique(com.hedera.services.bdd.spec.transactions.token.TokenMovement.movingUnique) TokenSupplyType(com.hederahashgraph.api.proto.java.TokenSupplyType) TxnVerbs.tokenUnfreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnfreeze) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 2 with SUCCESS

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

the class ContractKeysHTSSuite method burnTokenWithFullPrefixAndPartialPrefixKeys.

private HapiApiSpec burnTokenWithFullPrefixAndPartialPrefixKeys() {
    final var theAccount = "anybody";
    final var burnContractByteCode = "burnContractByteCode";
    final var amount = 99L;
    final var fungibleToken = "fungibleToken";
    final var theContract = "mintContract";
    final var firstBurnTxn = "firstBurnTxn";
    final var secondBurnTxn = "secondBurnTxn";
    final AtomicLong fungibleNum = new AtomicLong();
    return defaultHapiSpec("burnTokenWithFullPrefixAndPartialPrefixKeys").given(newKeyNamed(MULTI_KEY), cryptoCreate(theAccount).balance(10 * ONE_HUNDRED_HBARS), cryptoCreate(TOKEN_TREASURY), fileCreate(burnContractByteCode).payingWith(theAccount), updateLargeFile(theAccount, burnContractByteCode, extractByteCode(ContractResources.ORDINARY_CALLS_CONTRACT)), tokenCreate(fungibleToken).tokenType(TokenType.FUNGIBLE_COMMON).initialSupply(100).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(theContract).bytecode(burnContractByteCode).payingWith(theAccount).gas(GAS_TO_OFFER))).then(withOpContext((spec, opLog) -> allRunFor(spec, contractCall(theContract, BURN_TOKEN_ORDINARY_CALL, asAddress(spec.registry().getTokenID(fungibleToken)), 1, new ArrayList<Long>()).via(firstBurnTxn).payingWith(theAccount).signedBy(MULTI_KEY).signedBy(theAccount).hasKnownStatus(SUCCESS), contractCall(theContract, BURN_TOKEN_ORDINARY_CALL, asAddress(spec.registry().getTokenID(fungibleToken)), 1, new ArrayList<Long>()).via(secondBurnTxn).payingWith(theAccount).alsoSigningWithFullPrefix(MULTI_KEY).hasKnownStatus(SUCCESS))), childRecordsCheck(firstBurnTxn, SUCCESS, recordWith().status(INVALID_SIGNATURE)), childRecordsCheck(secondBurnTxn, SUCCESS, recordWith().status(SUCCESS).newTotalSupply(99)), getTokenInfo(fungibleToken).hasTotalSupply(amount), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(fungibleToken, amount));
}
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) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES) ON(com.hedera.services.bdd.spec.keys.SigControl.ON) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) BURN_TOKEN_ORDINARY_CALL(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.BURN_TOKEN_ORDINARY_CALL) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) ACCOUNT_IS_TREASURY(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_IS_TREASURY) DELEGATE_BURN_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DELEGATE_BURN_CALL_ABI) ExpectedTokenRel.relationshipWith(com.hedera.services.bdd.spec.queries.crypto.ExpectedTokenRel.relationshipWith) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) STATIC_ASSOCIATE_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.STATIC_ASSOCIATE_CALL_ABI) Frozen(com.hederahashgraph.api.proto.java.TokenFreezeStatus.Frozen) SomeFungibleTransfers.changingFungibleBalances(com.hedera.services.bdd.spec.assertions.SomeFungibleTransfers.changingFungibleBalances) DELEGATE_ASSOCIATE_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DELEGATE_ASSOCIATE_CALL_ABI) ACCOUNT_STILL_OWNS_NFTS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_STILL_OWNS_NFTS) STATIC_DISSOCIATE_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.STATIC_DISSOCIATE_CALL_ABI) STATIC_MINT_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.STATIC_MINT_CALL_ABI) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_ALREADY_ASSOCIATED_TO_ACCOUNT) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) TOKEN_NOT_ASSOCIATED_TO_ACCOUNT(com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT) TRANSFER_NFT_ORDINARY_CALL(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.TRANSFER_NFT_ORDINARY_CALL) Utils.extractByteCode(com.hedera.services.bdd.suites.contract.Utils.extractByteCode) NonFungibleTransfers(com.hedera.services.bdd.spec.assertions.NonFungibleTransfers) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TxnVerbs.tokenUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUpdate) NotNull(org.jetbrains.annotations.NotNull) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) STATIC_TRANSFER_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.STATIC_TRANSFER_CALL_ABI) KeyShape.sigs(com.hedera.services.bdd.spec.keys.KeyShape.sigs) TxnVerbs.tokenAssociate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenAssociate) MiscEETUtils.metadata(com.hedera.services.bdd.suites.utils.MiscEETUtils.metadata) ByteString.copyFromUtf8(com.google.protobuf.ByteString.copyFromUtf8) DELEGATE_MINT_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DELEGATE_MINT_CALL_ABI) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) QueryVerbs.getTokenInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getTokenInfo) Revoked(com.hederahashgraph.api.proto.java.TokenKycStatus.Revoked) HapiPropertySource.asToken(com.hedera.services.bdd.spec.HapiPropertySource.asToken) SINGLE_TOKEN_ASSOCIATE(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.SINGLE_TOKEN_ASSOCIATE) AtomicReference(java.util.concurrent.atomic.AtomicReference) DELEGATE_CONTRACT(com.hedera.services.bdd.spec.keys.KeyShape.DELEGATE_CONTRACT) INVALID_SIGNATURE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) ArrayList(java.util.ArrayList) UtilVerbs.emptyChildRecordsCheck(com.hedera.services.bdd.spec.utilops.UtilVerbs.emptyChildRecordsCheck) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) 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) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) AccountID(com.hederahashgraph.api.proto.java.AccountID) MINT_TOKEN_ORDINARY_CALL(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.MINT_TOKEN_ORDINARY_CALL) TxnVerbs.mintToken(com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken) TxnVerbs.tokenCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenCreate) ACCOUNT_FROZEN_FOR_TOKEN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.ACCOUNT_FROZEN_FOR_TOKEN) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) DELEGATE_DISSOCIATE_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DELEGATE_DISSOCIATE_CALL_ABI) 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) BURN_TOKEN_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.BURN_TOKEN_ABI) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) TokenType(com.hederahashgraph.api.proto.java.TokenType) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) TokenID(com.hederahashgraph.api.proto.java.TokenID) STATIC_BURN_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.STATIC_BURN_CALL_ABI) Utils.asAddress(com.hedera.services.bdd.suites.contract.Utils.asAddress) CONTRACT_REVERT_EXECUTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED) NON_FUNGIBLE_UNIQUE(com.hederahashgraph.api.proto.java.TokenType.NON_FUNGIBLE_UNIQUE) 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) DELEGATE_TRANSFER_CALL_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.DELEGATE_TRANSFER_CALL_ABI) TokenMovement.movingUnique(com.hedera.services.bdd.spec.transactions.token.TokenMovement.movingUnique) TokenSupplyType(com.hederahashgraph.api.proto.java.TokenSupplyType) TxnVerbs.tokenUnfreeze(com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnfreeze) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList)

Example 3 with SUCCESS

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

the class FibonacciPlusLoadProvider method contractOpsFactory.

private Function<HapiApiSpec, OpProvider> contractOpsFactory() {
    final String civilian = "civilian";
    final String bytecode = "bytecode";
    final SplittableRandom random = new SplittableRandom(1_234_567L);
    final IntFunction<String> contractNameFn = i -> "contract" + i;
    final int r = powerLawBaseReciprocal.get();
    final DoubleUnaryOperator logBaseReciprocal = x -> Math.log(x) / Math.log(r);
    final int numDiscreteSizes = (int) ceil(logBaseReciprocal.applyAsDouble(numContracts.get() * (r - 1)));
    double scale = powerLawScale.get();
    int numSlots = (int) Math.pow(scale, numDiscreteSizes - 1) * smallestNumSlots.get();
    int numContractsWithThisManySlots = 1;
    int nextContractNum = 0;
    for (int i = 0; i < numDiscreteSizes; i++) {
        log.info("Will use {} contracts with {} slots", numContractsWithThisManySlots, numSlots);
        for (int j = 0; j < numContractsWithThisManySlots; j++) {
            final var thisContractNum = nextContractNum++;
            final var thisContract = contractNameFn.apply(thisContractNum);
            contractSlots.put(thisContract, numSlots);
            if (validateStorage.get()) {
                final var slots = new BigInteger[numSlots];
                Arrays.fill(slots, BigInteger.ZERO);
                contractStorage.put(thisContract, slots);
            }
        }
        numSlots /= scale;
        numContractsWithThisManySlots *= r;
    }
    log.info("Will use {} contracts in total", nextContractNum);
    numContracts.set(nextContractNum);
    Supplier<String> randomCallChoice = () -> {
        final var iter = createdSoFar.iterator();
        final var n = createdSoFar.size();
        if (n == 1) {
            return iter.next();
        }
        for (int i = 0; i < random.nextInt(n - 1); i++, iter.next()) {
        /* No-op */
        }
        return iter.next();
    };
    final var that = this;
    return spec -> new OpProvider() {

        @Override
        public List<HapiSpecOperation> suggestedInitializers() {
            final List<HapiSpecOperation> inits = new ArrayList<>();
            inits.add(fileCreate(bytecode).path(FIBONACCI_PLUS_PATH).noLogging().payingWith(GENESIS));
            inits.add(cryptoCreate(civilian).balance(100 * ONE_MILLION_HBARS).payingWith(GENESIS));
            return inits;
        }

        @Override
        public Optional<HapiSpecOperation> get() {
            final var aCallNum = submittedOps.incrementAndGet();
            if (aCallNum == 1) {
                effStart.set(Instant.now());
            }
            final var choice = (createdSoFar.isEmpty() || random.nextDouble() > MIN_CALL_PROB) ? contractNameFn.apply(random.nextInt(numContracts.get())) : randomCallChoice.get();
            final HapiSpecOperation op;
            if (createdSoFar.contains(choice)) {
                final var n = slotsPerCall.get();
                final int[] targets = new int[n];
                final var m = contractSlots.get(choice);
                for (int i = 0; i < n; i++) {
                    targets[i] = random.nextInt(m);
                }
                final var targetsDesc = Arrays.toString(targets);
                if (verbose.get()) {
                    log.info("Calling {} with targets {} and fibN {}", choice, targetsDesc, fibN.get());
                }
                op = contractCall(choice, ADD_NTH_FIB_ABI, targets, fibN.get()).noLogging().payingWith(civilian).gas(GAS_TO_OFFER).exposingGasTo((code, gas) -> {
                    if (verbose.get()) {
                        log.info("(Tried to) call {} (targets = {}, fibN = {}) with {} gas --> {}", choice, targetsDesc, fibN.get(), gas, code);
                    }
                    that.observeExposedGas(gas);
                    if (code == SUCCESS && validateStorage.get()) {
                        final var curSlots = contractStorage.get(choice);
                        final var newSlots = Arrays.copyOf(curSlots, m);
                        for (int i = 0; i < n; i++) {
                            final var j = targets[i];
                            newSlots[j] = newSlots[j].add(fibNValue.get());
                        }
                        contractStorage.put(choice, newSlots);
                    }
                }).hasKnownStatusFrom(SUCCESS, CONTRACT_REVERT_EXECUTED, INSUFFICIENT_GAS).deferStatusResolution();
            } else {
                final var numSlots = contractSlots.get(choice);
                op = contractCreate(choice, FIBONACCI_PLUS_CONSTRUCTOR_ABI, numSlots).bytecode(bytecode).payingWith(civilian).balance(0L).gas(GAS_TO_OFFER).exposingGasTo((code, gas) -> {
                    if (code == SUCCESS) {
                        createdSoFar.add(choice);
                    }
                    log.info("(Tried to) create {} ({} slots) with {} gas --> {}", choice, numSlots, gas, code);
                    that.observeExposedGas(gas);
                }).noLogging().hasKnownStatusFrom(SUCCESS, INSUFFICIENT_GAS).deferStatusResolution();
            }
            return Optional.of(op);
        }
    };
}
Also used : UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) Arrays(java.util.Arrays) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) QueryVerbs.getExecTime(com.hedera.services.bdd.spec.queries.QueryVerbs.getExecTime) PerfUtilOps.stdMgmtOf(com.hedera.services.bdd.suites.perf.PerfUtilOps.stdMgmtOf) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) FIBONACCI_PLUS_CONSTRUCTOR_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_CONSTRUCTOR_ABI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) SplittableRandom(java.util.SplittableRandom) QueryVerbs.contractCallLocal(com.hedera.services.bdd.spec.queries.QueryVerbs.contractCallLocal) BigInteger(java.math.BigInteger) ContractFnResultAsserts.isLiteralArrayResult(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.isLiteralArrayResult) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ContractFnResultAsserts.resultWith(com.hedera.services.bdd.spec.assertions.ContractFnResultAsserts.resultWith) Set(java.util.Set) Math.ceil(java.lang.Math.ceil) Instant(java.time.Instant) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) UtilVerbs.noOp(com.hedera.services.bdd.spec.utilops.UtilVerbs.noOp) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) PerfUtilOps.mgmtOfIntProp(com.hedera.services.bdd.suites.perf.PerfUtilOps.mgmtOfIntProp) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) ArrayList(java.util.ArrayList) PerfUtilOps.mgmtOfBooleanProp(com.hedera.services.bdd.suites.perf.PerfUtilOps.mgmtOfBooleanProp) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) CURRENT_FIB_SLOTS_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.CURRENT_FIB_SLOTS_ABI) IntFunction(java.util.function.IntFunction) FIBONACCI_PLUS_PATH(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.FIBONACCI_PLUS_PATH) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) INSUFFICIENT_GAS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_GAS) CONTRACT_REVERT_EXECUTED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.CONTRACT_REVERT_EXECUTED) ADD_NTH_FIB_ABI(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources.ADD_NTH_FIB_ABI) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) LogManager(org.apache.logging.log4j.LogManager) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ArrayList(java.util.ArrayList) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) BigInteger(java.math.BigInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) SplittableRandom(java.util.SplittableRandom) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator)

Example 4 with SUCCESS

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

the class SStoreOperationLoadTest method runContractCalls.

private HapiApiSpec runContractCalls() {
    PerfTestLoadSettings settings = new PerfTestLoadSettings();
    final AtomicInteger submittedSoFar = new AtomicInteger(0);
    long setValue = 0x1234abdeL;
    Supplier<HapiSpecOperation[]> callBurst = () -> new HapiSpecOperation[] { contractCall("perf", ContractResources.BIG_ARRAY_CHANGE_ARRAY_ABI, setValue).noLogging().payingWith("sender").suppressStats(true).hasKnownStatusFrom(UNKNOWN, SUCCESS).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution() };
    return defaultHapiSpec("runContractCalls").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when(cryptoCreate("sender").balance(initialBalance.getAsLong()).withRecharging().rechargeWindow(3).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED), fileCreate("contractBytecode").path(ContractResources.BIG_ARRAY_BYTECODE_PATH).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED), contractCreate("perf").bytecode("contractBytecode").hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED), getContractInfo("perf").hasExpectedInfo().logged(), // Initialize storage size
    contractCall("perf", ContractResources.BIG_ARRAY_SET_SIZE_ABI, size).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).gas(300_000)).then(defaultLoadTest(callBurst, settings));
}
Also used : LoadTest(com.hedera.services.bdd.spec.utilops.LoadTest) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) UNKNOWN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN) UtilVerbs.logIt(com.hedera.services.bdd.spec.utilops.UtilVerbs.logIt) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Supplier(java.util.function.Supplier) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) QueryVerbs.getContractInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) DUPLICATE_TRANSACTION(com.hederahashgraph.api.proto.java.ResponseCodeEnum.DUPLICATE_TRANSACTION) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation)

Example 5 with SUCCESS

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

the class CryptoTransferLoadTestWithAutoAccounts method runCryptoTransfers.

protected HapiApiSpec runCryptoTransfers() {
    PerfTestLoadSettings settings = new PerfTestLoadSettings();
    Supplier<HapiSpecOperation[]> transferBurst = () -> {
        String sender = "sender";
        String receiver;
        if (r.nextInt(10) < 5) {
            receiver = "alias" + r.nextInt(AUTO_ACCOUNTS);
        } else {
            receiver = "receiver";
        }
        if (receiver.startsWith("alias")) {
            return new HapiSpecOperation[] { cryptoTransfer(tinyBarsFromToWithAlias(sender, receiver, 1L)).logging().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 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("RunCryptoTransfersWithAutoAccounts").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(), withOpContext((spec, opLog) -> {
        List<HapiSpecOperation> ops = new ArrayList<>();
        for (int i = 0; i < AUTO_ACCOUNTS; i++) {
            var alias = "alias" + i;
            ops.add(newKeyNamed(alias));
            ops.add(cryptoTransfer(tinyBarsFromToWithAlias(DEFAULT_PAYER, alias, ONE_HBAR)));
        }
        allRunFor(spec, ops);
    })).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) HapiCryptoTransfer.tinyBarsFromToWithAlias(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromToWithAlias) 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) ArrayList(java.util.ArrayList) 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) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) 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) 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) ArrayList(java.util.ArrayList) 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