use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method setupContract.
private SetupResult setupContract(ContractID contractId, ContractIdType contractIdType, boolean persist, boolean cache, Consumer<Contract.ContractBuilder> customizer) {
EntityId entityId = EntityId.of(contractId);
byte[] evmAddress = getEvmAddress(contractIdType, entityId);
ContractID protoContractId = getContractId(CONTRACT_ID, evmAddress);
var builder = domainBuilder.contract().customize(c -> c.evmAddress(evmAddress).id(entityId.getId()).num(entityId.getEntityNum()));
if (customizer != null) {
builder.customize(customizer);
}
Contract contract = persist ? builder.persist() : builder.get();
if (cache) {
contractIds.put(protoContractId, entityId);
}
return new SetupResult(contract, protoContractId);
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method assertContractResult.
private void assertContractResult(long consensusTimestamp, ContractFunctionResult result, List<ContractLoginfo> logInfoList, ObjectAssert<ContractResult> contractResult, List<com.hederahashgraph.api.proto.java.ContractStateChange> stateChanges) {
List<Long> createdContractIds = result.getCreatedContractIDsList().stream().map(ContractID::getContractNum).collect(Collectors.toList());
contractResult.returns(result.getBloom().toByteArray(), ContractResult::getBloom).returns(result.getContractCallResult().toByteArray(), ContractResult::getCallResult).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(createdContractIds, ContractResult::getCreatedContractIds).returns(result.getErrorMessage(), ContractResult::getErrorMessage).returns(result.toByteArray(), ContractResult::getFunctionResult).returns(result.getGasUsed(), ContractResult::getGasUsed);
for (int i = 0; i < logInfoList.size(); i++) {
int index = i;
ContractLoginfo logInfo = logInfoList.get(i);
assertThat(contractLogRepository.findById(new ContractLog.Id(consensusTimestamp, index))).isPresent().get().returns(logInfo.getBloom().toByteArray(), ContractLog::getBloom).returns(consensusTimestamp, ContractLog::getConsensusTimestamp).returns(EntityId.of(logInfo.getContractID()), ContractLog::getContractId).returns(logInfo.getData().toByteArray(), ContractLog::getData).returns(index, ContractLog::getIndex).returns(EntityId.of(result.getContractID()), ContractLog::getRootContractId).returns(Utility.getTopic(logInfo, 0), ContractLog::getTopic0).returns(Utility.getTopic(logInfo, 1), ContractLog::getTopic1).returns(Utility.getTopic(logInfo, 2), ContractLog::getTopic2).returns(Utility.getTopic(logInfo, 3), ContractLog::getTopic3);
}
int count = 0;
var contractStateChanges = assertThat(contractStateChangeRepository.findAll());
for (var contractStateChangeInfo : stateChanges) {
EntityId contractId = EntityId.of(contractStateChangeInfo.getContractID());
for (var storageChange : contractStateChangeInfo.getStorageChangesList()) {
byte[] slot = DomainUtils.toBytes(storageChange.getSlot());
byte[] valueWritten = storageChange.hasValueWritten() ? storageChange.getValueWritten().getValue().toByteArray() : null;
contractStateChanges.filteredOn(c -> c.getConsensusTimestamp() == consensusTimestamp && c.getContractId() == contractId.getId() && Arrays.equals(c.getSlot(), slot)).hasSize(1).first().returns(storageChange.getValueRead().toByteArray(), ContractStateChange::getValueRead).returns(valueWritten, ContractStateChange::getValueWritten);
++count;
}
}
contractStateChanges.hasSize(count);
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoTransferWithUnknownAlias.
@ParameterizedTest
@EnumSource(value = PartialDataAction.class, names = { "DEFAULT", "SKIP" })
void cryptoTransferWithUnknownAlias(PartialDataAction partialDataAction) {
// given
// both accounts have alias, and only account2's alias is in db
entityProperties.getPersist().setCryptoTransferAmounts(true);
entityProperties.getPersist().setNonFeeTransfers(true);
parserProperties.setPartialDataAction(partialDataAction);
Entity account1 = domainBuilder.entity().get();
Entity account2 = domainBuilder.entity().persist();
// crypto transfer from unknown account1 alias to account2 alias
Transaction transaction = buildTransaction(builder -> builder.getCryptoTransferBuilder().getTransfersBuilder().addAccountAmounts(accountAliasAmount(DomainUtils.fromBytes(account1.getAlias()), 100)).addAccountAmounts(accountAliasAmount(DomainUtils.fromBytes(account2.getAlias()), -100)));
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord transactionRecord = buildTransactionRecord(r -> r.getTransferListBuilder().addAccountAmounts(accountAmount(account1.getNum(), 100)).addAccountAmounts(accountAmount(account2.getNum(), -100)), transactionBody, ResponseCodeEnum.SUCCESS.getNumber());
List<EntityId> expectedEntityIds = partialDataAction == PartialDataAction.DEFAULT ? Arrays.asList(account2.toEntityId(), null) : List.of(account2.toEntityId());
// when
parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));
// then
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(5, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, transactionRecord), () -> assertThat(findNonFeeTransfers()).extracting(NonFeeTransfer::getEntityId).containsExactlyInAnyOrderElementsOf(expectedEntityIds));
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenAccountReassociate.
@Test
void onTokenAccountReassociate() {
List<TokenAccount> expected = new ArrayList<>();
EntityId tokenId1 = EntityId.of("0.0.3", TOKEN);
// save token entities first
Token token = getToken(tokenId1, EntityId.of("0.0.500", ACCOUNT), 1L, 1L);
tokenRepository.save(token);
// token account was associated before this record file
EntityId accountId1 = EntityId.of("0.0.7", ACCOUNT);
TokenAccount associate = getTokenAccount(tokenId1, accountId1, 5L, 5L, true, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.REVOKED);
tokenAccountRepository.save(associate);
expected.add(associate);
// when
TokenAccount freeze = getTokenAccount(tokenId1, accountId1, null, 10L, null, null, TokenFreezeStatusEnum.FROZEN, null);
sqlEntityListener.onTokenAccount(freeze);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 10L, true, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.REVOKED));
TokenAccount kycGrant = getTokenAccount(tokenId1, accountId1, null, 15L, null, null, null, TokenKycStatusEnum.GRANTED);
sqlEntityListener.onTokenAccount(kycGrant);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 15L, true, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.GRANTED));
TokenAccount dissociate = getTokenAccount(tokenId1, accountId1, null, 16L, false, null, null, null);
sqlEntityListener.onTokenAccount(dissociate);
expected.add(getTokenAccount(tokenId1, accountId1, 5L, 16L, false, false, TokenFreezeStatusEnum.FROZEN, TokenKycStatusEnum.GRANTED));
// associate after dissociate, the token has freeze key with freezeDefault = false, the token also has kyc key,
// so the new relationship should have UNFROZEN, REVOKED
TokenAccount reassociate = getTokenAccount(tokenId1, accountId1, 20L, 20L, true, false, null, null);
sqlEntityListener.onTokenAccount(reassociate);
expected.add(getTokenAccount(tokenId1, accountId1, 20L, 20L, true, false, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.REVOKED));
completeFileAndCommit();
// then
assertThat(tokenAccountRepository.findAll()).containsExactlyInAnyOrderElementsOf(expected);
}
use of com.hedera.mirror.common.domain.entity.EntityId in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onTokenMerge.
@Test
void onTokenMerge() {
EntityId tokenId = EntityId.of("0.0.3", TOKEN);
EntityId accountId = EntityId.of("0.0.500", ACCOUNT);
// save token entities first
Token token = getToken(tokenId, accountId, 1L, 1L, 1000, false, keyFromString(KEY), 1_000_000_000L, null, "FOO COIN TOKEN", null, "FOOTOK", null, null, TokenPauseStatusEnum.UNPAUSED);
sqlEntityListener.onToken(token);
Token tokenUpdated = getToken(tokenId, accountId, null, 5L, null, null, null, null, keyFromString(KEY2), "BAR COIN TOKEN", keyFromString(KEY), "BARTOK", keyFromString(KEY2), keyFromString(KEY2), TokenPauseStatusEnum.UNPAUSED);
sqlEntityListener.onToken(tokenUpdated);
completeFileAndCommit();
// then
Token tokenMerged = getToken(tokenId, accountId, 1L, 5L, 1000, false, keyFromString(KEY), 1_000_000_000L, keyFromString(KEY2), "BAR COIN TOKEN", keyFromString(KEY), "BARTOK", keyFromString(KEY2), keyFromString(KEY2), TokenPauseStatusEnum.UNPAUSED);
assertThat(tokenRepository.findAll()).containsExactlyInAnyOrder(tokenMerged);
}
Aggregations