use of com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onContractHistory.
@ValueSource(ints = { 1, 2, 3 })
@ParameterizedTest
void onContractHistory(int commitIndex) {
// given
Contract contractCreate = domainBuilder.contract().customize(c -> c.obtainerId(null)).get();
Contract contractUpdate = contractCreate.toEntityId().toEntity();
contractUpdate.setAutoRenewPeriod(30L);
contractUpdate.setEvmAddress(contractCreate.getEvmAddress());
contractUpdate.setExpirationTimestamp(500L);
contractUpdate.setKey(domainBuilder.key());
contractUpdate.setMemo("updated");
contractUpdate.setTimestampLower(contractCreate.getTimestampLower() + 1);
contractUpdate.setProxyAccountId(EntityId.of(100L, ACCOUNT));
Contract contractDelete = contractCreate.toEntityId().toEntity();
contractDelete.setDeleted(true);
contractDelete.setEvmAddress(contractCreate.getEvmAddress());
contractDelete.setTimestampLower(contractCreate.getTimestampLower() + 2);
contractDelete.setObtainerId(EntityId.of(999L, EntityType.CONTRACT));
// Expected merged objects
Contract mergedCreate = TestUtils.clone(contractCreate);
Contract mergedUpdate = TestUtils.merge(contractCreate, contractUpdate);
Contract mergedDelete = TestUtils.merge(mergedUpdate, contractDelete);
mergedCreate.setTimestampUpper(contractUpdate.getTimestampLower());
// when
sqlEntityListener.onContract(contractCreate);
if (commitIndex > 1) {
completeFileAndCommit();
assertThat(contractRepository.findAll()).containsExactly(contractCreate);
assertThat(findHistory(Contract.class)).isEmpty();
}
sqlEntityListener.onContract(contractUpdate);
if (commitIndex > 2) {
completeFileAndCommit();
assertThat(contractRepository.findAll()).containsExactly(mergedUpdate);
assertThat(findHistory(Contract.class)).containsExactly(mergedCreate);
}
sqlEntityListener.onContract(contractDelete);
completeFileAndCommit();
// then
mergedUpdate.setTimestampUpper(contractDelete.getTimestampLower());
assertThat(contractRepository.findAll()).containsExactly(mergedDelete);
assertThat(findHistory(Contract.class)).containsExactly(mergedCreate, mergedUpdate);
assertThat(entityRepository.count()).isZero();
}
use of com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onNonFeeTransfer.
@Test
void onNonFeeTransfer() {
// given
NonFeeTransfer nonFeeTransfer1 = domainBuilder.nonFeeTransfer().customize(n -> n.amount(1L).consensusTimestamp(1L).entityId(EntityId.of(1L, ACCOUNT)).payerAccountId(TRANSACTION_PAYER)).get();
NonFeeTransfer nonFeeTransfer2 = domainBuilder.nonFeeTransfer().customize(n -> n.amount(2L).consensusTimestamp(2L).entityId(EntityId.of(2L, ACCOUNT)).payerAccountId(TRANSACTION_PAYER)).get();
// when
sqlEntityListener.onNonFeeTransfer(nonFeeTransfer1);
sqlEntityListener.onNonFeeTransfer(nonFeeTransfer2);
completeFileAndCommit();
// then
assertThat(findNonFeeTransfers()).containsExactlyInAnyOrder(nonFeeTransfer1, nonFeeTransfer2);
}
use of com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT in project hedera-mirror-node by hashgraph.
the class ConsensusUpdateTopicTransactionHandlerTest 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.consensusUpdateTopic().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).build();
var topicId = EntityId.of(recordItem.getTransactionBody().getConsensusUpdateTopic().getTopicID());
var timestamp = recordItem.getConsensusTimestamp();
var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(topicId)).get();
when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
// when, then
assertThrows(AliasNotFoundException.class, () -> transactionHandler.updateTransaction(transaction, recordItem));
}
use of com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT in project hedera-mirror-node by hashgraph.
the class ContractCreateTransactionHandlerTest 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.contractCreate().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));
}
use of com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT in project hedera-mirror-node by hashgraph.
the class TokenUpdateTransactionHandlerTest method updateTransactionWithAliasNotFoundAndPartialDataActionSkip.
@Test
void updateTransactionWithAliasNotFoundAndPartialDataActionSkip() {
recordParserProperties.setPartialDataAction(PartialDataAction.SKIP);
var alias = DomainUtils.fromBytes(domainBuilder.key());
var recordItem = recordItemBuilder.tokenUpdate().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).build();
var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
var timestamp = recordItem.getConsensusTimestamp();
var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).get();
when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
transactionHandler.updateTransaction(transaction, recordItem);
assertTokenUpdate(timestamp, tokenId, Assertions::assertNull);
}
Aggregations