Search in sources :

Example 11 with Transaction

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

the class PlatformTxnAccessorTest method getsCorrectLoggableForm.

@Test
void getsCorrectLoggableForm() throws Exception {
    Transaction signedTxnWithBody = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).setSigMap(SignatureMap.newBuilder().addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(ByteString.copyFrom("UNREAL".getBytes())).setEd25519(ByteString.copyFrom("FAKE".getBytes())))).build();
    SwirldTransaction platformTxn = new SwirldTransaction(signedTxnWithBody.toByteArray());
    // when:
    PlatformTxnAccessor subject = new PlatformTxnAccessor(platformTxn);
    Transaction signedTxn4Log = subject.getSignedTxnWrapper();
    Transaction asBodyBytes = signedTxn4Log.toBuilder().setBodyBytes(CommonUtils.extractTransactionBodyByteString(signedTxn4Log)).build();
    // then:
    assertEquals(someTxn, CommonUtils.extractTransactionBody(signedTxn4Log));
    assertEquals(signedTxnWithBody, asBodyBytes);
}
Also used : SwirldTransaction(com.swirlds.common.SwirldTransaction) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) Test(org.junit.jupiter.api.Test)

Example 12 with Transaction

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

the class PlatformTxnAccessorTest method sigMetaGetterSetterCheck.

@Test
void sigMetaGetterSetterCheck() throws InvalidProtocolBufferException {
    // setup:
    Transaction signedTxnWithBody = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).build();
    SwirldTransaction platformTxn = new SwirldTransaction(signedTxnWithBody.toByteArray());
    // given:
    SignedTxnAccessor subject = new PlatformTxnAccessor(platformTxn);
    // when:
    subject.setSigMeta(RationalizedSigMeta.noneAvailable());
    // then:
    assertSame(RationalizedSigMeta.noneAvailable(), subject.getSigMeta());
}
Also used : SwirldTransaction(com.swirlds.common.SwirldTransaction) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) Test(org.junit.jupiter.api.Test)

Example 13 with Transaction

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

the class PlatformTxnAccessorTest method failsOnInvalidTxn.

@Test
void failsOnInvalidTxn() {
    // given:
    Transaction signedNonsenseTxn = Transaction.newBuilder().setBodyBytes(ByteString.copyFrom(NONSENSE)).build();
    // and:
    SwirldTransaction platformTxn = new SwirldTransaction(signedNonsenseTxn.toByteArray());
    // expect:
    assertThrows(InvalidProtocolBufferException.class, () -> new PlatformTxnAccessor(platformTxn));
}
Also used : SwirldTransaction(com.swirlds.common.SwirldTransaction) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) Test(org.junit.jupiter.api.Test)

Example 14 with Transaction

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

the class PlatformTxnAccessorTest method allowsUncheckedConstruction.

@Test
void allowsUncheckedConstruction() {
    // setup:
    Transaction validTxn = Transaction.getDefaultInstance();
    // expect:
    assertDoesNotThrow(() -> SignedTxnAccessor.uncheckedFrom(validTxn));
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) Test(org.junit.jupiter.api.Test)

Example 15 with Transaction

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

the class HapiTokenUpdate method feeFor.

@Override
protected long feeFor(HapiApiSpec spec, Transaction txn, int numPayerKeys) throws Throwable {
    try {
        final TokenInfo info = HapiTokenFeeScheduleUpdate.lookupInfo(spec, token, log, loggingOff);
        FeeCalculator.ActivityMetrics metricsCalc = (_txn, svo) -> {
            var estimate = TokenUpdateUsage.newEstimate(_txn, suFrom(svo));
            estimate.givenCurrentExpiry(info.getExpiry().getSeconds()).givenCurrentMemo(info.getMemo()).givenCurrentName(info.getName()).givenCurrentSymbol(info.getSymbol());
            if (info.hasFreezeKey()) {
                estimate.givenCurrentFreezeKey(Optional.of(info.getFreezeKey()));
            }
            if (info.hasAdminKey()) {
                estimate.givenCurrentAdminKey(Optional.of(info.getAdminKey()));
            }
            if (info.hasSupplyKey()) {
                estimate.givenCurrentSupplyKey(Optional.of(info.getSupplyKey()));
            }
            if (info.hasKycKey()) {
                estimate.givenCurrentKycKey(Optional.of(info.getKycKey()));
            }
            if (info.hasWipeKey()) {
                estimate.givenCurrentWipeKey(Optional.of(info.getWipeKey()));
            }
            if (info.hasFeeScheduleKey()) {
                estimate.givenCurrentFeeScheduleKey(Optional.of(info.getFeeScheduleKey()));
            }
            if (info.hasPauseKey()) {
                estimate.givenCurrentPauseKey(Optional.of(info.getPauseKey()));
            }
            if (info.hasAutoRenewAccount()) {
                estimate.givenCurrentlyUsingAutoRenewAccount();
            }
            return estimate.get();
        };
        return spec.fees().forActivityBasedOp(HederaFunctionality.TokenUpdate, metricsCalc, txn, numPayerKeys);
    } catch (Throwable t) {
        log.warn("Couldn't estimate usage", t);
        return HapiApiSuite.ONE_HBAR;
    }
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TokenInfo(com.hederahashgraph.api.proto.java.TokenInfo) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) TokenUpdateUsage(com.hedera.services.usage.token.TokenUpdateUsage) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Consumer(java.util.function.Consumer) 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) FeeCalculator(com.hedera.services.bdd.spec.fees.FeeCalculator) TokenInfo(com.hederahashgraph.api.proto.java.TokenInfo)

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