Search in sources :

Example 6 with EntityId

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);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractID(com.hederahashgraph.api.proto.java.ContractID) Contract(com.hedera.mirror.common.domain.contract.Contract)

Example 7 with EntityId

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);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractLoginfo(com.hederahashgraph.api.proto.java.ContractLoginfo)

Example 8 with EntityId

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));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) NonFeeTransfer(com.hedera.mirror.common.domain.transaction.NonFeeTransfer) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with EntityId

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);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) TokenAccount(com.hedera.mirror.common.domain.token.TokenAccount) ArrayList(java.util.ArrayList) Token(com.hedera.mirror.common.domain.token.Token) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with EntityId

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);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Token(com.hedera.mirror.common.domain.token.Token) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

EntityId (com.hedera.mirror.common.domain.entity.EntityId)134 Test (org.junit.jupiter.api.Test)64 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)33 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)22 EntityType (com.hedera.mirror.common.domain.entity.EntityType)21 TokenAccount (com.hedera.mirror.common.domain.token.TokenAccount)21 Token (com.hedera.mirror.common.domain.token.Token)20 Entity (com.hedera.mirror.common.domain.entity.Entity)17 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)17 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)16 Assertions (org.junit.jupiter.api.Assertions)16 Contract (com.hedera.mirror.common.domain.contract.Contract)15 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)15 DomainUtils (com.hedera.mirror.common.util.DomainUtils)15 ByteString (com.google.protobuf.ByteString)14 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)14 AccountID (com.hederahashgraph.api.proto.java.AccountID)14 ContractID (com.hederahashgraph.api.proto.java.ContractID)14 Consumer (java.util.function.Consumer)13