Search in sources :

Example 31 with FileDeleteTransaction

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

the class ContractInfoIntegrationTest method canQueryContractInfo.

@Test
@DisplayName("Can query contract info")
void canQueryContractInfo() 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 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 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) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 32 with FileDeleteTransaction

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

the class ContractInfoIntegrationTest method getCostInsufficientTxFeeContractInfoFunction.

@Test
@DisplayName("Insufficient tx fee error.")
void getCostInsufficientTxFeeContractInfoFunction() 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 infoQuery = new ContractInfoQuery().setContractId(contractId).setMaxQueryPayment(new Hbar(100));
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        infoQuery.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) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) Hbar(com.hedera.hashgraph.sdk.Hbar) ContractInfoQuery(com.hedera.hashgraph.sdk.ContractInfoQuery) ContractCreateTransaction(com.hedera.hashgraph.sdk.ContractCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 33 with FileDeleteTransaction

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

the class ContractInfoIntegrationTest method getCostSmallMaxContractInfoFunction.

@Test
@DisplayName("Error, max is smaller than set payment.")
void getCostSmallMaxContractInfoFunction() 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 infoQuery = new ContractInfoQuery().setContractId(contractId).setMaxQueryPayment(Hbar.fromTinybars(1));
    assertThatExceptionOfType(MaxQueryPaymentExceededException.class).isThrownBy(() -> {
        infoQuery.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 : 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) ContractInfoQuery(com.hedera.hashgraph.sdk.ContractInfoQuery) ContractCreateTransaction(com.hedera.hashgraph.sdk.ContractCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 34 with FileDeleteTransaction

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

the class FileAppendIntegrationTest method canAppendLargeContentsToFile.

@Test
@DisplayName("Can append large contents to file")
void canAppendLargeContentsToFile() throws Exception {
    // There are potential bugs in FileAppendTransaction which require more than one node to trigger.
    var testEnv = new IntegrationTestEnv(2);
    var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents("[e2e::FileCreateTransaction]").execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
    Thread.sleep(5000);
    @Var var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(28);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNotNull();
    assertThat(info.keys.getThreshold()).isNull();
    assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey));
    new FileAppendTransaction().setFileId(fileId).setContents(Contents.BIG_CONTENTS).execute(testEnv.client).getReceipt(testEnv.client);
    var contents = new FileContentsQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(contents.toStringUtf8()).isEqualTo("[e2e::FileCreateTransaction]" + Contents.BIG_CONTENTS);
    info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(13522);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNotNull();
    assertThat(info.keys.getThreshold()).isNull();
    assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey));
    new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : FileContentsQuery(com.hedera.hashgraph.sdk.FileContentsQuery) FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) FileInfoQuery(com.hedera.hashgraph.sdk.FileInfoQuery) Var(com.google.errorprone.annotations.Var) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) FileAppendTransaction(com.hedera.hashgraph.sdk.FileAppendTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 35 with FileDeleteTransaction

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

the class FileAppendIntegrationTest method canAppendToFile.

@Test
@DisplayName("Can append to file")
void canAppendToFile() throws Exception {
    // There are potential bugs in FileAppendTransaction which require more than one node to trigger.
    var testEnv = new IntegrationTestEnv(1);
    var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).setContents("[e2e::FileCreateTransaction]").execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
    @Var var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(28);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNotNull();
    assertThat(info.keys.getThreshold()).isNull();
    assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey));
    new FileAppendTransaction().setFileId(fileId).setContents("[e2e::FileAppendTransaction]").execute(testEnv.client).getReceipt(testEnv.client);
    info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(56);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNotNull();
    assertThat(info.keys.getThreshold()).isNull();
    assertThat(info.keys).isEqualTo(KeyList.of(testEnv.operatorKey));
    new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
    testEnv.close();
}
Also used : FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) FileInfoQuery(com.hedera.hashgraph.sdk.FileInfoQuery) Var(com.google.errorprone.annotations.Var) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) FileAppendTransaction(com.hedera.hashgraph.sdk.FileAppendTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)41 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)40 DisplayName (org.junit.jupiter.api.DisplayName)39 Test (org.junit.jupiter.api.Test)39 ContractCreateTransaction (com.hedera.hashgraph.sdk.ContractCreateTransaction)23 ContractFunctionParameters (com.hedera.hashgraph.sdk.ContractFunctionParameters)22 ContractDeleteTransaction (com.hedera.hashgraph.sdk.ContractDeleteTransaction)21 Var (com.google.errorprone.annotations.Var)20 FileInfoQuery (com.hedera.hashgraph.sdk.FileInfoQuery)12 Hbar (com.hedera.hashgraph.sdk.Hbar)11 ContractCallQuery (com.hedera.hashgraph.sdk.ContractCallQuery)7 ContractInfoQuery (com.hedera.hashgraph.sdk.ContractInfoQuery)7 FileContentsQuery (com.hedera.hashgraph.sdk.FileContentsQuery)7 MaxQueryPaymentExceededException (com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException)5 ContractByteCodeQuery (com.hedera.hashgraph.sdk.ContractByteCodeQuery)4 ContractExecuteTransaction (com.hedera.hashgraph.sdk.ContractExecuteTransaction)3 FileAppendTransaction (com.hedera.hashgraph.sdk.FileAppendTransaction)3 Client (com.hedera.hashgraph.sdk.Client)1 ContractUpdateTransaction (com.hedera.hashgraph.sdk.ContractUpdateTransaction)1 FileId (com.hedera.hashgraph.sdk.FileId)1