use of com.hedera.hashgraph.sdk.FileInfoQuery in project hedera-sdk-java by hashgraph.
the class DeleteFileExample method main.
public static void main(String[] args) throws PrecheckStatusException, TimeoutException, 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).setContents(fileContents).setMaxTransactionFee(new Hbar(2)).execute(client);
TransactionReceipt receipt = transactionResponse.getReceipt(client);
FileId newFileId = Objects.requireNonNull(receipt.fileId);
System.out.println("file: " + newFileId);
// now delete the file
TransactionResponse fileDeleteTransactionResponse = new FileDeleteTransaction().setFileId(newFileId).execute(client);
// if this doesn't throw then the transaction was a success
fileDeleteTransactionResponse.getReceipt(client);
System.out.println("File deleted successfully.");
new FileInfoQuery().setFileId(newFileId).execute(client);
// note the above fileInfo will fail with FILE_DELETED due to a known issue on Hedera
}
use of com.hedera.hashgraph.sdk.FileInfoQuery in project hedera-sdk-java by hashgraph.
the class FileAppendIntegrationTest method canAppendLargeContentsToFileDespiteExpiration.
@Test
@DisplayName("Can append large contents to file despite TRANSACTION_EXPIRATION response codes")
void canAppendLargeContentsToFileDespiteExpiration() 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));
var appendTx = new FileAppendTransaction().setFileId(fileId).setContents(Contents.BIG_CONTENTS).setTransactionValidDuration(Duration.ofSeconds(25)).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();
}
use of com.hedera.hashgraph.sdk.FileInfoQuery in project hedera-sdk-java by hashgraph.
the class FileCreateIntegrationTest method canCreateFileWithNoContents.
@Test
@DisplayName("Can create file with no contents")
void canCreateFileWithNoContents() throws Exception {
var testEnv = new IntegrationTestEnv(1);
var response = new FileCreateTransaction().setKeys(testEnv.operatorKey).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).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();
}
use of com.hedera.hashgraph.sdk.FileInfoQuery 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();
}
use of com.hedera.hashgraph.sdk.FileInfoQuery 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();
}
Aggregations