Search in sources :

Example 36 with HapiApiSpec

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

the class HapiTokenUnpause method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(final HapiApiSpec spec) throws Throwable {
    var tId = TxnUtils.asTokenId(token, spec);
    TokenUnpauseTransactionBody opBody = spec.txns().<TokenUnpauseTransactionBody, TokenUnpauseTransactionBody.Builder>body(TokenUnpauseTransactionBody.class, b -> {
        b.setToken(tId);
    });
    return b -> b.setTokenUnpause(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) TokenOpsUsage(com.hedera.services.usage.token.TokenOpsUsage) TOKEN_OPS_USAGE_UTILS(com.hedera.services.usage.token.TokenOpsUsageUtils.TOKEN_OPS_USAGE_UTILS) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) TokenUnpauseTransactionBody(com.hederahashgraph.api.proto.java.TokenUnpauseTransactionBody) Function(java.util.function.Function) Consumer(java.util.function.Consumer) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AdapterUtils(com.hedera.services.bdd.spec.fees.AdapterUtils) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) TokenUnpauseTransactionBody(com.hederahashgraph.api.proto.java.TokenUnpauseTransactionBody)

Example 37 with HapiApiSpec

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

the class HapiTokenUpdate method feeFor.

@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
    try {
        final TokenInfo info = HapiTokenFeeScheduleUpdate.lookupInfo(spec, token, log, loggingOff);
        FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> {
            var estimate = TokenUpdateUsage.newEstimate(_txn, suFrom(svo));
            estimate.givenCurrentExpiry(info.getExpiry().getSeconds()).givenCurrentMemo(info.getMemo()).givenCurrentName(info.getName()).givenCurrentSymbol(info.getSymbol());
            if (info.hasFreezeKey()) {
                estimate.givenCurrentFreezeKey(Optional.of(info.getFreezeKey()));
            }
            if (info.hasAdminKey()) {
                estimate.givenCurrentAdminKey(Optional.of(info.getAdminKey()));
            }
            if (info.hasSupplyKey()) {
                estimate.givenCurrentSupplyKey(Optional.of(info.getSupplyKey()));
            }
            if (info.hasKycKey()) {
                estimate.givenCurrentKycKey(Optional.of(info.getKycKey()));
            }
            if (info.hasWipeKey()) {
                estimate.givenCurrentWipeKey(Optional.of(info.getWipeKey()));
            }
            if (info.hasFeeScheduleKey()) {
                estimate.givenCurrentFeeScheduleKey(Optional.of(info.getFeeScheduleKey()));
            }
            if (info.hasPauseKey()) {
                estimate.givenCurrentPauseKey(Optional.of(info.getPauseKey()));
            }
            if (info.hasAutoRenewAccount()) {
                estimate.givenCurrentlyUsingAutoRenewAccount();
            }
            return estimate.get();
        };
        return spec.fees().forActivityBasedOp(HederaFunctionality.TokenUpdate, metricsCalc, txn, numPayerKeys);
    } catch (Throwable t) {
        log.warn("Couldn't estimate usage", t);
        return HapiApiSuite.ONE_HBAR;
    }
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TokenInfo(com.hederahashgraph.api.proto.java.TokenInfo) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) TokenUpdateUsage(com.hedera.services.usage.token.TokenUpdateUsage) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) TokenInfo(com.hederahashgraph.api.proto.java.TokenInfo)

Example 38 with HapiApiSpec

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

the class HapiTokenUpdate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    var id = TxnUtils.asTokenId(token, spec);
    if (newSymbolFn.isPresent()) {
        newSymbol = Optional.of(newSymbolFn.get().apply(spec));
    }
    if (newNameFn.isPresent()) {
        newName = Optional.of(newNameFn.get().apply(spec));
    }
    TokenUpdateTransactionBody opBody = spec.txns().<TokenUpdateTransactionBody, TokenUpdateTransactionBody.Builder>body(TokenUpdateTransactionBody.class, b -> {
        b.setToken(id);
        newSymbol.ifPresent(b::setSymbol);
        newName.ifPresent(b::setName);
        newMemo.ifPresent(s -> b.setMemo(StringValue.newBuilder().setValue(s).build()));
        if (useImproperEmptyKey) {
            b.setAdminKey(TxnUtils.EMPTY_THRESHOLD_KEY);
        } else if (useEmptyAdminKeyList) {
            b.setAdminKey(TxnUtils.EMPTY_KEY_LIST);
        } else {
            newAdminKey.ifPresent(a -> b.setAdminKey(spec.registry().getKey(a)));
        }
        newTreasury.ifPresent(a -> b.setTreasury(spec.registry().getAccountID(a)));
        newSupplyKey.ifPresent(k -> b.setSupplyKey(spec.registry().getKey(k)));
        newSupplyKeySupplier.ifPresent(s -> b.setSupplyKey(s.get()));
        newWipeKey.ifPresent(k -> b.setWipeKey(spec.registry().getKey(k)));
        newKycKey.ifPresent(k -> b.setKycKey(spec.registry().getKey(k)));
        if (useInvalidFeeScheduleKey) {
            b.setFeeScheduleKey(TxnUtils.EMPTY_THRESHOLD_KEY);
        } else {
            newFeeScheduleKey.ifPresent(k -> b.setFeeScheduleKey(spec.registry().getKey(k)));
        }
        newFreezeKey.ifPresent(k -> b.setFreezeKey(spec.registry().getKey(k)));
        newPauseKey.ifPresent(k -> b.setPauseKey(spec.registry().getKey(k)));
        if (autoRenewAccount.isPresent()) {
            var autoRenewId = TxnUtils.asId(autoRenewAccount.get(), spec);
            b.setAutoRenewAccount(autoRenewId);
        }
        expiry.ifPresent(t -> b.setExpiry(Timestamp.newBuilder().setSeconds(t).build()));
        autoRenewPeriod.ifPresent(secs -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(secs).build()));
    });
    return b -> b.setTokenUpdate(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TokenInfo(com.hederahashgraph.api.proto.java.TokenInfo) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) TokenUpdateUsage(com.hedera.services.usage.token.TokenUpdateUsage) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody)

Example 39 with HapiApiSpec

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

the class HapiSysDelete method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (file.isPresent() && contract.isPresent()) {
        Assertions.fail("Ambiguous SystemDelete---both file and contract present!");
    }
    SystemDeleteTransactionBody opBody = spec.txns().<SystemDeleteTransactionBody, SystemDeleteTransactionBody.Builder>body(SystemDeleteTransactionBody.class, b -> {
        newExpiry.ifPresent(l -> b.setExpirationTime(TimestampSeconds.newBuilder().setSeconds(l)));
        file.ifPresent(n -> b.setFileID(asFileId(n, spec)));
        contract.ifPresent(n -> b.setContractID(asContractId(n, spec)));
    });
    return b -> b.setSystemDelete(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) SystemDeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemDeleteTransactionBody) TxnUtils.asFileId(com.hedera.services.bdd.spec.transactions.TxnUtils.asFileId) SystemDelete(com.hederahashgraph.api.proto.java.HederaFunctionality.SystemDelete) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) MoreObjects(com.google.common.base.MoreObjects) Function(java.util.function.Function) Consumer(java.util.function.Consumer) OptionalLong(java.util.OptionalLong) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) TimestampSeconds(com.hederahashgraph.api.proto.java.TimestampSeconds) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TxnUtils.asContractId(com.hedera.services.bdd.spec.transactions.TxnUtils.asContractId) SystemDeleteTransactionBody(com.hederahashgraph.api.proto.java.SystemDeleteTransactionBody)

Example 40 with HapiApiSpec

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

the class HapiTokenAssociate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    var aId = TxnUtils.asId(account, spec);
    TokenAssociateTransactionBody opBody = spec.txns().<TokenAssociateTransactionBody, TokenAssociateTransactionBody.Builder>body(TokenAssociateTransactionBody.class, b -> {
        b.setAccount(aId);
        b.addAllTokens(tokens.stream().map(lit -> TxnUtils.asTokenId(lit, spec)).collect(toList()));
    });
    return b -> b.setTokenAssociate(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) TokenAssociateTransactionBody(com.hederahashgraph.api.proto.java.TokenAssociateTransactionBody) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) Function(java.util.function.Function) ArrayList(java.util.ArrayList) QueryVerbs.getContractInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) MoreObjects(com.google.common.base.MoreObjects) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) HapiGetAccountInfo(com.hedera.services.bdd.spec.queries.crypto.HapiGetAccountInfo) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Logger(org.apache.logging.log4j.Logger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiGetContractInfo(com.hedera.services.bdd.spec.queries.contract.HapiGetContractInfo) TokenAssociateUsage(com.hedera.services.usage.token.TokenAssociateUsage) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) TokenAssociateTransactionBody(com.hederahashgraph.api.proto.java.TokenAssociateTransactionBody)

Aggregations

HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)140 List (java.util.List)134 LogManager (org.apache.logging.log4j.LogManager)125 Logger (org.apache.logging.log4j.Logger)125 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)84 UtilVerbs.withOpContext (com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext)78 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)76 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)69 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)65 Function (java.util.function.Function)63 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)58 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)56 ByteString (com.google.protobuf.ByteString)53 Key (com.hederahashgraph.api.proto.java.Key)52 CustomSpecAssert.allRunFor (com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor)51 Optional (java.util.Optional)50 UtilVerbs.newKeyNamed (com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed)49 Consumer (java.util.function.Consumer)49 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)47 TxnVerbs.fileCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate)46