Search in sources :

Example 31 with ContractID

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

the class ContractDeleteTransactionHandlerTest method testGetEntityIdReceipt.

@Test
void testGetEntityIdReceipt() {
    var recordItem = recordItemBuilder.contractDelete().build();
    ContractID contractIdBody = recordItem.getTransactionBody().getContractDeleteInstance().getContractID();
    ContractID contractIdReceipt = recordItem.getRecord().getReceipt().getContractID();
    EntityId expectedEntityId = EntityId.of(contractIdReceipt);
    when(entityIdService.lookup(contractIdReceipt, contractIdBody)).thenReturn(expectedEntityId);
    EntityId entityId = transactionHandler.getEntity(recordItem);
    assertThat(entityId).isEqualTo(expectedEntityId);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractID(com.hederahashgraph.api.proto.java.ContractID) Test(org.junit.jupiter.api.Test)

Example 32 with ContractID

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

the class ContractUpdateTransactionHandlerTest method updateTransactionThrowsWithAliasNotFound.

@ParameterizedTest(name = "{0}")
@EnumSource(value = PartialDataAction.class, names = { "DEFAULT", "ERROR" })
void updateTransactionThrowsWithAliasNotFound(PartialDataAction partialDataAction) {
    // given
    recordParserProperties.setPartialDataAction(partialDataAction);
    var alias = DomainUtils.fromBytes(domainBuilder.key());
    var recordItem = recordItemBuilder.contractUpdate().transactionBody(b -> b.getAutoRenewAccountIdBuilder().setAlias(alias)).build();
    var contractId = EntityId.of(recordItem.getRecord().getReceipt().getContractID());
    var timestamp = recordItem.getConsensusTimestamp();
    var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(contractId)).get();
    when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
    // when, then
    assertThrows(AliasNotFoundException.class, () -> transactionHandler.updateTransaction(transaction, recordItem));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Contract(com.hedera.mirror.common.domain.contract.Contract) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) BoolValue(com.google.protobuf.BoolValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) ContractID(com.hederahashgraph.api.proto.java.ContractID) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Assertions(org.junit.jupiter.api.Assertions) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with ContractID

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

the class ContractUpdateTransactionHandlerTest method updateTransactionWithAliasNotFoundAndPartialDataActionSkip.

@Test
void updateTransactionWithAliasNotFoundAndPartialDataActionSkip() {
    recordParserProperties.setPartialDataAction(PartialDataAction.SKIP);
    var alias = DomainUtils.fromBytes(domainBuilder.key());
    var recordItem = recordItemBuilder.contractUpdate().transactionBody(b -> b.getAutoRenewAccountIdBuilder().setAlias(alias)).build();
    var contractId = EntityId.of(recordItem.getRecord().getReceipt().getContractID());
    var timestamp = recordItem.getConsensusTimestamp();
    var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(contractId)).get();
    when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
    transactionHandler.updateTransaction(transaction, recordItem);
    assertContractUpdate(timestamp, contractId, t -> assertThat(t).returns(null, Contract::getAutoRenewAccountId).satisfies(c -> assertThat(c.getAutoRenewPeriod()).isPositive()).satisfies(c -> assertThat(c.getExpirationTimestamp()).isPositive()).satisfies(c -> assertThat(c.getKey()).isNotEmpty()).satisfies(c -> assertThat(c.getMaxAutomaticTokenAssociations()).isPositive()).satisfies(c -> assertThat(c.getMemo()).isNotEmpty()).satisfies(c -> assertThat(c.getPublicKey()).isNotEmpty()).satisfies(c -> assertThat(c.getProxyAccountId().getId()).isPositive()));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Contract(com.hedera.mirror.common.domain.contract.Contract) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) BoolValue(com.google.protobuf.BoolValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) ContractID(com.hederahashgraph.api.proto.java.ContractID) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Assertions(org.junit.jupiter.api.Assertions) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) Contract(com.hedera.mirror.common.domain.contract.Contract) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ContractID (com.hederahashgraph.api.proto.java.ContractID)33 Test (org.junit.jupiter.api.Test)18 EntityId (com.hedera.mirror.common.domain.entity.EntityId)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 AccountID (com.hederahashgraph.api.proto.java.AccountID)9 Contract (com.hedera.mirror.common.domain.contract.Contract)7 Assertions (org.junit.jupiter.api.Assertions)7 ByteString (com.google.protobuf.ByteString)6 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)6 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)6 DomainUtils (com.hedera.mirror.common.util.DomainUtils)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Range (com.google.common.collect.Range)4 EntityType (com.hedera.mirror.common.domain.entity.EntityType)4 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 RecordItemBuilder (com.hedera.mirror.importer.parser.domain.RecordItemBuilder)4 Utility (com.hedera.mirror.importer.util.Utility)4 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 List (java.util.List)4