Search in sources :

Example 11 with FileInfoQuery

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

the class FileCreateIntegrationTest method canCreateFileWithNoKeys.

@Test
@DisplayName("Can create file with no keys")
void canCreateFileWithNoKeys() 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 12 with FileInfoQuery

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

the class FileCreateIntegrationTest method canCreateFile.

@Test
@DisplayName("Can create file")
void canCreateFile() 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 13 with FileInfoQuery

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

the class FileInfoIntegrationTest method getCostBigMaxQueryFileInfo.

@Test
@DisplayName("Can get cost, even with a big max")
@SuppressWarnings("UnusedVariable")
void getCostBigMaxQueryFileInfo() 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(new Hbar(1000));
    var cost = infoQuery.getCost(testEnv.client);
    var info = infoQuery.setQueryPayment(cost).execute(testEnv.client);
    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) Hbar(com.hedera.hashgraph.sdk.Hbar) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 14 with FileInfoQuery

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

the class FileInfoIntegrationTest method getCostSmallMaxQueryFileInfo.

@Test
@DisplayName("Error, max is smaller than set payment.")
void getCostSmallMaxQueryFileInfo() 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(MaxQueryPaymentExceededException.class).isThrownBy(() -> {
        infoQuery.execute(testEnv.client);
    });
    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) MaxQueryPaymentExceededException(com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException) FileDeleteTransaction(com.hedera.hashgraph.sdk.FileDeleteTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 15 with FileInfoQuery

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

the class FileInfoIntegrationTest method canQueryFileInfo.

@Test
@DisplayName("Can query file info")
void canQueryFileInfo() 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)

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