Search in sources :

Example 1 with Transaction

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

the class FeeBuilderTest method assertGetSignatureSizeReturnsZero.

@Test
void assertGetSignatureSizeReturnsZero() {
    Transaction signedTxn = Transaction.newBuilder().setSignedTransactionBytes(ByteString.copyFromUtf8("Wrong value")).build();
    assertEquals(0, FeeBuilder.getSignatureSize(signedTxn));
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 2 with Transaction

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

the class PojoSigMapPubKeyToSigBytesTest method getsExpectedSigBytesForOtherParties.

@Test
void getsExpectedSigBytesForOtherParties() throws Throwable {
    // given:
    Transaction signedTxn = newSignedSystemDelete().payerKt(payerKt).nonPayerKts(otherKt).get();
    PubKeyToSigBytes subject = new PojoSigMapPubKeyToSigBytes(SignedTxnAccessor.uncheckedFrom(signedTxn).getSigMap());
    // expect:
    lookupsMatch(payerKt, defaultFactory, CommonUtils.extractTransactionBodyBytes(signedTxn), subject);
    lookupsMatch(otherKt, defaultFactory, CommonUtils.extractTransactionBodyBytes(signedTxn), subject);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) Test(org.junit.jupiter.api.Test)

Example 3 with Transaction

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

the class SigVerifierRegressionTest method rejectsInvalidTxn.

@Test
void rejectsInvalidTxn() throws Throwable {
    // given:
    Transaction invalidSignedTxn = Transaction.newBuilder().setBodyBytes(ByteString.copyFrom("NONSENSE".getBytes())).build();
    // expect:
    assertFalse(sigVerifies(invalidSignedTxn));
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) Test(org.junit.jupiter.api.Test)

Example 4 with Transaction

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

the class HapiQueryOp method fittedPayment.

private Transaction fittedPayment(HapiApiSpec spec) throws Throwable {
    if (explicitPayment.isPresent()) {
        return explicitPayment.get().signedTxnFor(spec);
    } else if (nodePaymentFn.isPresent()) {
        return finalizedTxn(spec, opDef(spec, nodePaymentFn.get().apply(spec)));
    } else if (nodePayment.isPresent()) {
        return finalizedTxn(spec, opDef(spec, nodePayment.get()));
    } else {
        long initNodePayment = costOnlyNodePayment(spec);
        Transaction payment = finalizedTxn(spec, opDef(spec, initNodePayment), true);
        if (!loggingOff) {
            log.info(spec.logPrefix() + "Paying for COST_ANSWER of " + this + " with " + txnToString(payment));
        }
        long realNodePayment = timedCostLookupWith(spec, payment);
        if (recordsNodePayment) {
            spec.registry().saveAmount(nodePaymentName, realNodePayment);
        }
        if (!suppressStats) {
            spec.incrementNumLedgerOps();
        }
        if (expectedCostAnswerPrecheck() != OK) {
            return null;
        }
        if (spec.setup().costSnapshotMode() != OFF) {
            spec.recordPayment(new Payment(initNodePayment, self().getClass().getSimpleName(), COST_ANSWER_QUERY_COST));
            spec.recordPayment(new Payment(realNodePayment, self().getClass().getSimpleName(), ANSWER_ONLY_QUERY_COST));
        }
        txnSubmitted = payment;
        if (!loggingOff) {
            log.info(spec.logPrefix() + "--> Node payment for " + this + " is " + realNodePayment + " tinyBars.");
        }
        if (expectStrictCostAnswer) {
            Transaction insufficientPayment = finalizedTxn(spec, opDef(spec, realNodePayment - 1));
            submitWith(spec, insufficientPayment);
            if (INSUFFICIENT_TX_FEE != reflectForPrecheck(response)) {
                String errMsg = String.format("Strict cost of answer! suppose to be %s, but get %s", INSUFFICIENT_TX_FEE, reflectForPrecheck(response));
                log.error(errMsg);
                throw new HapiQueryPrecheckStateException(errMsg);
            } else {
                log.info("Query with node payment of {} tinyBars got INSUFFICIENT_TX_FEE as expected!", realNodePayment - 1);
            }
        }
        return finalizedTxn(spec, opDef(spec, realNodePayment));
    }
}
Also used : Payment(com.hedera.services.bdd.spec.fees.Payment) Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiQueryPrecheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryPrecheckStateException) TxnUtils.txnToString(com.hedera.services.bdd.spec.transactions.TxnUtils.txnToString)

Example 5 with Transaction

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

the class HapiQueryOp method submitOp.

@Override
protected boolean submitOp(HapiApiSpec spec) throws Throwable {
    fixNodeFor(spec);
    configureTlsFor(spec);
    Transaction payment = Transaction.getDefaultInstance();
    int retryCount = 1;
    while (true) {
        /* Note that HapiQueryOp#fittedPayment makes a COST_ANSWER query if necessary. */
        if (needsPayment()) {
            payment = fittedPayment(spec);
        }
        if (stopAfterCostAnswer) {
            return false;
        }
        /* If the COST_ANSWER query was expected to fail, we will not do anything else for this query. */
        if (needsPayment() && !nodePayment.isPresent() && expectedCostAnswerPrecheck() != OK) {
            return false;
        }
        if (needsPayment() && !loggingOff) {
            log.info(spec.logPrefix() + "Paying for " + this + " with " + txnToString(payment));
        }
        timedSubmitWith(spec, payment);
        actualPrecheck = reflectForPrecheck(response);
        if (answerOnlyRetryPrechecks.isPresent() && answerOnlyRetryPrechecks.get().contains(actualPrecheck) && isWithInRetryLimit(retryCount)) {
            retryCount++;
            sleep(10);
        } else {
            break;
        }
    }
    if (permissibleAnswerOnlyPrechecks.isPresent()) {
        if (permissibleAnswerOnlyPrechecks.get().contains(actualPrecheck)) {
            answerOnlyPrecheck = Optional.of(actualPrecheck);
        } else {
            String errMsg = String.format("Answer-only precheck was %s, not one of %s!", actualPrecheck, permissibleAnswerOnlyPrechecks.get());
            if (!loggingOff) {
                log.error(errMsg);
            }
            throw new HapiQueryPrecheckStateException(errMsg);
        }
    } else {
        if (expectedAnswerOnlyPrecheck() != actualPrecheck) {
            String errMsg = String.format("Bad answerOnlyPrecheck! expected %s, actual %s", expectedAnswerOnlyPrecheck(), actualPrecheck);
            if (!loggingOff) {
                log.error(errMsg);
            }
            throw new HapiQueryPrecheckStateException(errMsg);
        }
    }
    if (expectedCostAnswerPrecheck() != OK || expectedAnswerOnlyPrecheck() != OK) {
        return false;
    }
    txnSubmitted = payment;
    return true;
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiQueryPrecheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryPrecheckStateException) TxnUtils.txnToString(com.hedera.services.bdd.spec.transactions.TxnUtils.txnToString)

Aggregations

Transaction (com.hederahashgraph.api.proto.java.Transaction)174 Test (org.junit.jupiter.api.Test)128 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)108 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)93 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)91 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)84 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)63 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)28 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)28 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)28 UtilityTest (com.hedera.mirror.importer.util.UtilityTest)26 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)26 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)25 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)25 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)25 Entity (com.hedera.mirror.common.domain.entity.Entity)22 TokenTransferList (com.hederahashgraph.api.proto.java.TokenTransferList)21 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)18 ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)17 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)17