Search in sources :

Example 6 with Id

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

the class ContractCallTransitionLogicTest method verifyProcessorCallingWithCorrectCallData.

@Test
void verifyProcessorCallingWithCorrectCallData() {
    // setup:
    ByteString functionParams = ByteString.copyFromUtf8("0x00120");
    var op = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setContractCall(ContractCallTransactionBody.newBuilder().setGas(gas).setAmount(sent).setFunctionParameters(functionParams).setContractID(target));
    contractCallTxn = op.build();
    // 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.fromHexString(CommonUtils.hex(functionParams.toByteArray())), txnCtx.consensusTime())).willReturn(results);
    given(worldState.persistProvisionalContractCreations()).willReturn(List.of(target));
    // when:
    subject.doStateTransition();
    // then:
    verify(evmTxProcessor).execute(senderAccount, contractAccount.getId().asEvmAddress(), gas, sent, Bytes.fromHexString(CommonUtils.hex(functionParams.toByteArray())), txnCtx.consensusTime());
    verify(sigImpactHistorian).markEntityChanged(target.getContractNum());
}
Also used : ByteString(com.google.protobuf.ByteString) Id(com.hedera.services.store.models.Id) Test(org.junit.jupiter.api.Test)

Example 7 with Id

use of com.hedera.services.store.models.Id 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 8 with Id

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

the class EntityIdTest method idConstructorWorks.

@Test
void idConstructorWorks() {
    Id id = IdUtils.asModelId("1.2.3");
    var subject = new EntityId(id);
    assertEquals(id.shard(), subject.shard());
    assertEquals(id.realm(), subject.realm());
    assertEquals(id.num(), subject.num());
    assertTrue(subject.matches(id));
}
Also used : Id(com.hedera.services.store.models.Id) Test(org.junit.jupiter.api.Test)

Example 9 with Id

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

the class FixedFeeSpecTest method validationWorksWithWellBehaved.

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

Example 10 with Id

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

the class FixedFeeSpecTest method finalizationRequiresFungibleDenomAtCreationWithOtherDenom.

@Test
void finalizationRequiresFungibleDenomAtCreationWithOtherDenom() {
    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.validateAndFinalizeWith(token, feeCollector, tokenStore), CUSTOM_FEE_DENOMINATION_MUST_BE_FUNGIBLE_COMMON);
}
Also used : Id(com.hedera.services.store.models.Id) Test(org.junit.jupiter.api.Test)

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