Search in sources :

Example 36 with Contract

use of com.hedera.mirror.common.domain.contract.Contract 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 37 with Contract

use of com.hedera.mirror.common.domain.contract.Contract 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)

Example 38 with Contract

use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerCryptoTest method cryptoTransferWithEvmAddressAlias.

@Test
void cryptoTransferWithEvmAddressAlias() {
    Contract contract = domainBuilder.contract().persist();
    assertThat(contractRepository.findByEvmAddress(contract.getEvmAddress())).isPresent();
    entityProperties.getPersist().setNonFeeTransfers(true);
    long transferAmount = 123;
    var transfer1 = accountAliasAmount(DomainUtils.fromBytes(contract.getEvmAddress()), transferAmount).build();
    Transaction transaction = buildTransaction(builder -> builder.getCryptoTransferBuilder().getTransfersBuilder().addAccountAmounts(transfer1));
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord transactionRecord = transactionRecordSuccess(transactionBody);
    RecordItem recordItem = new RecordItem(transaction, transactionRecord);
    parseRecordItemAndCommit(recordItem);
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, nonFeeTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, transactionRecord), () -> assertThat(findNonFeeTransfers()).allSatisfy(nonFeeTransfer -> {
        assertThat(nonFeeTransfer.getEntityId()).isEqualTo(contract.toEntityId());
        assertThat(nonFeeTransfer.getAmount()).isEqualTo(transferAmount);
        assertThat(nonFeeTransfer.getPayerAccountId()).isEqualTo(recordItem.getPayerAccountId());
    }));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) CryptoAllowanceRepository(com.hedera.mirror.importer.repository.CryptoAllowanceRepository) EntityId(com.hedera.mirror.common.domain.entity.EntityId) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) ContractRepository(com.hedera.mirror.importer.repository.ContractRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) KeyList(com.hederahashgraph.api.proto.java.KeyList) NftAllowanceRepository(com.hedera.mirror.importer.repository.NftAllowanceRepository) TestUtils(com.hedera.mirror.importer.TestUtils) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) Collection(java.util.Collection) Resource(javax.annotation.Resource) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) Nft(com.hedera.mirror.common.domain.token.Nft) RealmID(com.hederahashgraph.api.proto.java.RealmID) Stream(java.util.stream.Stream) ShardID(com.hederahashgraph.api.proto.java.ShardID) NftRemoveAllowance(com.hederahashgraph.api.proto.java.NftRemoveAllowance) StakingRewardTransfer(com.hedera.mirror.common.domain.transaction.StakingRewardTransfer) Optional(java.util.Optional) AccountIdConverter(com.hedera.mirror.common.converter.AccountIdConverter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) ErrataType(com.hedera.mirror.common.domain.transaction.ErrataType) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) NftId(com.hedera.mirror.common.domain.token.NftId) CsvSource(org.junit.jupiter.params.provider.CsvSource) Contract(com.hedera.mirror.common.domain.contract.Contract) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) BoolValue(com.google.protobuf.BoolValue) HashMap(java.util.HashMap) EnumSource(org.junit.jupiter.params.provider.EnumSource) NftAllowance(com.hederahashgraph.api.proto.java.NftAllowance) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) LinkedList(java.util.LinkedList) AccountID(com.hederahashgraph.api.proto.java.AccountID) LiveHash(com.hedera.mirror.common.domain.transaction.LiveHash) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) TransferList(com.hederahashgraph.api.proto.java.TransferList) NftRepository(com.hedera.mirror.importer.repository.NftRepository) TokenAllowanceRepository(com.hedera.mirror.importer.repository.TokenAllowanceRepository) Int32Value(com.google.protobuf.Int32Value) IterableAssert(org.assertj.core.api.IterableAssert) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) DisplayName(org.junit.jupiter.api.DisplayName) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) Assertions(org.junit.jupiter.api.Assertions) Condition(org.assertj.core.api.Condition) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) Contract(com.hedera.mirror.common.domain.contract.Contract) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with Contract

use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.

the class CompositeBatchPersisterTest method persist.

@Test
@Transactional
void persist() {
    Contract contract = domainBuilder.contract().get();
    ContractResult contractResult = domainBuilder.contractResult().get();
    compositeBatchInserter.persist(List.of(contract));
    compositeBatchInserter.persist(List.of(contractResult));
    assertThat(contractRepository.findAll()).containsExactly(contract);
    assertThat(contractResultRepository.findAll()).containsExactly(contractResult);
}
Also used : ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) Contract(com.hedera.mirror.common.domain.contract.Contract) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with Contract

use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method contractDeleteToNew.

@ParameterizedTest
@EnumSource(value = ContractIdType.class, names = { "PLAIN", "PARSABLE_EVM" })
void contractDeleteToNew(ContractIdType contractIdType) {
    // The contract is not in db, it should still work for PLAIN and PARSABLE_EVM
    SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, false, false);
    Transaction transaction = contractDeleteTransaction(setupResult.protoContractId, false);
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.DELETE);
    RecordItem recordItem = new RecordItem(transaction, record);
    parseRecordItemAndCommit(recordItem);
    Contract contract = getTransactionEntity(record.getConsensusTimestamp());
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(EntityId.of(CONTRACT_ID)), () -> assertTransactionAndRecord(transactionBody, record), () -> assertThat(contract).isNotNull().returns(true, Contract::getDeleted).returns(recordItem.getConsensusTimestamp(), Contract::getTimestampLower).returns(null, Contract::getAutoRenewPeriod).returns(null, Contract::getExpirationTimestamp).returns(null, Contract::getKey).returns(EntityId.of(PAYER), Contract::getObtainerId).returns(null, Contract::getProxyAccountId));
}
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) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) Contract(com.hedera.mirror.common.domain.contract.Contract) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Contract (com.hedera.mirror.common.domain.contract.Contract)49 Test (org.junit.jupiter.api.Test)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 EntityId (com.hedera.mirror.common.domain.entity.EntityId)21 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)18 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)18 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)17 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)16 Assertions (org.junit.jupiter.api.Assertions)16 DomainUtils (com.hedera.mirror.common.util.DomainUtils)15 AccountID (com.hederahashgraph.api.proto.java.AccountID)15 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)13 ContractID (com.hederahashgraph.api.proto.java.ContractID)13 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)13 Entity (com.hedera.mirror.common.domain.entity.Entity)12 AliasNotFoundException (com.hedera.mirror.importer.exception.AliasNotFoundException)12 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)12 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12