Search in sources :

Example 1 with ContractDeleteTransaction

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

the class ContractBytecodeIntegrationTest method getCostInsufficientTxFeeQueryContractBytecode.

@Test
@DisplayName("Insufficient tx fee error.")
void getCostInsufficientTxFeeQueryContractBytecode() 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(100));
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        bytecodeQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client);
    }).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE"));
    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)

Example 2 with ContractDeleteTransaction

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

the class ContractBytecodeIntegrationTest method getCostSmallMaxQueryContractBytecode.

@Test
@DisplayName("Error, max is smaller than set payment.")
void getCostSmallMaxQueryContractBytecode() 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(Hbar.fromTinybars(1));
    assertThatExceptionOfType(MaxQueryPaymentExceededException.class).isThrownBy(() -> {
        bytecodeQuery.execute(testEnv.client);
    });
    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) MaxQueryPaymentExceededException(com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException) 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 3 with ContractDeleteTransaction

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

the class ContractCallIntegrationTest method cannotCallContractFunctionWhenContractIDIsNotSet.

@Test
@DisplayName("Cannot call contract function when contract ID is not set")
void cannotCallContractFunctionWhenContractIDIsNotSet() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents(SMART_CONTRACT_BYTECODE).execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.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 ContractCallQuery().setGas(100000).setFunction("getMessage").execute(testEnv.client);
    }).withMessageContaining(Status.INVALID_CONTRACT_ID.toString());
    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) ContractFunctionParameters(com.hedera.hashgraph.sdk.ContractFunctionParameters) ContractCallQuery(com.hedera.hashgraph.sdk.ContractCallQuery) 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 4 with ContractDeleteTransaction

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

the class ContractCallIntegrationTest method getCostInsufficientTxFeeContractCallFunction.

@Test
@DisplayName("Insufficient tx fee error.")
void getCostInsufficientTxFeeContractCallFunction() 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 callQuery = new ContractCallQuery().setContractId(contractId).setGas(100000).setFunction("getMessage").setMaxQueryPayment(new Hbar(100));
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        callQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client);
    }).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE"));
    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) ContractCallQuery(com.hedera.hashgraph.sdk.ContractCallQuery) 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)

Example 5 with ContractDeleteTransaction

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

the class ContractCallIntegrationTest method canCallContractFunction.

@Test
@DisplayName("Can call contract function")
void canCallContractFunction() 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 callQuery = new ContractCallQuery().setContractId(contractId).setGas(100000).setFunction("getMessage").setQueryPayment(new Hbar(1));
    var result = callQuery.execute(testEnv.client);
    assertThat(result.getString(0)).isEqualTo("Hello from Hedera.");
    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) ContractCallQuery(com.hedera.hashgraph.sdk.ContractCallQuery) 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

ContractDeleteTransaction (com.hedera.hashgraph.sdk.ContractDeleteTransaction)26 DisplayName (org.junit.jupiter.api.DisplayName)24 Test (org.junit.jupiter.api.Test)24 ContractCreateTransaction (com.hedera.hashgraph.sdk.ContractCreateTransaction)23 ContractFunctionParameters (com.hedera.hashgraph.sdk.ContractFunctionParameters)23 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)23 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)21 Var (com.google.errorprone.annotations.Var)16 ContractCallQuery (com.hedera.hashgraph.sdk.ContractCallQuery)8 ContractInfoQuery (com.hedera.hashgraph.sdk.ContractInfoQuery)8 Hbar (com.hedera.hashgraph.sdk.Hbar)8 ContractByteCodeQuery (com.hedera.hashgraph.sdk.ContractByteCodeQuery)4 ContractExecuteTransaction (com.hedera.hashgraph.sdk.ContractExecuteTransaction)4 MaxQueryPaymentExceededException (com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException)3 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 ContractId (com.hedera.hashgraph.sdk.ContractId)1