use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractUpdateAllToExisting.
@ParameterizedTest
@CsvSource({ "PLAIN, 5005, 5005", "PARSABLE_EVM, 0, 0", "CREATE2_EVM, , 5002" })
void contractUpdateAllToExisting(ContractIdType contractIdType, Long newAutoRenewAccount, Long expectedAutoRenewAccount) {
// first create the contract
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true, c -> {
c.obtainerId(null).declineReward(true).stakedAccountId(1L);
if (newAutoRenewAccount == null) {
c.autoRenewAccountId(expectedAutoRenewAccount);
}
});
Contract contract = setupResult.contract;
// now update
Transaction transaction = contractUpdateAllTransaction(setupResult.protoContractId, true, b -> {
if (newAutoRenewAccount != null) {
b.getAutoRenewAccountIdBuilder().setAccountNum(newAutoRenewAccount);
}
});
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(expectedAutoRenewAccount, Contract::getAutoRenewAccountId).returns(contract.getCreatedTimestamp(), Contract::getCreatedTimestamp).returns(contract.getFileId(), // FileId is ignored on updates by HAPI
Contract::getFileId));
}
use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractUpdateAllWithMemoToExisting.
@Test
void contractUpdateAllWithMemoToExisting() {
// first create the contract
EntityId contractId = EntityId.of(CONTRACT_ID);
Contract contract = domainBuilder.contract().customize(c -> c.obtainerId(null).id(contractId.getId()).num(contractId.getEntityNum()).stakedNodeId(1L)).persist();
// now update
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(contract.getCreatedTimestamp(), Contract::getCreatedTimestamp).returns(contract.getFileId(), // FileId is ignored on updates by HAPI
Contract::getFileId));
}
use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoTransferWithEvmAddressAlias.
@Test
void cryptoTransferWithEvmAddressAlias() {
Contract contract = domainBuilder.contract().persist();
assertThat(contractRepository.findByEvmAddress(contract.getEvmAddress())).isPresent();
entityProperties.getPersist().setNonFeeTransfers(true);
long transferAmount = 123;
var transfer1 = accountAliasAmount(DomainUtils.fromBytes(contract.getEvmAddress()), transferAmount).build();
Transaction transaction = buildTransaction(builder -> builder.getCryptoTransferBuilder().getTransfersBuilder().addAccountAmounts(transfer1));
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord transactionRecord = transactionRecordSuccess(transactionBody);
RecordItem recordItem = new RecordItem(transaction, transactionRecord);
parseRecordItemAndCommit(recordItem);
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, nonFeeTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, transactionRecord), () -> assertThat(findNonFeeTransfers()).allSatisfy(nonFeeTransfer -> {
assertThat(nonFeeTransfer.getEntityId()).isEqualTo(contract.toEntityId());
assertThat(nonFeeTransfer.getAmount()).isEqualTo(transferAmount);
assertThat(nonFeeTransfer.getPayerAccountId()).isEqualTo(recordItem.getPayerAccountId());
}));
}
use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.
the class CompositeBatchPersisterTest method persist.
@Test
@Transactional
void persist() {
Contract contract = domainBuilder.contract().get();
ContractResult contractResult = domainBuilder.contractResult().get();
compositeBatchInserter.persist(List.of(contract));
compositeBatchInserter.persist(List.of(contractResult));
assertThat(contractRepository.findAll()).containsExactly(contract);
assertThat(contractResultRepository.findAll()).containsExactly(contractResult);
}
use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractDeleteToNew.
@ParameterizedTest
@EnumSource(value = ContractIdType.class, names = { "PLAIN", "PARSABLE_EVM" })
void contractDeleteToNew(ContractIdType contractIdType) {
// The contract is not in db, it should still work for PLAIN and PARSABLE_EVM
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, 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);
Contract contract = getTransactionEntity(record.getConsensusTimestamp());
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(EntityId.of(CONTRACT_ID)), () -> assertTransactionAndRecord(transactionBody, record), () -> assertThat(contract).isNotNull().returns(true, Contract::getDeleted).returns(recordItem.getConsensusTimestamp(), Contract::getTimestampLower).returns(null, Contract::getAutoRenewPeriod).returns(null, Contract::getExpirationTimestamp).returns(null, Contract::getKey).returns(EntityId.of(PAYER), Contract::getObtainerId).returns(null, Contract::getProxyAccountId));
}
Aggregations