Search in sources :

Example 1 with HapiGetTxnRecord

use of com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord in project hedera-services by hashgraph.

the class UtilVerbs method recordFeeAmount.

/* Some more complicated ops built from primitive sub-ops */
public static CustomSpecAssert recordFeeAmount(String forTxn, String byName) {
    return new CustomSpecAssert((spec, workLog) -> {
        HapiGetTxnRecord subOp = getTxnRecord(forTxn);
        allRunFor(spec, subOp);
        TransactionRecord record = subOp.getResponseRecord();
        long fee = record.getTransactionFee();
        spec.registry().saveAmount(byName, fee);
    });
}
Also used : HapiGetTxnRecord(com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord)

Example 2 with HapiGetTxnRecord

use of com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord in project hedera-services by hashgraph.

the class HapiSpecOperation method lookupSubmissionRecord.

protected void lookupSubmissionRecord(HapiApiSpec spec) throws Throwable {
    HapiGetTxnRecord subOp = getTxnRecord(extractTxnId(txnSubmitted)).noLogging().assertingNothing().suppressStats(true).nodePayment(spec.setup().defaultNodePaymentTinyBars());
    Optional<Throwable> error = subOp.execFor(spec);
    if (error.isPresent()) {
        throw error.get();
    }
    recordOfSubmission = subOp.getResponse().getTransactionGetRecord().getTransactionRecord();
}
Also used : HapiGetTxnRecord(com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord)

Example 3 with HapiGetTxnRecord

use of com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord in project hedera-services by hashgraph.

the class UtilVerbs method chunkAFile.

public static HapiSpecOperation chunkAFile(String filePath, int chunkSize, String payer, String topic, AtomicLong count) {
    return withOpContext((spec, ctxLog) -> {
        List<HapiSpecOperation> opsList = new ArrayList<HapiSpecOperation>();
        String overriddenFile = new String(filePath);
        int overriddenChunkSize = chunkSize;
        String overriddenTopic = new String(topic);
        boolean validateRunningHash = false;
        long currentCount = count.getAndIncrement();
        if (currentCount >= 0) {
            var ciProperties = spec.setup().ciPropertiesMap();
            if (null != ciProperties) {
                if (ciProperties.has("file")) {
                    overriddenFile = ciProperties.get("file");
                }
                if (ciProperties.has("chunkSize")) {
                    overriddenChunkSize = ciProperties.getInteger("chunkSize");
                }
                if (ciProperties.has("validateRunningHash")) {
                    validateRunningHash = ciProperties.getBoolean("validateRunningHash");
                }
                int threads = PerfTestLoadSettings.DEFAULT_THREADS;
                if (ciProperties.has("threads")) {
                    threads = ciProperties.getInteger("threads");
                }
                int factor = HCSChunkingRealisticPerfSuite.DEFAULT_COLLISION_AVOIDANCE_FACTOR;
                if (ciProperties.has("collisionAvoidanceFactor")) {
                    factor = ciProperties.getInteger("collisionAvoidanceFactor");
                }
                overriddenTopic += currentCount % (threads * factor);
            }
        }
        ByteString msg = ByteString.copyFrom(Files.readAllBytes(Paths.get(overriddenFile)));
        int size = msg.size();
        int totalChunks = (size + overriddenChunkSize - 1) / overriddenChunkSize;
        int position = 0;
        int currentChunk = 0;
        var initialTransactionID = asTransactionID(spec, Optional.of(payer));
        while (position < size) {
            ++currentChunk;
            int newPosition = Math.min(size, position + overriddenChunkSize);
            ByteString subMsg = msg.substring(position, newPosition);
            HapiMessageSubmit subOp = submitMessageTo(overriddenTopic).message(subMsg).chunkInfo(totalChunks, currentChunk, initialTransactionID).payingWith(payer).hasKnownStatus(SUCCESS).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED, INSUFFICIENT_PAYER_BALANCE).noLogging().suppressStats(true);
            if (1 == currentChunk) {
                subOp = subOp.usePresetTimestamp();
            }
            if (validateRunningHash) {
                String txnName = "submitMessage-" + overriddenTopic + "-" + currentChunk;
                HapiGetTxnRecord validateOp = getTxnRecord(txnName).hasCorrectRunningHash(overriddenTopic, subMsg.toByteArray()).payingWith(payer).noLogging();
                opsList.add(subOp.via(txnName));
                opsList.add(validateOp);
            } else {
                opsList.add(subOp.deferStatusResolution());
            }
            position = newPosition;
        }
        CustomSpecAssert.allRunFor(spec, opsList);
    });
}
Also used : HapiMessageSubmit(com.hedera.services.bdd.spec.transactions.consensus.HapiMessageSubmit) ByteString(com.google.protobuf.ByteString) HapiGetTxnRecord(com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord) ArrayList(java.util.ArrayList) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) HapiPropertySource.asAccountString(com.hedera.services.bdd.spec.HapiPropertySource.asAccountString) ByteString(com.google.protobuf.ByteString)

Example 4 with HapiGetTxnRecord

use of com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord in project hedera-services by hashgraph.

the class UtilVerbs method validateTransferListForBalances.

public static HapiSpecOperation validateTransferListForBalances(List<String> txns, List<String> accounts, Set<String> wereDeleted) {
    return assertionsHold((spec, assertLog) -> {
        Map<String, Long> actualBalances = accounts.stream().collect(Collectors.toMap((String account) -> asAccountString(spec.registry().getAccountID(account)), (String account) -> {
            if (wereDeleted.contains(account)) {
                return 0L;
            }
            long balance = -1L;
            try {
                BalanceSnapshot preOp = balanceSnapshot("x", account);
                allRunFor(spec, preOp);
                balance = spec.registry().getBalanceSnapshot("x");
            } catch (Throwable ignore) {
            }
            return balance;
        }));
        List<AccountAmount> transfers = new ArrayList<>();
        for (String txn : txns) {
            HapiGetTxnRecord subOp = getTxnRecord(txn).logged().payingWith(EXCHANGE_RATE_CONTROL);
            allRunFor(spec, subOp);
            TransactionRecord record = subOp.getResponse().getTransactionGetRecord().getTransactionRecord();
            transfers.addAll(record.getTransferList().getAccountAmountsList());
        }
        Map<String, Long> changes = changesAccordingTo(transfers);
        assertLog.info("Balance changes according to transfer list: " + changes);
        changes.entrySet().forEach(change -> {
            String account = change.getKey();
            long oldBalance = -1L;
            /* The account/contract may have just been created, no snapshot was taken. */
            try {
                oldBalance = spec.registry().getBalanceSnapshot(account + "Snapshot");
            } catch (Throwable ignore) {
            }
            long expectedBalance = change.getValue() + Math.max(0L, oldBalance);
            long actualBalance = actualBalances.getOrDefault(account, -1L);
            assertLog.info("Balance of " + account + " was expected to be " + expectedBalance + ", is actually " + actualBalance + "...");
            Assertions.assertEquals(expectedBalance, actualBalance, "New balance for " + account + " should be " + expectedBalance + " tinyBars.");
        });
    });
}
Also used : HapiGetTxnRecord(com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord) OptionalLong(java.util.OptionalLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) HapiPropertySource.asAccountString(com.hedera.services.bdd.spec.HapiPropertySource.asAccountString) ByteString(com.google.protobuf.ByteString) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 5 with HapiGetTxnRecord

use of com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord in project hedera-services by hashgraph.

the class UtilVerbs method validateRecordTransactionFees.

public static HapiSpecOperation validateRecordTransactionFees(String txn, Set<AccountID> feeRecipients) {
    return assertionsHold((spec, assertLog) -> {
        HapiGetTxnRecord subOp = getTxnRecord(txn).logged().payingWith(EXCHANGE_RATE_CONTROL).expectStrictCostAnswer();
        allRunFor(spec, subOp);
        TransactionRecord record = subOp.getResponse().getTransactionGetRecord().getTransactionRecord();
        long realFee = record.getTransferList().getAccountAmountsList().stream().filter(aa -> feeRecipients.contains(aa.getAccountID())).mapToLong(AccountAmount::getAmount).sum();
        Assertions.assertEquals(realFee, record.getTransactionFee(), "Inconsistent transactionFee field!");
    });
}
Also used : HapiGetTxnRecord(com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord)

Aggregations

HapiGetTxnRecord (com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord)5 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)3 ByteString (com.google.protobuf.ByteString)2 HapiPropertySource.asAccountString (com.hedera.services.bdd.spec.HapiPropertySource.asAccountString)2 ArrayList (java.util.ArrayList)2 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)1 HapiMessageSubmit (com.hedera.services.bdd.spec.transactions.consensus.HapiMessageSubmit)1 AccountAmount (com.hederahashgraph.api.proto.java.AccountAmount)1 OptionalLong (java.util.OptionalLong)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1