Search in sources :

Example 11 with Id

use of com.hedera.services.store.models.Id in project hedera-services by hashgraph.

the class FixedFeeSpecTest method finalizationWorksWithFungibleDenomAtCreation.

@Test
void finalizationWorksWithFungibleDenomAtCreation() {
    given(token.isFungibleCommon()).willReturn(true);
    given(tokenStore.loadTokenOrFailWith(new Id(0, 0, otherDenom.num()), INVALID_TOKEN_ID_IN_CUSTOM_FEES)).willReturn(token);
    given(feeCollector.isAssociatedWith(otherDenom.asId())).willReturn(true);
    final var otherDenomSubject = new FixedFeeSpec(123, otherDenom);
    assertDoesNotThrow(() -> otherDenomSubject.validateAndFinalizeWith(token, feeCollector, tokenStore));
}
Also used : Id(com.hedera.services.store.models.Id) Test(org.junit.jupiter.api.Test)

Example 12 with Id

use of com.hedera.services.store.models.Id in project hedera-services by hashgraph.

the class FixedFeeSpecTest method validationRequiresAssociatedFeeCollector.

@Test
void validationRequiresAssociatedFeeCollector() {
    given(tokenStore.loadTokenOrFailWith(new Id(0, 0, otherDenom.num()), INVALID_TOKEN_ID_IN_CUSTOM_FEES)).willReturn(token);
    given(token.isFungibleCommon()).willReturn(true);
    final var otherDenomSubject = new FixedFeeSpec(123, otherDenom);
    assertFailsWith(() -> otherDenomSubject.validateWith(feeCollector, tokenStore), TOKEN_NOT_ASSOCIATED_TO_FEE_COLLECTOR);
}
Also used : Id(com.hedera.services.store.models.Id) Test(org.junit.jupiter.api.Test)

Example 13 with Id

use of com.hedera.services.store.models.Id in project hedera-services by hashgraph.

the class FixedFeeSpecTest method validationRequiresFungibleDenom.

@Test
void validationRequiresFungibleDenom() {
    given(tokenStore.loadTokenOrFailWith(new Id(0, 0, otherDenom.num()), INVALID_TOKEN_ID_IN_CUSTOM_FEES)).willReturn(token);
    final var otherDenomSubject = new FixedFeeSpec(123, otherDenom);
    assertFailsWith(() -> otherDenomSubject.validateWith(feeCollector, tokenStore), CUSTOM_FEE_DENOMINATION_MUST_BE_FUNGIBLE_COMMON);
}
Also used : Id(com.hedera.services.store.models.Id) Test(org.junit.jupiter.api.Test)

Example 14 with Id

use of com.hedera.services.store.models.Id in project hedera-services by hashgraph.

the class ContractCallTransitionLogicTest method verifyExternaliseContractResultCall.

@Test
void verifyExternaliseContractResultCall() {
    // setup:
    givenValidTxnCtx();
    // and:
    given(accessor.getTxn()).willReturn(contractCallTxn);
    given(txnCtx.accessor()).willReturn(accessor);
    // and:
    given(accountStore.loadAccount(senderAccount.getId())).willReturn(senderAccount);
    given(accountStore.loadContract(new Id(target.getShardNum(), target.getRealmNum(), target.getContractNum()))).willReturn(contractAccount);
    // and:
    var results = TransactionProcessingResult.successful(null, 1234L, 0L, 124L, Bytes.EMPTY, contractAccount.getId().asEvmAddress(), Map.of());
    given(evmTxProcessor.execute(senderAccount, contractAccount.getId().asEvmAddress(), gas, sent, Bytes.EMPTY, txnCtx.consensusTime())).willReturn(results);
    given(worldState.persistProvisionalContractCreations()).willReturn(List.of(target));
    // when:
    subject.doStateTransition();
    // then:
    verify(recordService).externaliseEvmCallTransaction(any());
    verify(worldState).persistProvisionalContractCreations();
    verify(txnCtx).setTargetedContract(target);
}
Also used : Id(com.hedera.services.store.models.Id) Test(org.junit.jupiter.api.Test)

Example 15 with Id

use of com.hedera.services.store.models.Id in project hedera-services by hashgraph.

the class CryptoApproveAllowanceTransitionLogic method doStateTransition.

@Override
public void doStateTransition() {
    /* --- Extract gRPC --- */
    final TransactionBody cryptoApproveAllowanceTxn = txnCtx.accessor().getTxn();
    final AccountID payer = cryptoApproveAllowanceTxn.getTransactionID().getAccountID();
    final var op = cryptoApproveAllowanceTxn.getCryptoApproveAllowance();
    entitiesChanged.clear();
    /* --- Use models --- */
    final Id payerId = Id.fromGrpcAccount(payer);
    final var payerAccount = accountStore.loadAccount(payerId);
    /* --- Do the business logic --- */
    applyCryptoAllowances(op.getCryptoAllowancesList(), payerAccount);
    applyFungibleTokenAllowances(op.getTokenAllowancesList(), payerAccount);
    applyNftAllowances(op.getNftAllowancesList(), payerAccount);
    /* --- Persist the payer 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)

Aggregations

Id (com.hedera.services.store.models.Id)17 Test (org.junit.jupiter.api.Test)13 NftId (com.hedera.services.store.models.NftId)3 FcTokenAllowanceId (com.hedera.services.state.submerkle.FcTokenAllowanceId)2 Account (com.hedera.services.store.models.Account)2 Token (com.hedera.services.store.models.Token)2 AccountID (com.hederahashgraph.api.proto.java.AccountID)2 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)2 Code (org.hyperledger.besu.evm.Code)2 ByteString (com.google.protobuf.ByteString)1 MerkleToken (com.hedera.services.state.merkle.MerkleToken)1 MerkleUniqueToken (com.hedera.services.state.merkle.MerkleUniqueToken)1 EntityId (com.hedera.services.state.submerkle.EntityId)1 RichInstant (com.hedera.services.state.submerkle.RichInstant)1 TokenRelationship (com.hedera.services.store.models.TokenRelationship)1 UniqueToken (com.hedera.services.store.models.UniqueToken)1 EntityNumPair.fromNftId (com.hedera.services.utils.EntityNumPair.fromNftId)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Bytes (org.apache.tuweni.bytes.Bytes)1