Search in sources :

Example 6 with FileInfoQuery

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

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

the class FileUpdateIntegrationTest method cannotUpdateImmutableFile.

@Test
@DisplayName("Cannot update immutable file")
void cannotUpdateImmutableFile() throws Exception {
    var testEnv = new IntegrationTestEnv(1);
    var response = new FileCreateTransaction().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).isNull();
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new FileUpdateTransaction().setFileId(fileId).setContents("[e2e::FileUpdateTransaction]").execute(testEnv.client).getReceipt(testEnv.client);
    }).withMessageContaining(Status.UNAUTHORIZED.toString());
    testEnv.close();
}
Also used : FileUpdateTransaction(com.hedera.hashgraph.sdk.FileUpdateTransaction) 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 8 with FileInfoQuery

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

the class FileUpdateIntegrationTest method canUpdateFile.

@Test
@DisplayName("Can update file")
void canUpdateFile() 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 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 FileUpdateTransaction().setFileId(fileId).setContents("[e2e::FileUpdateTransaction]").execute(testEnv.client).getReceipt(testEnv.client);
    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 : FileUpdateTransaction(com.hedera.hashgraph.sdk.FileUpdateTransaction) FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) FileInfoQuery(com.hedera.hashgraph.sdk.FileInfoQuery) Var(com.google.errorprone.annotations.Var) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with FileInfoQuery

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

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

FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)16 FileInfoQuery (com.hedera.hashgraph.sdk.FileInfoQuery)16 DisplayName (org.junit.jupiter.api.DisplayName)14 Test (org.junit.jupiter.api.Test)14 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)12 Var (com.google.errorprone.annotations.Var)4 FileAppendTransaction (com.hedera.hashgraph.sdk.FileAppendTransaction)4 Hbar (com.hedera.hashgraph.sdk.Hbar)3 Client (com.hedera.hashgraph.sdk.Client)2 FileContentsQuery (com.hedera.hashgraph.sdk.FileContentsQuery)2 FileId (com.hedera.hashgraph.sdk.FileId)2 FileUpdateTransaction (com.hedera.hashgraph.sdk.FileUpdateTransaction)2 TransactionReceipt (com.hedera.hashgraph.sdk.TransactionReceipt)2 TransactionResponse (com.hedera.hashgraph.sdk.TransactionResponse)2 FileInfo (com.hedera.hashgraph.sdk.FileInfo)1 MaxQueryPaymentExceededException (com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException)1