Search in sources :

Example 21 with TransactionBody

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

the class EntityRecordItemListenerContractTest method assertPartialContractCallResult.

private void assertPartialContractCallResult(ContractCallTransactionBody transactionBody, TransactionRecord record) {
    long consensusTimestamp = DomainUtils.timestampInNanosMax(record.getConsensusTimestamp());
    ContractFunctionResult result = record.getContractCallResult();
    ObjectAssert<ContractResult> contractResult = assertThat(contractResultRepository.findAll()).filteredOn(c -> c.getConsensusTimestamp().equals(consensusTimestamp)).hasSize(1).first().returns(transactionBody.getAmount(), ContractResult::getAmount).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(EntityId.of(transactionBody.getContractID()), ContractResult::getContractId).returns(toBytes(transactionBody.getFunctionParameters()), ContractResult::getFunctionParameters).returns(transactionBody.getGas(), ContractResult::getGasLimit);
    assertPartialContractResult(contractResult);
}
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) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult)

Example 22 with TransactionBody

use of com.hederahashgraph.api.proto.java.TransactionBody 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 23 with TransactionBody

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

the class EntityRecordItemListenerContractTest method contractCallFailedWithResult.

@Test
void contractCallFailedWithResult() {
    RecordItem recordItem = recordItemBuilder.contractCall().record(r -> r.setContractCreateResult(ContractFunctionResult.getDefaultInstance())).receipt(r -> r.clearContractID().setStatus(ResponseCodeEnum.CONTRACT_EXECUTION_EXCEPTION)).build();
    var record = recordItem.getRecord();
    var transactionBody = recordItem.getTransactionBody();
    parseRecordItemAndCommit(recordItem);
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(), () -> assertFailedContractCallTransaction(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 24 with TransactionBody

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

the class EntityRecordItemListenerContractTest method contractCallToNew.

@ParameterizedTest
@EnumSource(ContractIdType.class)
void contractCallToNew(ContractIdType contractIdType) {
    // The contract is not in db, it should still work. Note for the create2 evm address,
    // ContractCallTransactionHandler will get the correct plain contractId from the transaction record instead
    // only cache the create2 evm address to verify it later
    SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, false, contractIdType == ContractIdType.CREATE2_EVM);
    Transaction transaction = contractCallTransaction(setupResult.protoContractId);
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.CALL);
    ContractCallTransactionBody contractCallTransactionBody = transactionBody.getContractCall();
    RecordItem recordItem = new RecordItem(transaction, record);
    parseRecordItemAndCommit(recordItem);
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(EntityId.of(CREATED_CONTRACT_ID)), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractCallResult(contractCallTransactionBody, record));
}
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) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with TransactionBody

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

the class EntityRecordItemListenerContractTest method contractCallToExisting.

@ParameterizedTest
@EnumSource(ContractIdType.class)
void contractCallToExisting(ContractIdType contractIdType) {
    SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true);
    // now call
    Transaction transaction = contractCallTransaction(setupResult.protoContractId);
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.CALL);
    ContractCallTransactionBody contractCallTransactionBody = transactionBody.getContractCall();
    RecordItem recordItem = new RecordItem(transaction, record);
    parseRecordItemAndCommit(recordItem);
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(EntityId.of(CONTRACT_ID), EntityId.of(CREATED_CONTRACT_ID)), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractCallResult(contractCallTransactionBody, record), () -> assertThat(contractRepository.findAll()).contains(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) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)145 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)106 Test (org.junit.jupiter.api.Test)100 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)96 Transaction (com.hederahashgraph.api.proto.java.Transaction)91 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)91 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)34 AccountID (com.hederahashgraph.api.proto.java.AccountID)32 EnumSource (org.junit.jupiter.params.provider.EnumSource)32 EntityId (com.hedera.mirror.common.domain.entity.EntityId)31 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)31 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)31 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)31 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)31 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)31 Entity (com.hedera.mirror.common.domain.entity.Entity)29 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)29 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)28 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)28 Contract (com.hedera.mirror.common.domain.contract.Contract)27