Search in sources :

Example 6 with ContractID

use of com.hederahashgraph.api.proto.java.ContractID in project hedera-services by hashgraph.

the class UtilVerbs method contractListWithPropertiesInheritedFrom.

public static HapiSpecOperation contractListWithPropertiesInheritedFrom(final String contractList, final long expectedSize, final String parent) {
    return withOpContext((spec, ctxLog) -> {
        List<HapiSpecOperation> opsList = new ArrayList<HapiSpecOperation>();
        long contractListSize = spec.registry().getAmount(contractList + "Size");
        Assertions.assertEquals(expectedSize, contractListSize, contractList + " has bad size!");
        if (contractListSize > 1) {
            ContractID currentID = spec.registry().getContractId(contractList + "0");
            long nextIndex = 1;
            while (nextIndex < contractListSize) {
                ContractID nextID = spec.registry().getContractId(contractList + nextIndex);
                Assertions.assertEquals(currentID.getShardNum(), nextID.getShardNum());
                Assertions.assertEquals(currentID.getRealmNum(), nextID.getRealmNum());
                Assertions.assertTrue(currentID.getContractNum() < nextID.getContractNum());
                currentID = nextID;
                nextIndex++;
            }
        }
        for (long i = 0; i < contractListSize; i++) {
            HapiSpecOperation op = getContractInfo(contractList + i).has(contractWith().propertiesInheritedFrom(parent)).logged();
            opsList.add(op);
        }
        CustomSpecAssert.allRunFor(spec, opsList);
    });
}
Also used : ArrayList(java.util.ArrayList) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 7 with ContractID

use of com.hederahashgraph.api.proto.java.ContractID 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 8 with ContractID

use of com.hederahashgraph.api.proto.java.ContractID in project hedera-mirror-node by hashgraph.

the class NonFeeTransferExtractionStrategyImplTest method extractNonFeeTransfersContractCallReceipt.

@Test
void extractNonFeeTransfersContractCallReceipt() {
    var amount = 123456L;
    var contractNum = 8888L;
    ContractID contractIdBody = ContractID.newBuilder().setContractNum(-1L).build();
    ContractID contractIdReceipt = ContractID.newBuilder().setContractNum(contractNum).build();
    var transactionBody = getContractCallTransactionBody(-1L, amount);
    var contractCallResult = ContractFunctionResult.newBuilder().setContractID(contractIdReceipt);
    var receipt = TransactionReceipt.newBuilder().setContractID(contractIdReceipt).setStatus(ResponseCodeEnum.SUCCESS);
    var transactionRecord = TransactionRecord.newBuilder().setReceipt(receipt).setContractCallResult(contractCallResult).build();
    when(entityIdService.lookup(contractIdReceipt, contractIdBody)).thenReturn(EntityId.of(contractIdReceipt));
    var result = extractionStrategy.extractNonFeeTransfers(transactionBody, transactionRecord);
    assertAll(() -> assertEquals(2, StreamSupport.stream(result.spliterator(), false).count()), () -> assertResult(createAccountAmounts(contractNum, amount, payerAccountNum, -amount), result));
}
Also used : ContractID(com.hederahashgraph.api.proto.java.ContractID) Test(org.junit.jupiter.api.Test)

Example 9 with ContractID

use of com.hederahashgraph.api.proto.java.ContractID in project hedera-mirror-node by hashgraph.

the class NonFeeTransferExtractionStrategyImplTest method extractNonFeeTransfersContractCallBody.

@Test
void extractNonFeeTransfersContractCallBody() {
    var amount = 123456L;
    var contractNum = 8888L;
    ContractID contractId = ContractID.newBuilder().setContractNum(contractNum).build();
    var transactionBody = getContractCallTransactionBody(contractNum, amount);
    var contractCallResult = ContractFunctionResult.newBuilder().setContractID(contractId);
    var transactionRecord = getSimpleTransactionRecord().toBuilder().setContractCallResult(contractCallResult).build();
    when(entityIdService.lookup(ContractID.getDefaultInstance(), contractId)).thenReturn(EntityId.of(contractId));
    var result = extractionStrategy.extractNonFeeTransfers(transactionBody, transactionRecord);
    assertAll(() -> assertEquals(2, StreamSupport.stream(result.spliterator(), false).count()), () -> assertResult(createAccountAmounts(contractNum, amount, payerAccountNum, -amount), result));
}
Also used : ContractID(com.hederahashgraph.api.proto.java.ContractID) Test(org.junit.jupiter.api.Test)

Example 10 with ContractID

use of com.hederahashgraph.api.proto.java.ContractID in project hedera-mirror-node by hashgraph.

the class ContractUpdateTransactionHandlerTest method testGetEntityIdReceipt.

@Test
void testGetEntityIdReceipt() {
    var recordItem = recordItemBuilder.contractUpdate().build();
    ContractID contractIdBody = recordItem.getTransactionBody().getContractUpdateInstance().getContractID();
    ContractID contractIdReceipt = recordItem.getRecord().getReceipt().getContractID();
    EntityId expectedEntityId = EntityId.of(contractIdReceipt);
    when(entityIdService.lookup(contractIdReceipt, contractIdBody)).thenReturn(expectedEntityId);
    EntityId entityId = transactionHandler.getEntity(recordItem);
    assertThat(entityId).isEqualTo(expectedEntityId);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractID(com.hederahashgraph.api.proto.java.ContractID) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ContractID (com.hederahashgraph.api.proto.java.ContractID)33 Test (org.junit.jupiter.api.Test)18 EntityId (com.hedera.mirror.common.domain.entity.EntityId)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 AccountID (com.hederahashgraph.api.proto.java.AccountID)9 Contract (com.hedera.mirror.common.domain.contract.Contract)7 Assertions (org.junit.jupiter.api.Assertions)7 ByteString (com.google.protobuf.ByteString)6 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)6 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)6 DomainUtils (com.hedera.mirror.common.util.DomainUtils)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Range (com.google.common.collect.Range)4 EntityType (com.hedera.mirror.common.domain.entity.EntityType)4 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 RecordItemBuilder (com.hedera.mirror.importer.parser.domain.RecordItemBuilder)4 Utility (com.hedera.mirror.importer.util.Utility)4 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 List (java.util.List)4