use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onContract.
@Test
void onContract() {
// given
Contract contract1 = domainBuilder.contract().get();
Contract contract2 = domainBuilder.contract().customize(c -> c.fileId(null).initcode(domainBuilder.bytes(1024)).autoRenewAccountId(null).evmAddress(null)).get();
// when
sqlEntityListener.onContract(contract1);
sqlEntityListener.onContract(contract2);
completeFileAndCommit();
// then
assertThat(entityRepository.count()).isZero();
assertThat(contractRepository.findAll()).containsExactlyInAnyOrder(contract1, contract2);
assertThat(findHistory(Contract.class)).isEmpty();
}
use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onContractWithHistoryAndNonHistoryUpdates.
@ValueSource(booleans = { true, false })
@ParameterizedTest
void onContractWithHistoryAndNonHistoryUpdates(boolean nonHistoryBefore) {
// given
Contract contract = domainBuilder.contract().persist();
Contract contractStakePeriodStart1 = contract.toEntityId().toEntity();
contractStakePeriodStart1.setStakePeriodStart(2L);
contractStakePeriodStart1.setTimestampRange(null);
Contract contractStakePeriodStart2 = contract.toEntityId().toEntity();
contractStakePeriodStart2.setStakePeriodStart(7L);
contractStakePeriodStart2.setTimestampRange(null);
Contract contractMemoUpdated = contract.toEntityId().toEntity();
contractMemoUpdated.setMemo(domainBuilder.text(16));
contractMemoUpdated.setTimestampLower(domainBuilder.timestamp());
// when
if (nonHistoryBefore) {
sqlEntityListener.onContract(contractStakePeriodStart1);
sqlEntityListener.onContract(contractStakePeriodStart2);
sqlEntityListener.onContract(contractMemoUpdated);
} else {
sqlEntityListener.onContract(contractMemoUpdated);
sqlEntityListener.onContract(contractStakePeriodStart1);
sqlEntityListener.onContract(contractStakePeriodStart2);
}
completeFileAndCommit();
// then
Contract contractMerged = TestUtils.clone(contract);
contractMerged.setMemo(contractMemoUpdated.getMemo());
contractMerged.setStakePeriodStart(contractStakePeriodStart2.getStakePeriodStart());
contractMerged.setTimestampRange(contractMemoUpdated.getTimestampRange());
contract.setTimestampUpper(contractMemoUpdated.getTimestampLower());
assertThat(contractRepository.findAll()).containsExactly(contractMerged);
assertThat(findHistory(Contract.class)).containsExactly(contract);
}
use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onContractHistory.
@ParameterizedTest(name = "{2} record files with {0}")
@MethodSource("provideParamsContractHistory")
void onContractHistory(String bytecodeSource, Consumer<Contract.ContractBuilder> customizer, int commitIndex) {
// given
Contract contractCreate = domainBuilder.contract().customize(c -> c.obtainerId(null)).customize(customizer).get();
Contract contractUpdate = contractCreate.toEntityId().toEntity();
contractUpdate.setAutoRenewAccountId(110L);
contractUpdate.setAutoRenewPeriod(30L);
contractUpdate.setExpirationTimestamp(500L);
contractUpdate.setKey(domainBuilder.key());
contractUpdate.setMaxAutomaticTokenAssociations(100);
contractUpdate.setMemo("updated");
contractUpdate.setTimestampLower(contractCreate.getTimestampLower() + 1);
contractUpdate.setProxyAccountId(EntityId.of(100L, ACCOUNT));
Contract contractDelete = contractCreate.toEntityId().toEntity();
contractDelete.setDeleted(true);
contractDelete.setPermanentRemoval(true);
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.contract.Contract in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onContractWithNonHistoryUpdates.
@Test
void onContractWithNonHistoryUpdates() {
// given
// Update to non-history field with existing contract should just update nonce
var existingContract = domainBuilder.contract().persist();
Contract existingContractStakePeriodStart1 = existingContract.toEntityId().toEntity();
existingContractStakePeriodStart1.setStakePeriodStart(2L);
existingContractStakePeriodStart1.setTimestampRange(null);
Contract existingContractStakePeriodStart2 = existingContract.toEntityId().toEntity();
existingContractStakePeriodStart2.setStakePeriodStart(5L);
existingContractStakePeriodStart2.setTimestampRange(null);
// Update to non-history field with partial data should be discarded
Contract nonExistingContract = domainBuilder.contract().get();
Contract nonExistingContractStakePeriodStart1 = nonExistingContract.toEntityId().toEntity();
nonExistingContractStakePeriodStart1.setStakePeriodStart(6L);
nonExistingContractStakePeriodStart1.setTimestampRange(null);
Contract nonExistingContractStakePeriodStart2 = nonExistingContract.toEntityId().toEntity();
nonExistingContractStakePeriodStart2.setStakePeriodStart(8L);
nonExistingContractStakePeriodStart2.setTimestampRange(null);
// when
sqlEntityListener.onContract(existingContractStakePeriodStart1);
sqlEntityListener.onContract(existingContractStakePeriodStart2);
sqlEntityListener.onContract(nonExistingContractStakePeriodStart1);
sqlEntityListener.onContract(nonExistingContractStakePeriodStart2);
completeFileAndCommit();
existingContract.setStakePeriodStart(existingContractStakePeriodStart2.getStakePeriodStart());
assertThat(contractRepository.findAll()).containsExactly(existingContract);
Contract existingContractStakePeriodStart3 = existingContract.toEntityId().toEntity();
existingContractStakePeriodStart3.setStakePeriodStart(10L);
existingContractStakePeriodStart3.setTimestampRange(null);
Contract nonExistingContractStakePeriodStart3 = domainBuilder.entityId(EntityType.CONTRACT).toEntity();
nonExistingContractStakePeriodStart3.setStakePeriodStart(12L);
nonExistingContractStakePeriodStart3.setTimestampRange(null);
sqlEntityListener.onContract(existingContractStakePeriodStart3);
sqlEntityListener.onContract(nonExistingContractStakePeriodStart3);
completeFileAndCommit();
// then
existingContract.setStakePeriodStart(existingContractStakePeriodStart3.getStakePeriodStart());
assertThat(contractRepository.findAll()).containsExactly(existingContract);
assertThat(findHistory(Contract.class)).isEmpty();
}
use of com.hedera.mirror.common.domain.contract.Contract in project hedera-mirror-node by hashgraph.
the class ContractCreateTransactionHandlerTest method updateTransactionWithAliasNotFoundAndPartialDataActionSkip.
@Test
void updateTransactionWithAliasNotFoundAndPartialDataActionSkip() {
recordParserProperties.setPartialDataAction(PartialDataAction.SKIP);
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));
transactionHandler.updateTransaction(transaction, recordItem);
assertContract(contractId, timestamp, t -> assertThat(t).returns(null, Contract::getAutoRenewAccountId).returns(null, Contract::getEvmAddress).satisfies(c -> assertThat(c.getFileId().getId()).isPositive()).returns(null, Contract::getInitcode));
}
Aggregations