Search in sources :

Example 16 with ContractFunctionParameters

use of com.hedera.hashgraph.sdk.ContractFunctionParameters in project hedera-sdk-java by hashgraph.

the class ContractUpdateIntegrationTest method canUpdateContract.

@Test
@DisplayName("Can update contract")
void canUpdateContract() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    @Var var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
    response = new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client);
    var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId);
    @Var var info = new ContractInfoQuery().setContractId(contractId).execute(testEnv.client);
    assertThat(info.contractId).isEqualTo(contractId);
    assertThat(info.accountId).isNotNull();
    assertThat(Objects.requireNonNull(info.accountId).toString()).isEqualTo(contractId.toString());
    assertThat(info.adminKey).isNotNull();
    assertThat(Objects.requireNonNull(info.adminKey).toString()).isEqualTo(Objects.requireNonNull(testEnv.operatorKey).toString());
    assertThat(info.storage).isEqualTo(128);
    assertThat(info.contractMemo).isEqualTo("[e2e::ContractCreateTransaction]");
    new ContractUpdateTransaction().setContractId(contractId).setContractMemo("[e2e::ContractUpdateTransaction]").execute(testEnv.client).getReceipt(testEnv.client);
    info = new ContractInfoQuery().setContractId(contractId).execute(testEnv.client);
    assertThat(info.contractId).isEqualTo(contractId);
    assertThat(info.accountId).isNotNull();
    assertThat(Objects.requireNonNull(info.accountId).toString()).isEqualTo(contractId.toString());
    assertThat(info.adminKey).isNotNull();
    assertThat(Objects.requireNonNull(info.adminKey).toString()).isEqualTo(Objects.requireNonNull(testEnv.operatorKey).toString());
    assertThat(info.storage).isEqualTo(128);
    assertThat(info.contractMemo).isEqualTo("[e2e::ContractUpdateTransaction]");
    new ContractDeleteTransaction().setTransferAccountId(testEnv.operatorId).setContractId(contractId).execute(testEnv.client).getReceipt(testEnv.client);
    new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) ContractDeleteTransaction(com.hedera.hashgraph.sdk.ContractDeleteTransaction) Var(com.google.errorprone.annotations.Var) ContractFunctionParameters(com.hedera.hashgraph.sdk.ContractFunctionParameters) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) ContractInfoQuery(com.hedera.hashgraph.sdk.ContractInfoQuery) ContractCreateTransaction(com.hedera.hashgraph.sdk.ContractCreateTransaction) ContractUpdateTransaction(com.hedera.hashgraph.sdk.ContractUpdateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 17 with ContractFunctionParameters

use of com.hedera.hashgraph.sdk.ContractFunctionParameters in project hedera-mirror-node by hashgraph.

the class ContractFeature method executeCreateChildTransaction.

private void executeCreateChildTransaction(int transferAmount) {
    networkTransactionResponse = contractClient.executeContract(contractId, contractClient.getSdkClient().getAcceptanceTestProperties().getFeatureProperties().getMaxContractFunctionGas(), "createChild", new ContractFunctionParameters().addUint256(BigInteger.valueOf(transferAmount)), null);
    assertNotNull(networkTransactionResponse.getTransactionId());
    assertNotNull(networkTransactionResponse.getReceipt());
}
Also used : ContractFunctionParameters(com.hedera.hashgraph.sdk.ContractFunctionParameters)

Example 18 with ContractFunctionParameters

use of com.hedera.hashgraph.sdk.ContractFunctionParameters in project hedera-sdk-java by hashgraph.

the class SystemIntegrationTest method allSystemTransactionsAreNotSupported.

@Test
@DisplayName("All system transactions are not supported")
void allSystemTransactionsAreNotSupported() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var fileId = Objects.requireNonNull(new FileCreateTransaction().setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client).getReceipt(testEnv.client).fileId);
    var contractId = Objects.requireNonNull(new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client).getReceipt(testEnv.client).contractId);
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new SystemDeleteTransaction().setContractId(contractId).setExpirationTime(Instant.now()).execute(testEnv.client);
    }).withMessageContaining(Status.NOT_SUPPORTED.toString());
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new SystemDeleteTransaction().setFileId(fileId).setExpirationTime(Instant.now()).execute(testEnv.client);
    }).withMessageContaining(Status.NOT_SUPPORTED.toString());
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new SystemUndeleteTransaction().setContractId(contractId).execute(testEnv.client);
    }).withMessageContaining(Status.NOT_SUPPORTED.toString());
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        new SystemUndeleteTransaction().setFileId(fileId).execute(testEnv.client);
    }).withMessageContaining(Status.NOT_SUPPORTED.toString());
    testEnv.close();
}
Also used : FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) SystemDeleteTransaction(com.hedera.hashgraph.sdk.SystemDeleteTransaction) ContractFunctionParameters(com.hedera.hashgraph.sdk.ContractFunctionParameters) ContractCreateTransaction(com.hedera.hashgraph.sdk.ContractCreateTransaction) SystemUndeleteTransaction(com.hedera.hashgraph.sdk.SystemUndeleteTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 19 with ContractFunctionParameters

use of com.hedera.hashgraph.sdk.ContractFunctionParameters in project hedera-sdk-java by hashgraph.

the class ContractBytecodeIntegrationTest method canQueryContractBytecode.

@Test
@DisplayName("Can query contract bytecode")
void canQueryContractBytecode() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    @Var var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
    response = new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client);
    var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId);
    var bytecode = new ContractByteCodeQuery().setContractId(contractId).execute(testEnv.client);
    assertThat(bytecode.size()).isEqualTo(798);
    new ContractDeleteTransaction().setTransferAccountId(testEnv.operatorId).setContractId(contractId).execute(testEnv.client).getReceipt(testEnv.client);
    new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : ContractByteCodeQuery(com.hedera.hashgraph.sdk.ContractByteCodeQuery) FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) ContractDeleteTransaction(com.hedera.hashgraph.sdk.ContractDeleteTransaction) Var(com.google.errorprone.annotations.Var) ContractFunctionParameters(com.hedera.hashgraph.sdk.ContractFunctionParameters) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) ContractCreateTransaction(com.hedera.hashgraph.sdk.ContractCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 20 with ContractFunctionParameters

use of com.hedera.hashgraph.sdk.ContractFunctionParameters in project hedera-sdk-java by hashgraph.

the class ContractBytecodeIntegrationTest method getCostBigMaxQueryContractBytecode.

@Test
@DisplayName("Can get cost, even with a big max")
void getCostBigMaxQueryContractBytecode() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    @Var var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
    response = new ContractCreateTransaction().setAdminKey(testEnv.operatorKey).setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client);
    var contractId = Objects.requireNonNull(response.getReceipt(testEnv.client).contractId);
    var bytecodeQuery = new ContractByteCodeQuery().setContractId(contractId).setMaxQueryPayment(new Hbar(1000));
    var cost = bytecodeQuery.getCost(testEnv.client);
    var bytecode = bytecodeQuery.setQueryPayment(cost).execute(testEnv.client);
    assertThat(bytecode.size()).isEqualTo(798);
    new ContractDeleteTransaction().setTransferAccountId(testEnv.operatorId).setContractId(contractId).execute(testEnv.client).getReceipt(testEnv.client);
    new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : ContractByteCodeQuery(com.hedera.hashgraph.sdk.ContractByteCodeQuery) FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) ContractDeleteTransaction(com.hedera.hashgraph.sdk.ContractDeleteTransaction) Var(com.google.errorprone.annotations.Var) ContractFunctionParameters(com.hedera.hashgraph.sdk.ContractFunctionParameters) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) ContractCreateTransaction(com.hedera.hashgraph.sdk.ContractCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

ContractFunctionParameters (com.hedera.hashgraph.sdk.ContractFunctionParameters)32 DisplayName (org.junit.jupiter.api.DisplayName)30 Test (org.junit.jupiter.api.Test)30 ContractCreateTransaction (com.hedera.hashgraph.sdk.ContractCreateTransaction)29 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)28 ContractDeleteTransaction (com.hedera.hashgraph.sdk.ContractDeleteTransaction)23 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)22 Var (com.google.errorprone.annotations.Var)18 ContractInfoQuery (com.hedera.hashgraph.sdk.ContractInfoQuery)10 ContractCallQuery (com.hedera.hashgraph.sdk.ContractCallQuery)8 Hbar (com.hedera.hashgraph.sdk.Hbar)8 ContractExecuteTransaction (com.hedera.hashgraph.sdk.ContractExecuteTransaction)6 ContractByteCodeQuery (com.hedera.hashgraph.sdk.ContractByteCodeQuery)4 MaxQueryPaymentExceededException (com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException)3 ContractUpdateTransaction (com.hedera.hashgraph.sdk.ContractUpdateTransaction)2 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1 Client (com.hedera.hashgraph.sdk.Client)1 ContractCreateFlow (com.hedera.hashgraph.sdk.ContractCreateFlow)1 ContractFunctionResult (com.hedera.hashgraph.sdk.ContractFunctionResult)1