Search in sources :

Example 6 with TransactionBody

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

the class ContextOptionValidatorTest method acceptsOk.

@Test
void acceptsOk() {
    SignedTxnAccessor accessor = mock(SignedTxnAccessor.class);
    // given:
    long validDuration = 1_000L;
    Instant consensusTime = Instant.ofEpochSecond(1_234_567L);
    Instant validStart = Instant.ofEpochSecond(consensusTime.minusSeconds(validDuration - 1).getEpochSecond());
    // and:
    TransactionID txnId = TransactionID.newBuilder().setTransactionValidStart(Timestamp.newBuilder().setSeconds(validStart.getEpochSecond())).build();
    TransactionBody txn = TransactionBody.newBuilder().setTransactionID(txnId).setTransactionValidDuration(Duration.newBuilder().setSeconds(validDuration)).build();
    // and:
    given(accessor.getTxn()).willReturn(txn);
    given(accessor.getTxnId()).willReturn(txnId);
    // when:
    ResponseCodeEnum status = subject.chronologyStatus(accessor, consensusTime);
    // then:
    assertEquals(OK, status);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Instant(java.time.Instant) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test)

Example 7 with TransactionBody

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

the class ContextOptionValidatorTest method recognizesFutureValidStartStart.

@Test
void recognizesFutureValidStartStart() {
    SignedTxnAccessor accessor = mock(SignedTxnAccessor.class);
    // given:
    long validDuration = 1_000L;
    Instant consensusTime = Instant.ofEpochSecond(1_234_567L);
    Instant validStart = Instant.ofEpochSecond(consensusTime.plusSeconds(1L).getEpochSecond());
    // and:
    TransactionID txnId = TransactionID.newBuilder().setTransactionValidStart(Timestamp.newBuilder().setSeconds(validStart.getEpochSecond())).build();
    TransactionBody txn = TransactionBody.newBuilder().setTransactionID(txnId).setTransactionValidDuration(Duration.newBuilder().setSeconds(validDuration)).build();
    // and:
    given(accessor.getTxn()).willReturn(txn);
    given(accessor.getTxnId()).willReturn(txnId);
    // when:
    ResponseCodeEnum status = subject.chronologyStatus(accessor, consensusTime);
    // then:
    assertEquals(INVALID_TRANSACTION_START, status);
    // and:
    assertEquals(INVALID_TRANSACTION_START, subject.chronologyStatusForTxn(validStart, validDuration, consensusTime));
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Instant(java.time.Instant) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test)

Example 8 with TransactionBody

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

the class ContractCallTransitionLogicTest method codeCacheThrowingExceptionDuringGetDoesntPropagate.

@Test
void codeCacheThrowingExceptionDuringGetDoesntPropagate() {
    TransactionBody txnBody = Mockito.mock(TransactionBody.class);
    ContractCallTransactionBody ccTxnBody = Mockito.mock(ContractCallTransactionBody.class);
    given(accessor.getTxn()).willReturn(txnBody);
    given(txnBody.getContractCall()).willReturn(ccTxnBody);
    given(ccTxnBody.getContractID()).willReturn(IdUtils.asContract("0.0.1324"));
    given(codeCache.getIfPresent(any(Address.class))).willThrow(new RuntimeException("oh no"));
    // when:
    assertDoesNotThrow(() -> subject.preFetch(accessor));
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) Address(org.hyperledger.besu.datatypes.Address) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) Test(org.junit.jupiter.api.Test)

Example 9 with TransactionBody

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

the class CryptoAdjustAllowanceTransitionLogic method doStateTransition.

@Override
public void doStateTransition() {
    /* --- Extract gRPC --- */
    final TransactionBody cryptoAdjustAllowanceTxn = txnCtx.accessor().getTxn();
    final AccountID payer = cryptoAdjustAllowanceTxn.getTransactionID().getAccountID();
    final var op = cryptoAdjustAllowanceTxn.getCryptoAdjustAllowance();
    entitiesChanged.clear();
    /* --- Use models --- */
    final Id payerId = Id.fromGrpcAccount(payer);
    final var payerAccount = accountStore.loadAccount(payerId);
    /* --- Do the business logic --- */
    adjustCryptoAllowances(op.getCryptoAllowancesList(), payerAccount);
    adjustFungibleTokenAllowances(op.getTokenAllowancesList(), payerAccount);
    adjustNftAllowances(op.getNftAllowancesList(), payerAccount);
    /* --- Persist the owner account --- */
    for (final var entry : entitiesChanged.entrySet()) {
        accountStore.commitAccount(entry.getValue());
    }
    txnCtx.setStatus(SUCCESS);
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AccountID(com.hederahashgraph.api.proto.java.AccountID) FcTokenAllowanceId(com.hedera.services.state.submerkle.FcTokenAllowanceId) Id(com.hedera.services.store.models.Id)

Example 10 with TransactionBody

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

the class HapiScheduleCreate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    var subOp = scheduled.signedTxnFor(spec);
    ScheduleCreateTransactionBody opBody = spec.txns().<ScheduleCreateTransactionBody, ScheduleCreateTransactionBody.Builder>body(ScheduleCreateTransactionBody.class, b -> {
        if (scheduleNoFunction) {
            b.setScheduledTransactionBody(SchedulableTransactionBody.getDefaultInstance());
        } else {
            try {
                var deserializedTxn = TransactionBody.parseFrom(subOp.getBodyBytes());
                scheduledTxn.set(ScheduleUtils.fromOrdinary(deserializedTxn));
                b.setScheduledTransactionBody(scheduledTxn.get());
            } catch (InvalidProtocolBufferException fatal) {
                throw new IllegalStateException("Couldn't deserialize serialized TransactionBody!");
            }
        }
        if (useSentinelKeyListForAdminKey) {
            b.setAdminKey(Key.newBuilder().setKeyList(KeyList.getDefaultInstance()));
        } else {
            adminKey.ifPresent(k -> b.setAdminKey(spec.registry().getKey(k)));
        }
        entityMemo.ifPresent(b::setMemo);
        payerAccountID.ifPresent(a -> {
            var payer = TxnUtils.asId(a, spec);
            b.setPayerAccountID(payer);
        });
    });
    return b -> b.setScheduleCreate(opBody);
}
Also used : ScheduleCreateTransactionBody(com.hederahashgraph.api.proto.java.ScheduleCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) ScheduleUtils(com.hedera.services.bdd.suites.schedule.ScheduleUtils) ScheduleCreate(com.hederahashgraph.api.proto.java.HederaFunctionality.ScheduleCreate) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HapiSpecSetup(com.hedera.services.bdd.spec.HapiSpecSetup) ScheduleCreateTransactionBody(com.hederahashgraph.api.proto.java.ScheduleCreateTransactionBody) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) KeyList(com.hederahashgraph.api.proto.java.KeyList) BiConsumer(java.util.function.BiConsumer) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) HapiPropertySource.asScheduleString(com.hedera.services.bdd.spec.HapiPropertySource.asScheduleString) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) SchedulableTransactionBody(com.hederahashgraph.api.proto.java.SchedulableTransactionBody) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) TxnFactory.bannerWith(com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith) 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) Collections(java.util.Collections) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

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