Search in sources :

Example 6 with ContractUpdateTransactionBody

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

the class SmartContractFeeBuilder method getContractUpdateStorageBytesSec.

private long getContractUpdateStorageBytesSec(TransactionBody txBody, Timestamp contractExpiryTime) {
    long storageSize = 0;
    ContractUpdateTransactionBody contractUpdateTxBody = txBody.getContractUpdateInstance();
    if (contractUpdateTxBody.hasAdminKey()) {
        storageSize += getAccountKeyStorageSize(contractUpdateTxBody.getAdminKey());
    }
    if (contractUpdateTxBody.getMemo() != null) {
        storageSize += contractUpdateTxBody.getMemoBytes().size();
    }
    Instant expirationTime = RequestBuilder.convertProtoTimeStamp(contractExpiryTime);
    Timestamp txValidStartTimestamp = txBody.getTransactionID().getTransactionValidStart();
    Instant txValidStartTime = RequestBuilder.convertProtoTimeStamp(txValidStartTimestamp);
    Duration duration = Duration.between(txValidStartTime, expirationTime);
    long seconds = Math.min(duration.getSeconds(), MAX_ENTITY_LIFETIME);
    storageSize = storageSize * seconds;
    return storageSize;
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Timestamp(com.hederahashgraph.api.proto.java.Timestamp)

Example 7 with ContractUpdateTransactionBody

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

the class ContractUpdateResourceUsageTest method setup.

@BeforeEach
private void setup() throws Throwable {
    contractUpdateTxn = mock(TransactionBody.class);
    ContractUpdateTransactionBody update = mock(ContractUpdateTransactionBody.class);
    given(update.getContractID()).willReturn(target);
    given(contractUpdateTxn.hasContractUpdateInstance()).willReturn(true);
    given(contractUpdateTxn.getContractUpdateInstance()).willReturn(update);
    nonContractUpdateTxn = mock(TransactionBody.class);
    given(nonContractUpdateTxn.hasContractUpdateInstance()).willReturn(false);
    account = mock(MerkleAccount.class);
    given(account.getExpiry()).willReturn(Long.MAX_VALUE);
    accounts = mock(MerkleMap.class);
    given(accounts.get(accountKey)).willReturn(account);
    view = mock(StateView.class);
    given(view.accounts()).willReturn(accounts);
    sigUsage = mock(SigValueObj.class);
    usageEstimator = mock(SmartContractFeeBuilder.class);
    subject = new ContractUpdateResourceUsage(usageEstimator);
}
Also used : ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) SmartContractFeeBuilder(com.hederahashgraph.fee.SmartContractFeeBuilder) MerkleMap(com.swirlds.merkle.map.MerkleMap) StateView(com.hedera.services.context.primitives.StateView) MerkleAccount(com.hedera.services.state.merkle.MerkleAccount) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) SigValueObj(com.hederahashgraph.fee.SigValueObj) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with ContractUpdateTransactionBody

use of com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method contractUpdateAllToExisting.

@ParameterizedTest
@CsvSource({ "PLAIN, 5005, 5005", "PARSABLE_EVM, 0, 0", "CREATE2_EVM, , 5002" })
void contractUpdateAllToExisting(ContractIdType contractIdType, Long newAutoRenewAccount, Long expectedAutoRenewAccount) {
    // first create the contract
    SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true, c -> {
        c.obtainerId(null).declineReward(true).stakedAccountId(1L);
        if (newAutoRenewAccount == null) {
            c.autoRenewAccountId(expectedAutoRenewAccount);
        }
    });
    Contract contract = setupResult.contract;
    // now update
    Transaction transaction = contractUpdateAllTransaction(setupResult.protoContractId, true, b -> {
        if (newAutoRenewAccount != null) {
            b.getAutoRenewAccountIdBuilder().setAccountNum(newAutoRenewAccount);
        }
    });
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.UPDATE);
    ContractUpdateTransactionBody contractUpdateTransactionBody = transactionBody.getContractUpdateInstance();
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(setupResult.contract.toEntityId()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractEntity(contractUpdateTransactionBody, record.getConsensusTimestamp()).returns(expectedAutoRenewAccount, Contract::getAutoRenewAccountId).returns(contract.getCreatedTimestamp(), Contract::getCreatedTimestamp).returns(contract.getFileId(), // FileId is ignored on updates by HAPI
    Contract::getFileId));
}
Also used : ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Contract(com.hedera.mirror.common.domain.contract.Contract) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with ContractUpdateTransactionBody

use of com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method contractUpdateAllWithMemoToExisting.

@Test
void contractUpdateAllWithMemoToExisting() {
    // first create the contract
    EntityId contractId = EntityId.of(CONTRACT_ID);
    Contract contract = domainBuilder.contract().customize(c -> c.obtainerId(null).id(contractId.getId()).num(contractId.getEntityNum()).stakedNodeId(1L)).persist();
    // now update
    Transaction transaction = contractUpdateAllTransaction(false);
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.UPDATE);
    ContractUpdateTransactionBody contractUpdateTransactionBody = transactionBody.getContractUpdateInstance();
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(EntityId.of(CONTRACT_ID)), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractEntity(contractUpdateTransactionBody, record.getConsensusTimestamp()).returns(contract.getCreatedTimestamp(), Contract::getCreatedTimestamp).returns(contract.getFileId(), // FileId is ignored on updates by HAPI
    Contract::getFileId));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) DomainUtils.toBytes(com.hedera.mirror.common.util.DomainUtils.toBytes) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringValue(com.google.protobuf.StringValue) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Duration(com.hederahashgraph.api.proto.java.Duration) EntityType(com.hedera.mirror.common.domain.entity.EntityType) ByteBuffer(java.nio.ByteBuffer) ContractID(com.hederahashgraph.api.proto.java.ContractID) Map(java.util.Map) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Version(org.springframework.data.util.Version) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TestUtils(com.hedera.mirror.importer.TestUtils) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) Range(com.google.common.collect.Range) Resource(javax.annotation.Resource) ContractLoginfo(com.hederahashgraph.api.proto.java.ContractLoginfo) Collectors(java.util.stream.Collectors) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) BytesValue(com.google.protobuf.BytesValue) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) STAKEDID_NOT_SET(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody.StakedIdCase.STAKEDID_NOT_SET) ObjectAssert(org.assertj.core.api.ObjectAssert) Optional(java.util.Optional) AccountIdConverter(com.hedera.mirror.common.converter.AccountIdConverter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) CsvSource(org.junit.jupiter.params.provider.CsvSource) Contract(com.hedera.mirror.common.domain.contract.Contract) HashMap(java.util.HashMap) EnumSource(org.junit.jupiter.params.provider.EnumSource) Value(lombok.Value) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) Int32Value(com.google.protobuf.Int32Value) DomainUtils(com.hedera.mirror.common.util.DomainUtils) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) Consumer(java.util.function.Consumer) TokenType(com.hederahashgraph.api.proto.java.TokenType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Assertions(org.junit.jupiter.api.Assertions) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) Collections(java.util.Collections) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Contract(com.hedera.mirror.common.domain.contract.Contract) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)9 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)7 Transaction (com.hederahashgraph.api.proto.java.Transaction)6 Contract (com.hedera.mirror.common.domain.contract.Contract)5 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)5 ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)5 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)5 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Timestamp (com.hederahashgraph.api.proto.java.Timestamp)3 ByteString (com.google.protobuf.ByteString)2 StringValue (com.google.protobuf.StringValue)2 ContractID (com.hederahashgraph.api.proto.java.ContractID)2 Duration (com.hederahashgraph.api.proto.java.Duration)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 CsvSource (org.junit.jupiter.params.provider.CsvSource)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 MoreObjects (com.google.common.base.MoreObjects)1 Range (com.google.common.collect.Range)1 BytesValue (com.google.protobuf.BytesValue)1