Search in sources :

Example 26 with SUCCESS

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

Example 27 with SUCCESS

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

the class SysFilesUpdate method updateTargetFromHumanReadable.

private HapiApiSpec updateTargetFromHumanReadable() {
    byte[] bytes = new byte[0];
    String nodesOverride = envNodes();
    System.out.println("Targeting " + nodesOverride);
    String loc = humanReadableFileNames.get(target);
    String readableFile = qualifiedPath(nodesOverride, loc, false);
    try {
        if (BOOK_FILES.contains(target)) {
            AddressBookPojo pojoBook = mapper.readValue(new File(readableFile), AddressBookPojo.class);
            var addressBook = NodeAddressBook.newBuilder();
            pojoBook.getEntries().stream().flatMap(updateConverters.get(target)).forEach(addressBook::addNodeAddress);
            bytes = addressBook.build().toByteArray();
        } else if (target == SystemFile.EXCHANGE_RATES) {
            var pojoRates = mapper.readValue(new File(readableFile), ExchangeRatesPojo.class);
            bytes = pojoRates.toProto().toByteArray();
        } else if (target == SystemFile.FEE_SCHEDULE) {
            final var literal = java.nio.file.Files.readString(Paths.get(readableFile));
            bytes = FeesJsonToProtoSerde.parseFeeScheduleFromJson(literal).toByteArray();
        } else {
            var jutilConfig = new Properties();
            jutilConfig.load(java.nio.file.Files.newInputStream(Paths.get(readableFile)));
            ServicesConfigurationList.Builder protoConfig = ServicesConfigurationList.newBuilder();
            jutilConfig.stringPropertyNames().stream().sorted(JutilPropsToSvcCfgBytes.LEGACY_THROTTLES_FIRST_ORDER).forEach(prop -> protoConfig.addNameValue(Setting.newBuilder().setName(prop).setValue(jutilConfig.getProperty(prop))));
            bytes = protoConfig.build().toByteArray();
        }
    } catch (Exception e) {
        System.out.println(String.format("File '%s' should contain a human-readable %s representation!", readableFile, target.toString()));
        e.printStackTrace();
        System.exit(1);
    }
    final byte[] toUpload = bytes;
    return customHapiSpec(String.format("Update-%s-FromHumanReadable", target)).withProperties(Map.of("nodes", nodesOverride, "default.payer", defaultPayerOverride, "startupAccounts.path", startupAccountsPathOverride)).given(withOpContext((spec, opLog) -> {
        var sysFileOcKeystore = SpecUtils.asOcKeystore(new File(DEFAULT_SYSFILE_PEM_LOC), KeyFactory.PEM_PASSPHRASE);
        var sysFileKey = Key.newBuilder().setEd25519(ByteString.copyFrom(com.swirlds.common.CommonUtils.unhex(sysFileOcKeystore.getPublicKeyAbyteStr()))).build();
        opLog.info("Will ensure default public key :: " + sysFileKey + " (hex = " + sysFileOcKeystore.getPublicKeyAbyteStr() + ")");
        spec.registry().saveKey(DEFAULT_SYSFILE_KEY, sysFileKey);
        spec.keys().incorporate(DEFAULT_SYSFILE_KEY, sysFileOcKeystore);
    }), keyFromPem(DEFAULT_SYSFILE_PEM_LOC).name("insurance").simpleWacl().passphrase(KeyFactory.PEM_PASSPHRASE)).when().then(withOpContext((spec, opLog) -> {
        if (toUpload.length < (6 * 1024)) {
            var singleOp = fileUpdate(registryNames.get(target)).payingWith(DEFAULT_PAYER).fee(feeToOffer()).contents(toUpload).signedBy(DEFAULT_PAYER, DEFAULT_SYSFILE_KEY);
            CustomSpecAssert.allRunFor(spec, singleOp);
        } else {
            int n = 0;
            while (n < toUpload.length) {
                int thisChunkSize = Math.min(toUpload.length - n, 4096);
                byte[] thisChunk = Arrays.copyOfRange(toUpload, n, n + thisChunkSize);
                HapiSpecOperation subOp;
                if (n == 0) {
                    subOp = fileUpdate(registryNames.get(target)).fee(feeToOffer()).wacl("insurance").contents(thisChunk).signedBy(DEFAULT_PAYER, DEFAULT_SYSFILE_KEY).hasKnownStatusFrom(SUCCESS, FEE_SCHEDULE_FILE_PART_UPLOADED);
                } else {
                    subOp = fileAppend(registryNames.get(target)).fee(feeToOffer()).content(thisChunk).signedBy(DEFAULT_PAYER, DEFAULT_SYSFILE_KEY).hasKnownStatusFrom(SUCCESS, FEE_SCHEDULE_FILE_PART_UPLOADED);
                }
                CustomSpecAssert.allRunFor(spec, subOp);
                n += thisChunkSize;
            }
        }
    }));
}
Also used : KeyPair(java.security.KeyPair) Arrays(java.util.Arrays) ServicesConfigurationList(com.hederahashgraph.api.proto.java.ServicesConfigurationList) Base64(org.apache.commons.codec.binary.Base64) CommonUtils(com.hedera.services.legacy.proto.utils.CommonUtils) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) Map(java.util.Map) SplittableRandom(java.util.SplittableRandom) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) EnumMap(java.util.EnumMap) CurrentAndNextFeeSchedule(com.hederahashgraph.api.proto.java.CurrentAndNextFeeSchedule) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) HapiApiSpec.customHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.customHapiSpec) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) KeyFactory(com.hedera.services.bdd.spec.keys.KeyFactory) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) ExchangeRateSet(com.hederahashgraph.api.proto.java.ExchangeRateSet) Optional(java.util.Optional) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) Pattern(java.util.regex.Pattern) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) Ed25519KeyStore(com.hedera.services.bdd.suites.utils.keypairs.Ed25519KeyStore) KeyPairObj(com.hedera.services.legacy.core.KeyPairObj) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) Function(java.util.function.Function) Setting(com.hederahashgraph.api.proto.java.Setting) UtilVerbs.keyFromPem(com.hedera.services.bdd.spec.utilops.UtilVerbs.keyFromPem) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) CustomSpecAssert(com.hedera.services.bdd.spec.utilops.CustomSpecAssert) Charset(java.nio.charset.Charset) Files(com.google.common.io.Files) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) FeesJsonToProtoSerde(com.hedera.services.sysfiles.serdes.FeesJsonToProtoSerde) TxnVerbs.fileAppend(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend) ObjectOutputStream(java.io.ObjectOutputStream) QueryVerbs.getFileContents(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents) Properties(java.util.Properties) FEE_SCHEDULE_FILE_PART_UPLOADED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FEE_SCHEDULE_FILE_PART_UPLOADED) BufferedWriter(java.io.BufferedWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) JutilPropsToSvcCfgBytes(com.hedera.services.bdd.suites.utils.sysfiles.serdes.JutilPropsToSvcCfgBytes) PropertySource.asAccount(com.hedera.services.bdd.spec.PropertySource.asAccount) SpecUtils(com.hedera.services.bdd.suites.utils.keypairs.SpecUtils) File(java.io.File) Key(com.hederahashgraph.api.proto.java.Key) Paths(java.nio.file.Paths) LogManager(org.apache.logging.log4j.LogManager) AccountKeyListObj(com.hedera.services.legacy.core.AccountKeyListObj) ByteString(com.google.protobuf.ByteString) Properties(java.util.Properties) IOException(java.io.IOException) ServicesConfigurationList(com.hederahashgraph.api.proto.java.ServicesConfigurationList) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) File(java.io.File)

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