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);
}
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());
}
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);
}
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);
}
}
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;
}
Aggregations