use of com.hedera.services.store.models.Account in project hedera-services by hashgraph.
the class TopicCreateTransitionLogic method doStateTransition.
@Override
public void doStateTransition() {
/* --- Extract gRPC --- */
final var transactionBody = transactionContext.accessor().getTxn();
final var payerAccountId = transactionBody.getTransactionID().getAccountID();
final var op = transactionBody.getConsensusCreateTopic();
final var submitKey = op.hasSubmitKey() ? validator.attemptDecodeOrThrow(op.getSubmitKey()) : null;
final var adminKey = op.hasAdminKey() ? validator.attemptDecodeOrThrow(op.getAdminKey()) : null;
final var memo = op.getMemo();
final var autoRenewPeriod = op.getAutoRenewPeriod();
final var autoRenewAccountId = Id.fromGrpcAccount(op.getAutoRenewAccount());
/* --- Validate --- */
final var memoValidationResult = validator.memoCheck(memo);
validateTrue(OK == memoValidationResult, memoValidationResult);
validateTrue(op.hasAutoRenewPeriod(), INVALID_RENEWAL_PERIOD);
validateTrue(validator.isValidAutoRenewPeriod(autoRenewPeriod), AUTORENEW_DURATION_NOT_IN_RANGE);
Account autoRenewAccount = null;
if (op.hasAutoRenewAccount()) {
autoRenewAccount = accountStore.loadAccountOrFailWith(autoRenewAccountId, INVALID_AUTORENEW_ACCOUNT);
validateFalse(autoRenewAccount.isSmartContract(), INVALID_AUTORENEW_ACCOUNT);
validateTrue(op.hasAdminKey(), AUTORENEW_ACCOUNT_NOT_ALLOWED);
}
/* --- Do business logic --- */
final var expirationTime = transactionContext.consensusTime().plusSeconds(autoRenewPeriod.getSeconds());
final var topicId = entityIdSource.newTopicId(payerAccountId);
final var topic = Topic.fromGrpcTopicCreate(Id.fromGrpcTopic(topicId), submitKey, adminKey, autoRenewAccount, memo, autoRenewPeriod.getSeconds(), expirationTime);
/* --- Persist the topic --- */
topicStore.persistNew(topic);
sigImpactHistorian.markEntityChanged(topicId.getTopicNum());
}
use of com.hedera.services.store.models.Account in project hedera-services by hashgraph.
the class ContractCallLocalResourceUsageTest method setsResultInQueryCxtIfPresent.
@Test
void setsResultInQueryCxtIfPresent() {
final var queryCtx = new HashMap<String, Object>();
final var transactionProcessingResult = TransactionProcessingResult.successful(new ArrayList<>(), 0, 0, 1, Bytes.EMPTY, callerID.asEvmAddress(), Collections.emptyMap());
final var response = okResponse(transactionProcessingResult);
final var estimateResponse = subject.dummyResponse(target);
final var expected = expectedUsage();
given(accountStore.loadAccount(any())).willReturn(new Account(Id.fromGrpcContract(target)));
given(accountStore.loadContract(any())).willReturn(new Account(Id.fromGrpcContract(target)));
given(evmTxProcessor.execute(any(), any(), anyLong(), anyLong(), any(), any())).willReturn(transactionProcessingResult);
given(usageEstimator.getContractCallLocalFeeMatrices(params.size(), response.getFunctionResult(), ANSWER_ONLY)).willReturn(nonGasUsage);
given(usageEstimator.getContractCallLocalFeeMatrices(params.size(), estimateResponse.getFunctionResult(), ANSWER_ONLY)).willReturn(nonGasUsage);
final var actualUsage1 = subject.usageGiven(satisfiableAnswerOnly, view);
final var actualUsage2 = subject.usageGivenType(satisfiableAnswerOnly, view, ANSWER_ONLY);
final var actualUsage3 = subject.usageGiven(satisfiableAnswerOnly, view, queryCtx);
assertEquals(response, queryCtx.get(ContractCallLocalAnswer.CONTRACT_CALL_LOCAL_CTX_KEY));
assertEquals(expected, actualUsage1);
assertEquals(expected, actualUsage2);
assertEquals(expected, actualUsage3);
}
use of com.hedera.services.store.models.Account in project hedera-services by hashgraph.
the class AccountStoreTest method loadsContractAsExpected.
/* --- Account loading --- */
@Test
void loadsContractAsExpected() {
miscMerkleAccount.setSmartContract(true);
setupWithAccount(miscMerkleId, miscMerkleAccount);
Account account = subject.loadContract(miscId);
assertEquals(Id.fromGrpcAccount(miscMerkleId.toGrpcAccountId()), account.getId());
}
use of com.hedera.services.store.models.Account in project hedera-services by hashgraph.
the class CryptoAdjustAllowanceTransitionLogicTest method checksIfAllowancesExceedLimit.
@Test
void checksIfAllowancesExceedLimit() {
addExistingAllowances();
Account owner = mock(Account.class);
given(accountStore.loadAccount(ownerAcccount.getId())).willReturn(owner);
given(owner.getTotalAllowances()).willReturn(101);
givenValidTxnCtx();
given(accessor.getTxn()).willReturn(cryptoAdjustAllowanceTxn);
given(txnCtx.accessor()).willReturn(accessor);
var exception = assertThrows(InvalidTransactionException.class, () -> subject.doStateTransition());
assertEquals(MAX_ALLOWANCES_EXCEEDED, exception.getResponseCode());
assertEquals(0, ownerAcccount.getCryptoAllowances().size());
assertEquals(0, ownerAcccount.getFungibleTokenAllowances().size());
assertEquals(0, ownerAcccount.getNftAllowances().size());
verify(accountStore, never()).commitAccount(ownerAcccount);
}
use of com.hedera.services.store.models.Account in project hedera-services by hashgraph.
the class CryptoApproveAllowanceTransitionLogicTest method checksIfAllowancesExceedLimit.
@Test
void checksIfAllowancesExceedLimit() {
Account owner = mock(Account.class);
given(accountStore.loadAccount(payerAcccount.getId())).willReturn(payerAcccount);
given(accountStore.loadAccountOrFailWith(ownerAcccount.getId(), INVALID_ALLOWANCE_OWNER_ID)).willReturn(owner);
given(owner.getTotalAllowances()).willReturn(101);
givenValidTxnCtx();
given(accessor.getTxn()).willReturn(cryptoApproveAllowanceTxn);
given(txnCtx.accessor()).willReturn(accessor);
var exception = assertThrows(InvalidTransactionException.class, () -> subject.doStateTransition());
assertEquals(MAX_ALLOWANCES_EXCEEDED, exception.getResponseCode());
assertEquals(0, ownerAcccount.getCryptoAllowances().size());
assertEquals(0, ownerAcccount.getFungibleTokenAllowances().size());
assertEquals(0, ownerAcccount.getNftAllowances().size());
verify(accountStore, never()).commitAccount(ownerAcccount);
}
Aggregations