Search in sources :

Example 6 with ContractFunctionResult

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

the class EntityRecordItemListenerTokenTest method tokenBurnNftsPrecompile.

@Test
void tokenBurnNftsPrecompile() {
    long mintTimestamp = 10L;
    tokenSupplyMintNftsPrecompile(mintTimestamp);
    long burnTimestamp = 15L;
    Transaction transaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, false, 0, SERIAL_NUMBER_LIST);
    AtomicReference<ContractFunctionResult> contractFunctionResultAtomic = new AtomicReference<>();
    insertAndParseTransaction(burnTimestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(SERIAL_NUMBER_LIST.size()).addAllSerialNumbers(SERIAL_NUMBER_LIST);
        buildContractFunctionResult(builder.getContractCallResultBuilder());
        contractFunctionResultAtomic.set(builder.getContractCallResult());
    });
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_1, true, mintTimestamp, burnTimestamp, METADATA.getBytes(), null, true);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_2, true, mintTimestamp, burnTimestamp, METADATA.getBytes(), null, true);
    assertContractResult(burnTimestamp, contractFunctionResultAtomic.get());
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with ContractFunctionResult

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

the class EntityRecordItemListenerTokenTest method tokenSupplyFtsPrecompile.

private void tokenSupplyFtsPrecompile(boolean isMint) {
    createAndAssociateToken(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, INITIAL_SUPPLY);
    long amount = 1000;
    long mintTimestamp = 10L;
    TokenTransferList tokenTransfer = tokenTransfer(TOKEN_ID, PAYER, amount);
    Transaction transaction = tokenSupplyTransaction(TOKEN_ID, FUNGIBLE_COMMON, isMint, amount, null);
    AtomicReference<ContractFunctionResult> contractFunctionResultAtomic = new AtomicReference<>();
    insertAndParseTransaction(mintTimestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(INITIAL_SUPPLY + amount);
        builder.addTokenTransferLists(tokenTransfer);
        buildContractFunctionResult(builder.getContractCallResultBuilder());
        contractFunctionResultAtomic.set(builder.getContractCallResult());
    });
    // Verify
    assertThat(tokenTransferRepository.count()).isEqualTo(2L);
    assertTokenTransferInRepository(TOKEN_ID, PAYER, CREATE_TIMESTAMP, INITIAL_SUPPLY);
    assertTokenTransferInRepository(TOKEN_ID, PAYER, mintTimestamp, amount);
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, mintTimestamp, SYMBOL, INITIAL_SUPPLY + amount);
    assertContractResult(mintTimestamp, contractFunctionResultAtomic.get());
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 8 with ContractFunctionResult

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

the class EntityRecordItemListenerTokenTest method tokenSupplyMintNftsPrecompile.

private void tokenSupplyMintNftsPrecompile(long timestamp) {
    // given
    createAndAssociateToken(TOKEN_ID, NON_FUNGIBLE_UNIQUE, SYMBOL, CREATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, PAYER2, false, false, false, 0);
    TokenTransferList mintTransfer = nftTransfer(TOKEN_ID, PAYER, DEFAULT_ACCOUNT_ID, SERIAL_NUMBER_LIST);
    Transaction transaction = tokenSupplyTransaction(TOKEN_ID, NON_FUNGIBLE_UNIQUE, true, 0, SERIAL_NUMBER_LIST);
    // when
    AtomicReference<ContractFunctionResult> contractFunctionResultAtomic = new AtomicReference<>();
    insertAndParseTransaction(timestamp, transaction, builder -> {
        builder.getReceiptBuilder().setNewTotalSupply(SERIAL_NUMBER_LIST.size()).addAllSerialNumbers(SERIAL_NUMBER_LIST);
        builder.addTokenTransferLists(mintTransfer);
        buildContractFunctionResult(builder.getContractCallResultBuilder());
        contractFunctionResultAtomic.set(builder.getContractCallResult());
    });
    // then
    assertThat(nftTransferRepository.count()).isEqualTo(2L);
    assertNftTransferInRepository(timestamp, SERIAL_NUMBER_2, TOKEN_ID, PAYER, null);
    assertNftTransferInRepository(timestamp, SERIAL_NUMBER_1, TOKEN_ID, PAYER, null);
    assertTokenInRepository(TOKEN_ID, true, CREATE_TIMESTAMP, timestamp, SYMBOL, 2);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_1, true, timestamp, timestamp, METADATA.getBytes(), EntityId.of(PAYER), false);
    assertNftInRepository(TOKEN_ID, SERIAL_NUMBER_2, true, timestamp, timestamp, METADATA.getBytes(), EntityId.of(PAYER), false);
    assertContractResult(timestamp, contractFunctionResultAtomic.get());
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 9 with ContractFunctionResult

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

the class EntityRecordItemListenerTokenTest method tokenAssociatePrecompile.

@Test
void tokenAssociatePrecompile() {
    createTokenEntity(TOKEN_ID, FUNGIBLE_COMMON, SYMBOL, CREATE_TIMESTAMP, true, true, true);
    Transaction associateTransaction = tokenAssociate(List.of(TOKEN_ID), PAYER2);
    AtomicReference<ContractFunctionResult> contractFunctionResultAtomic = new AtomicReference<>();
    insertAndParseTransaction(ASSOCIATE_TIMESTAMP, associateTransaction, builder -> {
        buildContractFunctionResult(builder.getContractCallResultBuilder());
        contractFunctionResultAtomic.set(builder.getContractCallResult());
    });
    assertTokenAccountInRepository(TOKEN_ID, PAYER2, ASSOCIATE_TIMESTAMP, ASSOCIATE_TIMESTAMP, true, TokenFreezeStatusEnum.UNFROZEN, TokenKycStatusEnum.REVOKED);
    assertContractResult(ASSOCIATE_TIMESTAMP, contractFunctionResultAtomic.get());
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with ContractFunctionResult

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

the class RecordFileParserTest method totalGasUsedMustBeCorrect.

@Test
void totalGasUsedMustBeCorrect() {
    when(mirrorDateRangePropertiesProcessor.getDateRangeFilter(parserProperties.getStreamType())).thenReturn(DateRangeFilter.all());
    long timestamp = ++count;
    ContractFunctionResult contractFunctionResult1 = contractFunctionResult(10000000000L, new byte[] { 0, 6, 4, 0, 5, 7, 2 });
    RecordItem recordItem1 = contractCreate(contractFunctionResult1, timestamp, 0);
    ContractFunctionResult contractFunctionResult2 = contractFunctionResult(100000000000L, new byte[] { 3, 5, 1, 7, 4, 4, 0 });
    RecordItem recordItem2 = contractCall(contractFunctionResult2, timestamp, 0);
    ContractFunctionResult contractFunctionResult3 = contractFunctionResult(1000000000000L, new byte[] { 0, 1, 1, 2, 2, 6, 0 });
    RecordItem recordItem3 = ethereumTransaction(contractFunctionResult3, timestamp, 0);
    ContractFunctionResult contractFunctionResult4 = contractFunctionResult(1000000000000L, new byte[] { 0, 1, 1, 2, 2, 6, 0 });
    RecordItem recordItem4 = ethereumTransaction(contractFunctionResult4, timestamp, 1);
    RecordFile recordFile = getStreamFile(Flux.just(recordItem1, recordItem2, recordItem3, recordItem4), timestamp);
    parser.parse(recordFile);
    byte[] expectedLogBloom = new byte[] { 3, 7, 5, 7, 7, 7, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    assertAll(() -> assertEquals(10000000000L + 100000000000L + 1000000000000L, recordFile.getGasUsed()), () -> assertArrayEquals(expectedLogBloom, recordFile.getLogsBloom()), () -> verify(recordStreamFileListener, times(1)).onStart(), () -> verify(recordStreamFileListener, times(1)).onEnd(recordFile), () -> verify(recordItemListener, times(1)).onItem(recordItem1), () -> verify(recordItemListener, times(1)).onItem(recordItem2), () -> verify(recordItemListener, times(1)).onItem(recordItem3));
}
Also used : RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) AbstractStreamFileParserTest(com.hedera.mirror.importer.parser.AbstractStreamFileParserTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ContractFunctionResult (com.hederahashgraph.api.proto.java.ContractFunctionResult)30 Test (org.junit.jupiter.api.Test)20 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)14 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)13 ByteString (com.google.protobuf.ByteString)12 EntityId (com.hedera.mirror.common.domain.entity.EntityId)12 RecordFile (com.hedera.mirror.common.domain.transaction.RecordFile)12 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)11 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)11 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)11 DomainUtils (com.hedera.mirror.common.util.DomainUtils)11 RecordItemBuilder (com.hedera.mirror.importer.parser.domain.RecordItemBuilder)11 ContractLogRepository (com.hedera.mirror.importer.repository.ContractLogRepository)11 ContractStateChangeRepository (com.hedera.mirror.importer.repository.ContractStateChangeRepository)11 ContractID (com.hederahashgraph.api.proto.java.ContractID)11 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)11 TokenType (com.hederahashgraph.api.proto.java.TokenType)11 Collectors (java.util.stream.Collectors)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 ObjectAssert (org.assertj.core.api.ObjectAssert)11