Search in sources :

Example 6 with Account

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());
}
Also used : Account(com.hedera.services.store.models.Account)

Example 7 with Account

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);
}
Also used : Account(com.hedera.services.store.models.Account) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 8 with Account

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());
}
Also used : MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) Account(com.hedera.services.store.models.Account) Test(org.junit.jupiter.api.Test)

Example 9 with Account

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);
}
Also used : IdUtils.asAccount(com.hedera.test.utils.IdUtils.asAccount) Account(com.hedera.services.store.models.Account) Test(org.junit.jupiter.api.Test)

Example 10 with Account

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);
}
Also used : IdUtils.asAccount(com.hedera.test.utils.IdUtils.asAccount) Account(com.hedera.services.store.models.Account) Test(org.junit.jupiter.api.Test)

Aggregations

Account (com.hedera.services.store.models.Account)15 Test (org.junit.jupiter.api.Test)14 TokenRelationship (com.hedera.services.store.models.TokenRelationship)3 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)2 Id (com.hedera.services.store.models.Id)2 Token (com.hedera.services.store.models.Token)2 IdUtils.asAccount (com.hedera.test.utils.IdUtils.asAccount)2 NftId (com.hedera.services.store.models.NftId)1 OwnershipTracker (com.hedera.services.store.models.OwnershipTracker)1 UniqueToken (com.hedera.services.store.models.UniqueToken)1 EntityNumPair.fromNftId (com.hedera.services.utils.EntityNumPair.fromNftId)1 ContractCallLocalQuery (com.hederahashgraph.api.proto.java.ContractCallLocalQuery)1 ContractCallLocalResponse (com.hederahashgraph.api.proto.java.ContractCallLocalResponse)1 Query (com.hederahashgraph.api.proto.java.Query)1 Response (com.hederahashgraph.api.proto.java.Response)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Address (org.hyperledger.besu.datatypes.Address)1