Search in sources :

Example 6 with Contract

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

the class EntityRecordItemListenerContractTest method contractUpdateAllWithMemoToNew.

@Test
void contractUpdateAllWithMemoToNew() {
    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(null, Contract::getCreatedTimestamp).returns(null, // 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) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) Contract(com.hedera.mirror.common.domain.contract.Contract) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with Contract

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

the class EntityRecordItemListenerContractTest method contractCreateWithEvmAddress.

@Test
void contractCreateWithEvmAddress() {
    // no child tx, creates a single contract with evm address set
    byte[] evmAddress = domainBuilder.evmAddress();
    RecordItem recordItem = recordItemBuilder.contractCreate(CONTRACT_ID).transactionBody(t -> t.setDeclineReward(false).setStakedNodeId(1L)).record(r -> r.setContractCreateResult(r.getContractCreateResultBuilder().clearCreatedContractIDs().addCreatedContractIDs(CONTRACT_ID).setEvmAddress(BytesValue.of(DomainUtils.fromBytes(evmAddress))))).hapiVersion(RecordFile.HAPI_VERSION_0_23_0).build();
    var record = recordItem.getRecord();
    var transactionBody = recordItem.getTransactionBody().getContractCreateInstance();
    parseRecordItemAndCommit(recordItem);
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractRepository.count()), () -> assertEquals(0, entityRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertContractEntity(recordItem), () -> assertThat(contractResultRepository.findAll()).hasSize(1), () -> assertContractCreateResult(transactionBody, record));
}
Also used : 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) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with Contract

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

the class EntityRecordItemListenerContractTest method contractDeleteToExisting.

@ParameterizedTest
@CsvSource({ "PLAIN, false", "PARSABLE_EVM,true", "CREATE2_EVM,false" })
void contractDeleteToExisting(ContractIdType contractIdType, boolean permanentRemoval) {
    SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true);
    Transaction transaction = contractDeleteTransaction(setupResult.protoContractId, permanentRemoval);
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.DELETE);
    RecordItem recordItem = new RecordItem(transaction, record);
    parseRecordItemAndCommit(recordItem);
    Contract dbContractEntity = getTransactionEntity(record.getConsensusTimestamp());
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(setupResult.contract.toEntityId()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertThat(dbContractEntity).isNotNull().returns(true, Contract::getDeleted).returns(EntityId.of(PAYER), Contract::getObtainerId).returns(permanentRemoval, Contract::getPermanentRemoval).returns(Range.atLeast(recordItem.getConsensusTimestamp()), Contract::getTimestampRange).usingRecursiveComparison().ignoringFields("deleted", "obtainerId", "permanentRemoval", "timestampRange").isEqualTo(setupResult.contract));
}
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) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with Contract

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

the class EntityRecordItemListenerContractTest method assertContractEntity.

private ObjectAssert<Contract> assertContractEntity(ContractUpdateTransactionBody expected, Timestamp consensusTimestamp) {
    Contract contract = getTransactionEntity(consensusTimestamp);
    long updatedTimestamp = DomainUtils.timeStampInNanos(consensusTimestamp);
    var adminKey = expected.getAdminKey().toByteArray();
    var expectedMaxAutomaticTokenAssociations = expected.hasMaxAutomaticTokenAssociations() ? expected.getMaxAutomaticTokenAssociations().getValue() : null;
    var contractAssert = assertThat(contract).isNotNull().returns(expected.getAutoRenewPeriod().getSeconds(), Contract::getAutoRenewPeriod).returns(false, Contract::getDeleted).returns(DomainUtils.timeStampInNanos(expected.getExpirationTime()), Contract::getExpirationTimestamp).returns(adminKey, Contract::getKey).returns(expectedMaxAutomaticTokenAssociations, Contract::getMaxAutomaticTokenAssociations).returns(getMemoFromContractUpdateTransactionBody(expected), Contract::getMemo).returns(updatedTimestamp, Contract::getTimestampLower).returns(null, Contract::getObtainerId).returns(EntityId.of(expected.getProxyAccountID()), Contract::getProxyAccountId).returns(DomainUtils.getPublicKey(adminKey), Contract::getPublicKey).returns(EntityType.CONTRACT, Contract::getType).returns(expected.getDeclineReward().getValue(), Contract::isDeclineReward);
    if (expected.getStakedIdCase() == STAKEDID_NOT_SET) {
        return contractAssert;
    }
    if (expected.hasStakedAccountId()) {
        long expectedAccountId = AccountIdConverter.INSTANCE.convertToDatabaseColumn(EntityId.of(expected.getStakedAccountId()));
        contractAssert.returns(expectedAccountId, Contract::getStakedAccountId).returns(null, Contract::getStakedNodeId).returns(-1L, Contract::getStakePeriodStart);
    } else {
        contractAssert.returns(expected.getStakedNodeId(), Contract::getStakedNodeId).returns(null, Contract::getStakedAccountId).returns(Utility.getEpochDay(DomainUtils.timestampInNanosMax(consensusTimestamp)), Contract::getStakePeriodStart);
    }
    return contractAssert;
}
Also used : Contract(com.hedera.mirror.common.domain.contract.Contract)

Example 10 with Contract

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

the class EntityRecordItemListenerContractTest method contractCallToExistingWithPaidStakingRewards.

@Test
void contractCallToExistingWithPaidStakingRewards() {
    // given
    var setupResult = setupContract(CONTRACT_ID, ContractIdType.PLAIN, true, false);
    // 19137 days since epoch
    var timestamp = 1653506322000111222L;
    var stakePeriodStart = 19137L;
    // now call
    var transaction = contractCallTransaction(setupResult.protoContractId);
    var transactionBody = getTransactionBody(transaction);
    var record = getContractTransactionRecord(transactionBody, ContractTransactionType.CALL);
    var contractCallTransactionBody = transactionBody.getContractCall();
    var amount = contractCallTransactionBody.getAmount();
    var contractAccountId = AccountID.newBuilder().setAccountNum(CONTRACT_ID.getContractNum()).build();
    var contractAmount = AccountAmount.newBuilder().setAccountID(contractAccountId).setAmount(// with 15 reward payout
    amount + 15L);
    var stakingRewardAmount = AccountAmount.newBuilder().setAccountID(RecordItemBuilder.STAKING_REWARD_ACCOUNT).setAmount(-15L);
    var transferList = record.getTransferList().toBuilder().addAccountAmounts(contractAmount).addAccountAmounts(stakingRewardAmount);
    var paidRewardTransfer = AccountAmount.newBuilder().setAccountID(contractAccountId).setAmount(15L);
    record = record.toBuilder().setConsensusTimestamp(TestUtils.toTimestamp(timestamp)).setTransferList(transferList).addPaidStakingRewards(paidRewardTransfer).build();
    var recordItem = new RecordItem(transaction, record);
    // when
    parseRecordItemAndCommit(recordItem);
    // then
    var contract = setupResult.contract;
    contract.setStakePeriodStart(stakePeriodStart);
    Contract newContract = EntityId.of(CREATED_CONTRACT_ID).toEntity();
    newContract.setCreatedTimestamp(timestamp);
    newContract.setDeleted(false);
    newContract.setMaxAutomaticTokenAssociations(0);
    newContract.setMemo("");
    newContract.setStakedAccountId(-1L);
    newContract.setStakedNodeId(-1L);
    newContract.setStakePeriodStart(-1L);
    newContract.setTimestampLower(timestamp);
    assertAll(() -> assertEquals(0, entityRepository.count()), () -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(5, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, recordItem.getRecord()), () -> assertContractCallResult(contractCallTransactionBody, recordItem.getRecord()), () -> assertThat(contractRepository.findAll()).containsExactlyInAnyOrder(contract, newContract));
}
Also used : Contract(com.hedera.mirror.common.domain.contract.Contract) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) 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