Search in sources :

Example 66 with HapiApiSpec

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

the class HapiFileUpdate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    Optional<Key> wacl = useBadlyEncodedWacl ? Optional.of(badlyEncodedWacl()) : (useEmptyWacl ? Optional.of(emptyWacl()) : newWaclKey.map(spec.registry()::getKey));
    if (newContentsPath.isPresent()) {
        newContents = Optional.of(ByteString.copyFrom(Files.toByteArray(new File(newContentsPath.get()))));
    } else if (contentFn.isPresent()) {
        newContents = Optional.of(contentFn.get().apply(spec));
    } else if (propOverrides.isPresent() || propDeletions.isPresent()) {
        if (propOverrides.isEmpty()) {
            propOverrides = Optional.of(Collections.emptyMap());
        }
        ServicesConfigurationList defaults = readBaseProps(spec);
        ServicesConfigurationList.Builder list = ServicesConfigurationList.newBuilder();
        Map<String, String> overrides = propOverrides.get();
        Map<String, String> defaultPairs = defaults.getNameValueList().stream().collect(Collectors.toMap(Setting::getName, Setting::getValue));
        Set<String> keys = new HashSet<>();
        defaults.getNameValueList().stream().map(Setting::getName).filter(key -> !propDeletions.orElse(EMPTY_SET).contains(key)).forEach(keys::add);
        overrides.keySet().stream().forEach(keys::add);
        keys.forEach(key -> {
            if (overrides.containsKey(key)) {
                list.addNameValue(asSetting(key, overrides.get(key)));
            } else {
                list.addNameValue(asSetting(key, defaultPairs.get(key)));
            }
        });
        newContents = Optional.of(list.build().toByteString());
    }
    long nl = -1;
    if (expiryExtension.isPresent()) {
        try {
            var oldExpiry = spec.registry().getTimestamp(file).getSeconds();
            nl = oldExpiry - Instant.now().getEpochSecond() + expiryExtension.getAsLong();
        } catch (Exception ignore) {
        }
    } else if (lifetimeSecs.isPresent()) {
        nl = lifetimeSecs.get();
    }
    final OptionalLong newLifetime = (nl == -1) ? OptionalLong.empty() : OptionalLong.of(nl);
    var fid = TxnUtils.asFileId(file, spec);
    FileUpdateTransactionBody opBody = spec.txns().<FileUpdateTransactionBody, FileUpdateTransactionBody.Builder>body(FileUpdateTransactionBody.class, builder -> {
        builder.setFileID(fid);
        newMemo.ifPresent(s -> builder.setMemo(StringValue.newBuilder().setValue(s).build()));
        wacl.ifPresent(k -> builder.setKeys(k.getKeyList()));
        newContents.ifPresent(b -> builder.setContents(b));
        newLifetime.ifPresent(s -> builder.setExpirationTime(TxnFactory.expiryGiven(s)));
    });
    preUpdateCb.ifPresent(cb -> cb.accept(fid));
    return builder -> builder.setFileUpdate(opBody);
}
Also used : StringValue(com.google.protobuf.StringValue) ServicesConfigurationList(com.hederahashgraph.api.proto.java.ServicesConfigurationList) EMPTY_MAP(java.util.Collections.EMPTY_MAP) EMPTY_SET(java.util.Collections.EMPTY_SET) Map(java.util.Map) KeyList(com.hederahashgraph.api.proto.java.KeyList) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ONE_HBAR(com.hedera.services.bdd.suites.HapiApiSuite.ONE_HBAR) ByteString(com.google.protobuf.ByteString) FileGetInfoResponse(com.hederahashgraph.api.proto.java.FileGetInfoResponse) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) ExchangeRateSet(com.hederahashgraph.api.proto.java.ExchangeRateSet) Optional(java.util.Optional) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) HapiGetFileInfo(com.hedera.services.bdd.spec.queries.file.HapiGetFileInfo) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) Function(java.util.function.Function) Setting(com.hederahashgraph.api.proto.java.Setting) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OptionalLong(java.util.OptionalLong) TxnFactory(com.hedera.services.bdd.spec.transactions.TxnFactory) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Files(com.google.common.io.Files) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) ExtantFileContext(com.hedera.services.usage.file.ExtantFileContext) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) QueryVerbs.getFileContents(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) MoreObjects(com.google.common.base.MoreObjects) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) File(java.io.File) HapiGetFileContents(com.hedera.services.bdd.spec.queries.file.HapiGetFileContents) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) Assertions(org.junit.jupiter.api.Assertions) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) Setting(com.hederahashgraph.api.proto.java.Setting) ByteString(com.google.protobuf.ByteString) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) ServicesConfigurationList(com.hederahashgraph.api.proto.java.ServicesConfigurationList) OptionalLong(java.util.OptionalLong) File(java.io.File) Key(com.hederahashgraph.api.proto.java.Key) HashSet(java.util.HashSet)

Example 67 with HapiApiSpec

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

the class HapiScheduleCreate method defaultSigners.

@Override
protected List<Function<HapiApiSpec, Key>> defaultSigners() {
    List<Function<HapiApiSpec, Key>> signers = new ArrayList<>(List.of(spec -> spec.registry().getKey(effectivePayer(spec))));
    adminKey.ifPresent(k -> signers.add(spec -> spec.registry().getKey(k)));
    for (String added : initialSigners) {
        signers.add(spec -> spec.registry().getKey(added));
    }
    return signers;
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) ScheduleUtils(com.hedera.services.bdd.suites.schedule.ScheduleUtils) ScheduleCreate(com.hederahashgraph.api.proto.java.HederaFunctionality.ScheduleCreate) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HapiSpecSetup(com.hedera.services.bdd.spec.HapiSpecSetup) ScheduleCreateTransactionBody(com.hederahashgraph.api.proto.java.ScheduleCreateTransactionBody) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) KeyList(com.hederahashgraph.api.proto.java.KeyList) BiConsumer(java.util.function.BiConsumer) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) HapiPropertySource.asScheduleString(com.hedera.services.bdd.spec.HapiPropertySource.asScheduleString) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) SchedulableTransactionBody(com.hederahashgraph.api.proto.java.SchedulableTransactionBody) 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) 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) Collections(java.util.Collections) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HapiPropertySource.asScheduleString(com.hedera.services.bdd.spec.HapiPropertySource.asScheduleString) ByteString(com.google.protobuf.ByteString)

Example 68 with HapiApiSpec

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

the class HapiScheduleCreate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    var subOp = scheduled.signedTxnFor(spec);
    ScheduleCreateTransactionBody opBody = spec.txns().<ScheduleCreateTransactionBody, ScheduleCreateTransactionBody.Builder>body(ScheduleCreateTransactionBody.class, b -> {
        if (scheduleNoFunction) {
            b.setScheduledTransactionBody(SchedulableTransactionBody.getDefaultInstance());
        } else {
            try {
                var deserializedTxn = TransactionBody.parseFrom(subOp.getBodyBytes());
                scheduledTxn.set(ScheduleUtils.fromOrdinary(deserializedTxn));
                b.setScheduledTransactionBody(scheduledTxn.get());
            } catch (InvalidProtocolBufferException fatal) {
                throw new IllegalStateException("Couldn't deserialize serialized TransactionBody!");
            }
        }
        if (useSentinelKeyListForAdminKey) {
            b.setAdminKey(Key.newBuilder().setKeyList(KeyList.getDefaultInstance()));
        } else {
            adminKey.ifPresent(k -> b.setAdminKey(spec.registry().getKey(k)));
        }
        entityMemo.ifPresent(b::setMemo);
        payerAccountID.ifPresent(a -> {
            var payer = TxnUtils.asId(a, spec);
            b.setPayerAccountID(payer);
        });
    });
    return b -> b.setScheduleCreate(opBody);
}
Also used : ScheduleCreateTransactionBody(com.hederahashgraph.api.proto.java.ScheduleCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) ScheduleUtils(com.hedera.services.bdd.suites.schedule.ScheduleUtils) ScheduleCreate(com.hederahashgraph.api.proto.java.HederaFunctionality.ScheduleCreate) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HapiSpecSetup(com.hedera.services.bdd.spec.HapiSpecSetup) ScheduleCreateTransactionBody(com.hederahashgraph.api.proto.java.ScheduleCreateTransactionBody) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) KeyList(com.hederahashgraph.api.proto.java.KeyList) BiConsumer(java.util.function.BiConsumer) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) HapiPropertySource.asScheduleString(com.hedera.services.bdd.spec.HapiPropertySource.asScheduleString) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) SchedulableTransactionBody(com.hederahashgraph.api.proto.java.SchedulableTransactionBody) 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) 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) Collections(java.util.Collections) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 69 with HapiApiSpec

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

the class HapiScheduleSign method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    ScheduleSignTransactionBody opBody = spec.txns().<ScheduleSignTransactionBody, ScheduleSignTransactionBody.Builder>body(ScheduleSignTransactionBody.class, b -> {
        ScheduleID id;
        try {
            id = asScheduleId(schedule, spec);
            b.setScheduleID(id);
        } catch (RegistryNotFound e) {
            if (!ignoreMissing) {
                throw e;
            }
        }
    });
    return b -> b.setScheduleSign(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) ScheduleID(com.hederahashgraph.api.proto.java.ScheduleID) TxnUtils.asScheduleId(com.hedera.services.bdd.spec.transactions.TxnUtils.asScheduleId) ScheduleSign(com.hederahashgraph.api.proto.java.HederaFunctionality.ScheduleSign) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) MoreObjects(com.google.common.base.MoreObjects) HapiScheduleCreate.correspondingScheduledTxnId(com.hedera.services.bdd.spec.transactions.schedule.HapiScheduleCreate.correspondingScheduledTxnId) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Function(java.util.function.Function) ScheduleSignTransactionBody(com.hederahashgraph.api.proto.java.ScheduleSignTransactionBody) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) RegistryNotFound(com.hedera.services.bdd.spec.infrastructure.RegistryNotFound) ScheduleInfo(com.hederahashgraph.api.proto.java.ScheduleInfo) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Collections(java.util.Collections) RegistryNotFound(com.hedera.services.bdd.spec.infrastructure.RegistryNotFound) ScheduleSignTransactionBody(com.hederahashgraph.api.proto.java.ScheduleSignTransactionBody) ScheduleID(com.hederahashgraph.api.proto.java.ScheduleID)

Example 70 with HapiApiSpec

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

the class HapiScheduleSign method feeFor.

@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
    try {
        final ScheduleInfo info = ScheduleFeeUtils.lookupInfo(spec, schedule, loggingOff);
        FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> scheduleOpsUsage.scheduleSignUsage(_txn, suFrom(svo), info.getExpirationTime().getSeconds());
        return spec.fees().forActivityBasedOp(HederaFunctionality.ScheduleSign, metricsCalc, txn, numPayerKeys);
    } catch (Throwable ignore) {
        return HapiApiSuite.ONE_HBAR;
    }
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) ScheduleID(com.hederahashgraph.api.proto.java.ScheduleID) TxnUtils.asScheduleId(com.hedera.services.bdd.spec.transactions.TxnUtils.asScheduleId) ScheduleSign(com.hederahashgraph.api.proto.java.HederaFunctionality.ScheduleSign) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) MoreObjects(com.google.common.base.MoreObjects) HapiScheduleCreate.correspondingScheduledTxnId(com.hedera.services.bdd.spec.transactions.schedule.HapiScheduleCreate.correspondingScheduledTxnId) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Function(java.util.function.Function) ScheduleSignTransactionBody(com.hederahashgraph.api.proto.java.ScheduleSignTransactionBody) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) RegistryNotFound(com.hedera.services.bdd.spec.infrastructure.RegistryNotFound) ScheduleInfo(com.hederahashgraph.api.proto.java.ScheduleInfo) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Collections(java.util.Collections) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) ScheduleInfo(com.hederahashgraph.api.proto.java.ScheduleInfo)

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