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