Search in sources :

Example 21 with FileCreateTransaction

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

the class FileDeleteIntegrationTest method canDeleteFile.

@Test
@DisplayName("Can delete file")
void canDeleteFile() throws Exception {
    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 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 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) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 22 with FileCreateTransaction

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

the class FileInfoIntegrationTest method canQueryFileInfoWithNoAdminKeyOrContents.

@Test
@DisplayName("Can query file info with no admin key or contents")
void canQueryFileInfoWithNoAdminKeyOrContents() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var response = new FileCreateTransaction().execute(testEnv.client);
    var fileId = Objects.requireNonNull(response.getReceipt(testEnv.client).fileId);
    var info = new FileInfoQuery().setFileId(fileId).execute(testEnv.client);
    assertThat(info.fileId).isEqualTo(fileId);
    assertThat(info.size).isEqualTo(0);
    assertThat(info.isDeleted).isFalse();
    assertThat(info.keys).isNull();
    testEnv.close();
}
Also used : FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) FileInfoQuery(com.hedera.hashgraph.sdk.FileInfoQuery) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 23 with FileCreateTransaction

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

the class FileInfoIntegrationTest method getCostInsufficientTxFeeQueryFileInfo.

@Test
@DisplayName("Insufficient tx fee error.")
void getCostInsufficientTxFeeQueryFileInfo() throws Exception {
    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 infoQuery = new FileInfoQuery().setFileId(fileId).setMaxQueryPayment(Hbar.fromTinybars(1));
    assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
        infoQuery.setQueryPayment(Hbar.fromTinybars(1)).execute(testEnv.client);
    }).satisfies(error -> assertThat(error.status.toString()).isEqualTo("INSUFFICIENT_TX_FEE"));
    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) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 24 with FileCreateTransaction

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

the class FileClient method createFile.

public NetworkTransactionResponse createFile(byte[] content) {
    log.debug("Create new file");
    String memo = getMemo("Create file");
    FileCreateTransaction fileCreateTransaction = new FileCreateTransaction().setKeys(sdkClient.getExpandedOperatorAccountId().getPublicKey()).setContents(content).setFileMemo(memo).setTransactionMemo(memo);
    NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(fileCreateTransaction, KeyList.of(sdkClient.getExpandedOperatorAccountId().getPrivateKey()));
    FileId fileId = networkTransactionResponse.getReceipt().fileId;
    log.debug("Created new file {}", fileId);
    return networkTransactionResponse;
}
Also used : FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse) FileId(com.hedera.hashgraph.sdk.FileId)

Example 25 with FileCreateTransaction

use of com.hedera.hashgraph.sdk.FileCreateTransaction 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)

Aggregations

FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)54 DisplayName (org.junit.jupiter.api.DisplayName)47 Test (org.junit.jupiter.api.Test)47 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)40 ContractCreateTransaction (com.hedera.hashgraph.sdk.ContractCreateTransaction)30 ContractFunctionParameters (com.hedera.hashgraph.sdk.ContractFunctionParameters)28 ContractDeleteTransaction (com.hedera.hashgraph.sdk.ContractDeleteTransaction)23 Var (com.google.errorprone.annotations.Var)22 FileInfoQuery (com.hedera.hashgraph.sdk.FileInfoQuery)16 Hbar (com.hedera.hashgraph.sdk.Hbar)16 ContractInfoQuery (com.hedera.hashgraph.sdk.ContractInfoQuery)10 ContractCallQuery (com.hedera.hashgraph.sdk.ContractCallQuery)9 FileContentsQuery (com.hedera.hashgraph.sdk.FileContentsQuery)8 FileId (com.hedera.hashgraph.sdk.FileId)7 Client (com.hedera.hashgraph.sdk.Client)6 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)6 MaxQueryPaymentExceededException (com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException)5 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)5 ContractByteCodeQuery (com.hedera.hashgraph.sdk.ContractByteCodeQuery)4 ContractExecuteTransaction (com.hedera.hashgraph.sdk.ContractExecuteTransaction)4