Search in sources :

Example 46 with FileCreateTransaction

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

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

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

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

Example 50 with FileCreateTransaction

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

the class CreateFileExample method main.

public static void main(String[] args) throws TimeoutException, PrecheckStatusException, ReceiptStatusException {
    Client client = Client.forName(HEDERA_NETWORK);
    // Defaults the operator account ID and key such that all generated transactions will be paid for
    // by this account and be signed by this key
    client.setOperator(OPERATOR_ID, OPERATOR_KEY);
    // The file is required to be a byte array,
    // you can easily use the bytes of a file instead.
    String fileContents = "Hedera hashgraph is great!";
    TransactionResponse transactionResponse = new FileCreateTransaction().setKeys(OPERATOR_KEY.getPublicKey()).setContents(fileContents).setMaxTransactionFee(// 2 HBAR
    new Hbar(2)).execute(client);
    TransactionReceipt receipt = transactionResponse.getReceipt(client);
    FileId newFileId = receipt.fileId;
    System.out.println("file: " + newFileId);
}
Also used : FileCreateTransaction(com.hedera.hashgraph.sdk.FileCreateTransaction) TransactionResponse(com.hedera.hashgraph.sdk.TransactionResponse) TransactionReceipt(com.hedera.hashgraph.sdk.TransactionReceipt) Hbar(com.hedera.hashgraph.sdk.Hbar) FileId(com.hedera.hashgraph.sdk.FileId) Client(com.hedera.hashgraph.sdk.Client)

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