Search in sources :

Example 1 with ContractUpdateTransaction

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

the class ContractUpdateIntegrationTest method cannotUpdateContractThatIsImmutable.

@Test
@DisplayName("Cannot update contract that is immutable")
void cannotUpdateContractThatIsImmutable() 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().setGas(100000).setConstructorParameters(new ContractFunctionParameters().addString("Hello from Hedera.")).setBytecodeFileId(fileId).setContractMemo("[e2e::ContractCreateTransaction]").execute(testEnv.client).getReceipt(testEnv.client).contractId);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new ContractUpdateTransaction().setContractId(contractId).setContractMemo("[e2e::ContractUpdateTransaction]").execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.MODIFYING_IMMUTABLE_CONTRACT.toString());
    testEnv.close();
}
Also used : FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) ContractFunctionParameters(com.hedera.hashgraph.sdk.ContractFunctionParameters) 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 2 with ContractUpdateTransaction

use of com.hedera.hashgraph.sdk.ContractUpdateTransaction 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 3 with ContractUpdateTransaction

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

the class ContractClient method updateContract.

public NetworkTransactionResponse updateContract(ContractId contractId) {
    log.debug("Update contract {}", contractId);
    String memo = getMemo("Update contract");
    ContractUpdateTransaction contractUpdateTransaction = new ContractUpdateTransaction().setContractId(contractId).setContractMemo(memo).setTransactionMemo(memo);
    NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(contractUpdateTransaction);
    log.debug("Updated contract {}", contractId);
    return networkTransactionResponse;
}
Also used : NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) ContractUpdateTransaction(com.hedera.hashgraph.sdk.ContractUpdateTransaction)

Aggregations

ContractUpdateTransaction (com.hedera.hashgraph.sdk.ContractUpdateTransaction)3 ContractCreateTransaction (com.hedera.hashgraph.sdk.ContractCreateTransaction)2 ContractFunctionParameters (com.hedera.hashgraph.sdk.ContractFunctionParameters)2 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 Var (com.google.errorprone.annotations.Var)1 ContractDeleteTransaction (com.hedera.hashgraph.sdk.ContractDeleteTransaction)1 ContractInfoQuery (com.hedera.hashgraph.sdk.ContractInfoQuery)1 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)1 NetworkTransactionResponse (com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)1