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