Search in sources :

Example 1 with TransactionBody

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

the class SingletonEstimatorUtilsTest method getsBaseRecordBytesForTransfer.

@Test
void getsBaseRecordBytesForTransfer() {
    // given:
    TransactionBody txn = TransactionBody.newBuilder().setMemo(memo).setCryptoTransfer(CryptoTransferTransactionBody.newBuilder().setTransfers(transfers)).build();
    // and:
    int expected = FeeBuilder.BASIC_TX_RECORD_SIZE + memo.length() + FeeBuilder.BASIC_ACCOUNT_AMT_SIZE * transfers.getAccountAmountsCount();
    // when:
    int actual = ESTIMATOR_UTILS.baseRecordBytes(txn);
    // then:
    assertEquals(expected, actual);
}
Also used : CryptoTransferTransactionBody(com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Test(org.junit.jupiter.api.Test)

Example 2 with TransactionBody

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

the class SingletonEstimatorUtilsTest method hasExpectedBaseEstimate.

@Test
void hasExpectedBaseEstimate() {
    // given:
    TransactionBody txn = TransactionBody.newBuilder().setMemo("You won't want to hear this.").setCryptoTransfer(CryptoTransferTransactionBody.newBuilder().setTransfers(TransferList.newBuilder().addAccountAmounts(AccountAmount.newBuilder().setAmount(123L).setAccountID(AccountID.newBuilder().setAccountNum(75231))))).build();
    // and:
    long expectedBpt = ESTIMATOR_UTILS.baseBodyBytes(txn) + sigUsage.sigsSize();
    long expectedRbs = ESTIMATOR_UTILS.baseRecordBytes(txn) * RECEIPT_STORAGE_TIME_SEC;
    // when:
    var est = ESTIMATOR_UTILS.baseEstimate(txn, sigUsage);
    // then:
    assertEquals(1L * INT_SIZE, est.base().getBpr());
    assertEquals(sigUsage.numSigs(), est.base().getVpt());
    assertEquals(expectedBpt, est.base().getBpt());
    assertEquals(expectedRbs, est.getRbs());
}
Also used : CryptoTransferTransactionBody(com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Test(org.junit.jupiter.api.Test)

Example 3 with TransactionBody

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

the class SingletonEstimatorUtilsTest method getsBaseRecordBytesForNonTransfer.

@Test
void getsBaseRecordBytesForNonTransfer() {
    // given:
    TransactionBody txn = TransactionBody.newBuilder().setMemo(memo).build();
    // and:
    int expected = FeeBuilder.BASIC_TX_RECORD_SIZE + memo.length();
    // when:
    int actual = ESTIMATOR_UTILS.baseRecordBytes(txn);
    // then:
    assertEquals(expected, actual);
}
Also used : CryptoTransferTransactionBody(com.hederahashgraph.api.proto.java.CryptoTransferTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Test(org.junit.jupiter.api.Test)

Example 4 with TransactionBody

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

the class CryptoCreateTransitionLogic method doStateTransition.

@Override
public void doStateTransition() {
    try {
        TransactionBody cryptoCreateTxn = txnCtx.accessor().getTxn();
        AccountID sponsor = cryptoCreateTxn.getTransactionID().getAccountID();
        CryptoCreateTransactionBody op = cryptoCreateTxn.getCryptoCreateAccount();
        long balance = op.getInitialBalance();
        final var created = ledger.create(sponsor, balance, asCustomizer(op));
        sigImpactHistorian.markEntityChanged(created.getAccountNum());
        txnCtx.setCreated(created);
        txnCtx.setStatus(SUCCESS);
    } catch (InsufficientFundsException ife) {
        txnCtx.setStatus(INSUFFICIENT_PAYER_BALANCE);
    } catch (Exception e) {
        log.warn("Avoidable exception!", e);
        txnCtx.setStatus(FAIL_INVALID);
    }
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) InsufficientFundsException(com.hedera.services.exceptions.InsufficientFundsException) InsufficientFundsException(com.hedera.services.exceptions.InsufficientFundsException)

Example 5 with TransactionBody

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

the class PlatformTxnAccessorTest method usesExtractorToGetFunctionAsExpected.

@Test
void usesExtractorToGetFunctionAsExpected() {
    // setup:
    var memory = SignedTxnAccessor.functionExtractor;
    Function<TransactionBody, HederaFunctionality> mockFn = (Function<TransactionBody, HederaFunctionality>) mock(Function.class);
    SignedTxnAccessor.functionExtractor = mockFn;
    // and:
    someTxn = someTxn.toBuilder().setConsensusCreateTopic(ConsensusCreateTopicTransactionBody.newBuilder()).build();
    Transaction signedTxn = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).build();
    given(mockFn.apply(any())).willReturn(ConsensusCreateTopic);
    var subject = SignedTxnAccessor.uncheckedFrom(signedTxn);
    // when:
    var first = subject.getFunction();
    var second = subject.getFunction();
    // then:
    assertEquals(ConsensusCreateTopic, first);
    assertEquals(second, first);
    // and:
    verify(mockFn, times(1)).apply(any());
    // cleanup:
    SignedTxnAccessor.functionExtractor = memory;
}
Also used : HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Function(java.util.function.Function) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ConsensusCreateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusCreateTopicTransactionBody) 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)

Aggregations

TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)145 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)106 Test (org.junit.jupiter.api.Test)100 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)96 Transaction (com.hederahashgraph.api.proto.java.Transaction)91 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)91 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)34 AccountID (com.hederahashgraph.api.proto.java.AccountID)32 EnumSource (org.junit.jupiter.params.provider.EnumSource)32 EntityId (com.hedera.mirror.common.domain.entity.EntityId)31 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)31 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)31 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)31 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)31 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)31 Entity (com.hedera.mirror.common.domain.entity.Entity)29 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)29 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)28 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)28 Contract (com.hedera.mirror.common.domain.contract.Contract)27