Search in sources :

Example 76 with HapiApiSpec

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

the class HapiCryptoCreate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    key = key != null ? key : netOf(spec, keyName, keyShape, keyType, Optional.of(this::effectiveKeyGen));
    long amount = balanceFn.map(fn -> fn.apply(spec)).orElse(initialBalance.orElse(-1L));
    initialBalance = (amount >= 0) ? Optional.of(amount) : Optional.empty();
    CryptoCreateTransactionBody opBody = spec.txns().<CryptoCreateTransactionBody, CryptoCreateTransactionBody.Builder>body(CryptoCreateTransactionBody.class, b -> {
        b.setKey(key);
        proxy.ifPresent(b::setProxyAccountID);
        entityMemo.ifPresent(b::setMemo);
        sendThresh.ifPresent(b::setSendRecordThreshold);
        receiveThresh.ifPresent(b::setReceiveRecordThreshold);
        initialBalance.ifPresent(b::setInitialBalance);
        receiverSigRequired.ifPresent(b::setReceiverSigRequired);
        autoRenewDurationSecs.ifPresent(s -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(s).build()));
        maxAutomaticTokenAssociations.ifPresent(b::setMaxAutomaticTokenAssociations);
    });
    return b -> b.setCryptoCreateAccount(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) Arrays(java.util.Arrays) SigControl(com.hedera.services.bdd.spec.keys.SigControl) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) CryptoCreateMeta(com.hedera.services.usage.crypto.CryptoCreateMeta) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TxnUtils.netOf(com.hedera.services.bdd.spec.transactions.TxnUtils.netOf) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) TxnFactory.bannerWith(com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith) 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) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) KeyType(com.hedera.services.bdd.spec.keys.KeyFactory.KeyType) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)

Example 77 with HapiApiSpec

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

the class HapiCryptoDelete method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    AccountID target;
    if (referenceType == ReferenceType.REGISTRY_NAME) {
        target = TxnUtils.asId(account, spec);
    } else {
        account = lookUpAccountWithAlias(spec, aliasKeySource);
        target = asAccount(account);
    }
    CryptoDeleteTransactionBody opBody = spec.txns().<CryptoDeleteTransactionBody, CryptoDeleteTransactionBody.Builder>body(CryptoDeleteTransactionBody.class, b -> {
        transferAccount.ifPresent(a -> b.setTransferAccountID(spec.registry().getAccountID(a)));
        b.setDeleteAccountID(target);
    });
    return b -> b.setCryptoDelete(opBody);
}
Also used : CryptoDeleteTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) ReferenceType(com.hedera.services.bdd.spec.queries.crypto.ReferenceType) AccountID(com.hederahashgraph.api.proto.java.AccountID) LogManager(org.apache.logging.log4j.LogManager) HapiPropertySource.asAccount(com.hedera.services.bdd.spec.HapiPropertySource.asAccount) QueryUtils.lookUpAccountWithAlias(com.hedera.services.bdd.spec.queries.QueryUtils.lookUpAccountWithAlias) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoDeleteTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteTransactionBody)

Example 78 with HapiApiSpec

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

the class HapiCryptoUpdate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    try {
        updKey = updKeyName.map(spec.registry()::getKey);
    } catch (Exception ignore) {
    }
    AccountID id;
    if (referenceType == ReferenceType.REGISTRY_NAME) {
        id = TxnUtils.asId(account, spec);
    } else {
        id = asIdForKeyLookUp(aliasKeySource, spec);
        account = asAccountString(id);
    }
    CryptoUpdateTransactionBody opBody = spec.txns().<CryptoUpdateTransactionBody, CryptoUpdateTransactionBody.Builder>body(CryptoUpdateTransactionBody.class, builder -> {
        builder.setAccountIDToUpdate(id);
        newProxy.ifPresent(p -> {
            var proxyId = TxnUtils.asId(p, spec);
            builder.setProxyAccountID(proxyId);
        });
        updSigRequired.ifPresent(u -> builder.setReceiverSigRequiredWrapper(BoolValue.of(u)));
        if (useContractKey) {
            builder.setKey(Key.newBuilder().setContractID(HapiPropertySource.asContract("0.0.1234")));
        } else {
            updKey.ifPresent(builder::setKey);
        }
        newAutoRenewPeriod.ifPresent(p -> builder.setAutoRenewPeriod(Duration.newBuilder().setSeconds(p)));
        entityMemo.ifPresent(m -> builder.setMemo(StringValue.newBuilder().setValue(m).build()));
        sendThreshold.ifPresent(v -> builder.setSendRecordThresholdWrapper(UInt64Value.newBuilder().setValue(v).build()));
        newExpiry.ifPresent(l -> builder.setExpirationTime(Timestamp.newBuilder().setSeconds(l).build()));
        newMaxAutomaticAssociations.ifPresent(p -> builder.setMaxAutomaticTokenAssociations(Int32Value.of(p)));
    });
    return builder -> builder.setCryptoUpdateAccount(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) BoolValue(com.google.protobuf.BoolValue) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) UInt64Value(com.google.protobuf.UInt64Value) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) TxnUtils.defaultUpdateSigners(com.hedera.services.bdd.spec.transactions.TxnUtils.defaultUpdateSigners) OptionalLong(java.util.OptionalLong) PropertySource.asAccountString(com.hedera.services.bdd.spec.PropertySource.asAccountString) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) CryptoUpdateMeta(com.hedera.services.usage.crypto.CryptoUpdateMeta) ReferenceType(com.hedera.services.bdd.spec.queries.crypto.ReferenceType) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) Int32Value(com.google.protobuf.Int32Value) MoreObjects(com.google.common.base.MoreObjects) HapiPropertySource(com.hedera.services.bdd.spec.HapiPropertySource) ExtantCryptoContext(com.hedera.services.usage.crypto.ExtantCryptoContext) 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) Logger(org.apache.logging.log4j.Logger) TxnUtils.asIdForKeyLookUp(com.hedera.services.bdd.spec.transactions.TxnUtils.asIdForKeyLookUp) AdapterUtils(com.hedera.services.bdd.spec.fees.AdapterUtils) 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) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)

Example 79 with HapiApiSpec

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

the class HapiFileAppend method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (contentsSupplier.isPresent()) {
        contents = Optional.of(contentsSupplier.get().get());
    } else if (path.isPresent()) {
        contents = Optional.of(Files.toByteArray(new File(path.get())));
    }
    var fid = TxnUtils.asFileId(file, spec);
    FileAppendTransactionBody opBody = spec.txns().<FileAppendTransactionBody, FileAppendTransactionBody.Builder>body(FileAppendTransactionBody.class, builder -> {
        builder.setFileID(fid);
        contents.ifPresent(b -> builder.setContents(ByteString.copyFrom(b)));
    });
    preAppendCb.ifPresent(cb -> cb.accept(fid));
    return b -> b.setFileAppend(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) FileAppendMeta(com.hedera.services.usage.file.FileAppendMeta) Function(java.util.function.Function) Supplier(java.util.function.Supplier) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Files(com.google.common.io.Files) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) File(java.io.File) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) TxnUtils.currExpiry(com.hedera.services.bdd.spec.transactions.TxnUtils.currExpiry) AdapterUtils(com.hedera.services.bdd.spec.fees.AdapterUtils) 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) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) File(java.io.File)

Example 80 with HapiApiSpec

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

the class HapiFileCreate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (!immutable) {
        generateWaclKey(spec);
    }
    if (contentsPathFn.isPresent()) {
        var loc = contentsPathFn.get().apply(spec);
        contents = Optional.of(Files.toByteArray(new File(loc)));
    }
    FileCreateTransactionBody opBody = spec.txns().<FileCreateTransactionBody, FileCreateTransactionBody.Builder>body(FileCreateTransactionBody.class, builder -> {
        if (!immutable) {
            builder.setKeys(waclKey.getKeyList());
        }
        memo.ifPresent(builder::setMemo);
        contents.ifPresent(b -> builder.setContents(ByteString.copyFrom(b)));
        lifetime.ifPresent(s -> builder.setExpirationTime(TxnFactory.expiryGiven(s)));
        expiry.ifPresent(t -> builder.setExpirationTime(Timestamp.newBuilder().setSeconds(t).build()));
    });
    return b -> {
        expiryUsed.set(opBody.getExpirationTime());
        b.setFileCreate(opBody);
    };
}
Also used : FileCreateTransactionBody(com.hederahashgraph.api.proto.java.FileCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) Arrays(java.util.Arrays) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SigControl(com.hedera.services.bdd.spec.keys.SigControl) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) OptionalLong(java.util.OptionalLong) TxnFactory(com.hedera.services.bdd.spec.transactions.TxnFactory) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Files(com.google.common.io.Files) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) FileCreateTransactionBody(com.hederahashgraph.api.proto.java.FileCreateTransactionBody) KeyGenerator(com.hedera.services.bdd.spec.keys.KeyGenerator) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) IOException(java.io.IOException) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) File(java.io.File) LongConsumer(java.util.function.LongConsumer) ByteString(com.google.protobuf.ByteString) KeyFactory(com.hedera.services.bdd.spec.keys.KeyFactory) Consumer(java.util.function.Consumer) TxnFactory.bannerWith(com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) File(java.io.File)

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