Search in sources :

Example 51 with AccountID

use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.

the class ExtCodeCopyOperationSuite method verifiesExistence.

HapiApiSpec verifiesExistence() {
    final String CONTRACT = "extCodeCopyOpChecker";
    final String INVALID_ADDRESS = "0x0000000000000000000000000000000000123456";
    ByteString EMPTY_BYTECODE = ByteString.EMPTY;
    return defaultHapiSpec("VerifiesExistence").given(fileCreate("bytecode").path(ContractResources.EXT_CODE_OPERATIONS_CHECKER_CONTRACT), contractCreate("extCodeCopyOpChecker").bytecode("bytecode").gas(300_000L)).when().then(contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, INVALID_ADDRESS).hasKnownStatus(INVALID_SOLIDITY_ADDRESS), contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, INVALID_ADDRESS).hasAnswerOnlyPrecheck(INVALID_SOLIDITY_ADDRESS), withOpContext((spec, opLog) -> {
        AccountID accountID = spec.registry().getAccountID(DEFAULT_PAYER);
        ContractID contractID = spec.registry().getContractId(CONTRACT);
        String accountSolidityAddress = asHexedSolidityAddress(accountID);
        String contractAddress = asHexedSolidityAddress(contractID);
        final var call = contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, accountSolidityAddress).via("callRecord");
        final var callRecord = getTxnRecord("callRecord");
        final var accountCodeCallLocal = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, accountSolidityAddress).saveResultTo("accountCode");
        final var contractCodeCallLocal = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_CODE_COPY_OF, contractAddress).saveResultTo("contractCode");
        final var getBytecodeCall = getContractBytecode(CONTRACT).saveResultTo("contractGetBytecode");
        allRunFor(spec, call, callRecord, accountCodeCallLocal, contractCodeCallLocal, getBytecodeCall);
        final var recordResult = callRecord.getResponseRecord().getContractCallResult();
        final var accountCode = spec.registry().getBytes("accountCode");
        final var contractCode = spec.registry().getBytes("contractCode");
        final var getBytecode = spec.registry().getBytes("contractGetBytecode");
        Assertions.assertEquals(EMPTY_BYTECODE, recordResult.getContractCallResult());
        Assertions.assertArrayEquals(EMPTY_BYTECODE.toByteArray(), accountCode);
        Assertions.assertArrayEquals(getBytecode, contractCode);
    }));
}
Also used : UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) ByteString(com.google.protobuf.ByteString) ContractID(com.hederahashgraph.api.proto.java.ContractID) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) Assertions(org.junit.jupiter.api.Assertions) QueryVerbs.contractCallLocal(com.hedera.services.bdd.spec.queries.QueryVerbs.contractCallLocal) INVALID_SOLIDITY_ADDRESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS) HapiPropertySource.asHexedSolidityAddress(com.hedera.services.bdd.spec.HapiPropertySource.asHexedSolidityAddress) QueryVerbs.getContractBytecode(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractBytecode) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) AccountID(com.hederahashgraph.api.proto.java.AccountID) LogManager(org.apache.logging.log4j.LogManager) AccountID(com.hederahashgraph.api.proto.java.AccountID) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 52 with AccountID

use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.

the class ExtCodeHashOperationSuite method verifiesExistence.

HapiApiSpec verifiesExistence() {
    final String CONTRACT = "extCodeHashOpChecker";
    final String INVALID_ADDRESS = "0x0000000000000000000000000000000000123456";
    final ByteString EXPECTED_ACCOUNT_HASH = ByteString.copyFrom(Hash.keccak256(Bytes.EMPTY).toArray());
    return defaultHapiSpec("VerifiesExistence").given(fileCreate("bytecode").path(ContractResources.EXT_CODE_OPERATIONS_CHECKER_CONTRACT), contractCreate(CONTRACT).bytecode("bytecode").gas(300_000L)).when().then(contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, INVALID_ADDRESS).hasKnownStatus(INVALID_SOLIDITY_ADDRESS), contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, INVALID_ADDRESS).hasAnswerOnlyPrecheck(INVALID_SOLIDITY_ADDRESS), withOpContext((spec, opLog) -> {
        AccountID accountID = spec.registry().getAccountID(DEFAULT_PAYER);
        ContractID contractID = spec.registry().getContractId(CONTRACT);
        String accountSolidityAddress = asHexedSolidityAddress(accountID);
        String contractAddress = asHexedSolidityAddress(contractID);
        final var call = contractCall(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, accountSolidityAddress).via("callRecord");
        final var callRecord = getTxnRecord("callRecord");
        final var accountCodeHashCallLocal = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, accountSolidityAddress).saveResultTo("accountCodeHash");
        final var contractCodeHash = contractCallLocal(CONTRACT, ContractResources.EXT_CODE_OP_CHECKER_HASH_OF, contractAddress).saveResultTo("contractCodeHash");
        final var getBytecode = getContractBytecode(CONTRACT).saveResultTo("contractBytecode");
        allRunFor(spec, call, callRecord, accountCodeHashCallLocal, contractCodeHash, getBytecode);
        final var recordResult = callRecord.getResponseRecord().getContractCallResult();
        final var accountCodeHash = spec.registry().getBytes("accountCodeHash");
        final var contractCodeResult = spec.registry().getBytes("contractCodeHash");
        final var contractBytecode = spec.registry().getBytes("contractBytecode");
        final var expectedContractCodeHash = ByteString.copyFrom(Hash.keccak256(Bytes.of(contractBytecode)).toArray()).toByteArray();
        Assertions.assertEquals(EXPECTED_ACCOUNT_HASH, recordResult.getContractCallResult());
        Assertions.assertArrayEquals(EXPECTED_ACCOUNT_HASH.toByteArray(), accountCodeHash);
        Assertions.assertArrayEquals(expectedContractCodeHash, contractCodeResult);
    }));
}
Also used : UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) TxnVerbs.contractCall(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCall) Bytes(org.apache.tuweni.bytes.Bytes) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) ContractResources(com.hedera.services.bdd.spec.infrastructure.meta.ContractResources) Hash(org.hyperledger.besu.crypto.Hash) ByteString(com.google.protobuf.ByteString) ContractID(com.hederahashgraph.api.proto.java.ContractID) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) Assertions(org.junit.jupiter.api.Assertions) QueryVerbs.contractCallLocal(com.hedera.services.bdd.spec.queries.QueryVerbs.contractCallLocal) INVALID_SOLIDITY_ADDRESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SOLIDITY_ADDRESS) HapiPropertySource.asHexedSolidityAddress(com.hedera.services.bdd.spec.HapiPropertySource.asHexedSolidityAddress) QueryVerbs.getContractBytecode(com.hedera.services.bdd.spec.queries.QueryVerbs.getContractBytecode) TxnVerbs.contractCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.contractCreate) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) AccountID(com.hederahashgraph.api.proto.java.AccountID) LogManager(org.apache.logging.log4j.LogManager) AccountID(com.hederahashgraph.api.proto.java.AccountID) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 53 with AccountID

use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.

the class StakedAnswerFlow method systemScreen.

private ResponseCodeEnum systemScreen(final HederaFunctionality function, @Nullable final SignedTxnAccessor payment, final Query query) {
    AccountID payer = null;
    if (null != payment) {
        payer = payment.getPayer();
        final var permissionStatus = hapiOpPermissions.permissibilityOf(function, payer);
        if (permissionStatus != OK) {
            return permissionStatus;
        }
    }
    if (payer == null && RESTRICTED_FUNCTIONALITIES.contains(function)) {
        return NOT_SUPPORTED;
    } else if (payer == null || !IS_THROTTLE_EXEMPT.test(payer.getAccountNum())) {
        return throttles.shouldThrottleQuery(function, query) ? BUSY : OK;
    } else {
        return OK;
    }
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID)

Example 54 with AccountID

use of com.hederahashgraph.api.proto.java.AccountID 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)

Example 55 with AccountID

use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.

the class CryptoDeleteTransitionLogic method doStateTransition.

@Override
public void doStateTransition() {
    try {
        CryptoDeleteTransactionBody op = txnCtx.accessor().getTxn().getCryptoDelete();
        AccountID id = op.getDeleteAccountID();
        if (ledger.isKnownTreasury(id)) {
            txnCtx.setStatus(ACCOUNT_IS_TREASURY);
            return;
        }
        AccountID beneficiary = op.getTransferAccountID();
        if (ledger.isDetached(id) || ledger.isDetached(beneficiary)) {
            txnCtx.setStatus(ACCOUNT_EXPIRED_AND_PENDING_REMOVAL);
            return;
        }
        if (!ledger.allTokenBalancesVanish(id)) {
            txnCtx.setStatus(TRANSACTION_REQUIRES_ZERO_TOKEN_BALANCES);
            return;
        }
        ledger.delete(id, beneficiary);
        sigImpactHistorian.markEntityChanged(id.getAccountNum());
        txnCtx.setStatus(SUCCESS);
    } catch (MissingAccountException mae) {
        txnCtx.setStatus(INVALID_ACCOUNT_ID);
    } catch (DeletedAccountException dae) {
        txnCtx.setStatus(ACCOUNT_DELETED);
    } catch (Exception e) {
        log.warn("Avoidable exception!", e);
        txnCtx.setStatus(FAIL_INVALID);
    }
}
Also used : AccountID(com.hederahashgraph.api.proto.java.AccountID) MissingAccountException(com.hedera.services.exceptions.MissingAccountException) CryptoDeleteTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteTransactionBody) DeletedAccountException(com.hedera.services.exceptions.DeletedAccountException) MissingAccountException(com.hedera.services.exceptions.MissingAccountException) DeletedAccountException(com.hedera.services.exceptions.DeletedAccountException)

Aggregations

AccountID (com.hederahashgraph.api.proto.java.AccountID)71 Test (org.junit.jupiter.api.Test)24 List (java.util.List)21 ByteString (com.google.protobuf.ByteString)20 Assertions (org.junit.jupiter.api.Assertions)20 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)17 LogManager (org.apache.logging.log4j.LogManager)17 Logger (org.apache.logging.log4j.Logger)17 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)16 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)15 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)15 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)15 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)14 TransactionRecordAsserts.recordWith (com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith)13 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)13 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)13 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)13 TxnVerbs.mintToken (com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken)13 HapiSpecSetup (com.hedera.services.bdd.spec.HapiSpecSetup)12 QueryVerbs.getScheduleInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getScheduleInfo)12