Search in sources :

Example 1 with RecordItem

use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method contractUpdateAllToExisting.

@ParameterizedTest
@EnumSource(ContractIdType.class)
void contractUpdateAllToExisting(ContractIdType contractIdType) {
    // first create the contract
    SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true, c -> c.obtainerId(null));
    Contract contract = setupResult.contract;
    // now update
    Transaction transaction = contractUpdateAllTransaction(setupResult.protoContractId, true);
    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(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) ContractDeleteTransactionBody(com.hederahashgraph.api.proto.java.ContractDeleteTransactionBody) 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) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with RecordItem

use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method contractCreate.

@Test
void contractCreate() {
    RecordItem recordItem = recordItemBuilder.contractCreate().build();
    var record = recordItem.getRecord();
    var transactionBody = recordItem.getTransactionBody().getContractCreateInstance();
    parseRecordItemAndCommit(recordItem);
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(2, 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 : RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with RecordItem

use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerTopicTest method updateTopicTest.

@ParameterizedTest
@CsvSource({ "0.0.1300, 10, 20, admin-key, submit-key, memo, 11, 21, updated-admin-key, updated-submit-key, " + "updated-memo, 4000000, 1, 30", "0.0.1301, 10, 20, admin-key, submit-key, memo, 11, 21, '', '', '', 4000001, 1, 30", "0.0.1302, 0, 0, '', '', '', 11, 21, updated-admin-key, updated-submit-key, updated-memo, 4000002, ," })
void updateTopicTest(@ConvertWith(TopicIdArgumentConverter.class) TopicID topicId, long expirationTimeSeconds, int expirationTimeNanos, @ConvertWith(KeyConverter.class) Key adminKey, @ConvertWith(KeyConverter.class) Key submitKey, String memo, long updatedExpirationTimeSeconds, int updatedExpirationTimeNanos, @ConvertWith(KeyConverter.class) Key updatedAdminKey, @ConvertWith(KeyConverter.class) Key updatedSubmitKey, String updatedMemo, long consensusTimestamp, Long autoRenewAccountId, Long autoRenewPeriod) {
    // Store topic to be updated.
    var topic = createTopicEntity(topicId, expirationTimeSeconds, expirationTimeNanos, adminKey, submitKey, memo, autoRenewAccountId, autoRenewPeriod);
    entityRepository.save(topic);
    var responseCode = SUCCESS;
    var transaction = createUpdateTopicTransaction(topicId, updatedExpirationTimeSeconds, updatedExpirationTimeNanos, updatedAdminKey, updatedSubmitKey, updatedMemo, autoRenewAccountId, autoRenewPeriod);
    var transactionRecord = createTransactionRecord(topicId, consensusTimestamp, responseCode);
    var expectedEntity = createTopicEntity(topicId, updatedExpirationTimeSeconds, updatedExpirationTimeNanos, updatedAdminKey, updatedSubmitKey, updatedMemo, autoRenewAccountId, autoRenewPeriod);
    expectedEntity.setDeleted(false);
    expectedEntity.setTimestampLower(consensusTimestamp);
    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));
    var entity = getTopicEntity(topicId);
    assertTransactionInRepository(responseCode, consensusTimestamp, entity.getId());
    assertEntity(expectedEntity);
    assertEquals(1L, entityRepository.count());
}
Also used : RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with RecordItem

use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method contractDeleteToNewCreate2EvmAddress.

@Test
void contractDeleteToNewCreate2EvmAddress() {
    SetupResult setupResult = setupContract(CONTRACT_ID, ContractIdType.CREATE2_EVM, 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);
    var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(setupResult.contract.toEntityId()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertThat(dbTransaction.getEntityId()).isEqualTo(setupResult.contract.toEntityId()));
}
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) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with RecordItem

use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerContractTest method contractCallTokenPrecompiles.

@Test
void contractCallTokenPrecompiles() {
    // given
    RecordItem recordItemCall = recordItemBuilder.contractCall().build();
    parseRecordItemAndCommit(recordItemCall);
    var parentConsensusTimestamp = recordItemCall.getRecord().getConsensusTimestamp();
    var parentTransactionId = recordItemCall.getTransactionBody().getTransactionID();
    var childTransactionId = parentTransactionId.toBuilder().setNonce(1).build();
    var payerAccount = recordItemCall.getPayerAccountId();
    var validStart = DomainUtils.timeStampInNanos(parentTransactionId.getTransactionValidStart());
    // when
    RecordItem recordItemMint = recordItemBuilder.tokenMint(TokenType.FUNGIBLE_COMMON).transactionBodyWrapper(b -> b.setTransactionID(childTransactionId)).record(r -> r.setParentConsensusTimestamp(parentConsensusTimestamp)).build();
    parseRecordItemAndCommit(recordItemMint);
    // then
    assertEquals(2, transactionRepository.count());
    assertThat(transactionRepository.findById(recordItemCall.getConsensusTimestamp())).get().returns(payerAccount, com.hedera.mirror.common.domain.transaction.Transaction::getPayerAccountId).returns(validStart, com.hedera.mirror.common.domain.transaction.Transaction::getValidStartNs).returns(0, com.hedera.mirror.common.domain.transaction.Transaction::getNonce).returns(null, com.hedera.mirror.common.domain.transaction.Transaction::getParentConsensusTimestamp);
    assertThat(transactionRepository.findById(recordItemMint.getConsensusTimestamp())).get().returns(payerAccount, com.hedera.mirror.common.domain.transaction.Transaction::getPayerAccountId).returns(validStart, com.hedera.mirror.common.domain.transaction.Transaction::getValidStartNs).returns(1, com.hedera.mirror.common.domain.transaction.Transaction::getNonce).returns(recordItemCall.getConsensusTimestamp(), com.hedera.mirror.common.domain.transaction.Transaction::getParentConsensusTimestamp);
}
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) Transaction(com.hederahashgraph.api.proto.java.Transaction) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)182 Test (org.junit.jupiter.api.Test)131 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)131 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)108 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)95 Transaction (com.hederahashgraph.api.proto.java.Transaction)94 EntityId (com.hedera.mirror.common.domain.entity.EntityId)42 DomainUtils (com.hedera.mirror.common.util.DomainUtils)36 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)36 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)36 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)34 EnumSource (org.junit.jupiter.params.provider.EnumSource)34 Entity (com.hedera.mirror.common.domain.entity.Entity)31 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)31 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)29 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)29 AccountID (com.hederahashgraph.api.proto.java.AccountID)28 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)28 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)28 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)28