use of com.hedera.hashgraph.sdk.FileContentsQuery in project hedera-sdk-java by hashgraph.
the class FileContentsIntegrationTest method getCostInsufficientTxFeeQueryFileContents.
@Test
@DisplayName("Insufficient tx fee error.")
void getCostInsufficientTxFeeQueryFileContents() 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 contentsQuery = new FileContentsQuery().setFileId(fileId).setMaxQueryPayment(new Hbar(100));
assertThatExceptionOfType(PrecheckStatusException.class).isThrownBy(() -> {
contentsQuery.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();
}
use of com.hedera.hashgraph.sdk.FileContentsQuery in project hedera-mirror-node by hashgraph.
the class SDKClient method getAddressBookFromNetwork.
private NodeAddressBook getAddressBookFromNetwork(Client client) throws TimeoutException, PrecheckStatusException, InvalidProtocolBufferException {
ByteString contents = new FileContentsQuery().setFileId(ADDRESS_BOOK_ID).setMaxQueryPayment(new Hbar(1)).execute(client);
log.debug("Retrieved address book with content size: {} b", contents.size());
return NodeAddressBook.parseFrom(contents.toByteArray());
}
use of com.hedera.hashgraph.sdk.FileContentsQuery 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();
}
use of com.hedera.hashgraph.sdk.FileContentsQuery in project hedera-sdk-java by hashgraph.
the class FileContentsIntegrationTest method canQueryFileContents.
@Test
@DisplayName("Can query file contents")
void canQueryFileContents() 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 contents = new FileContentsQuery().setFileId(fileId).execute(testEnv.client);
assertThat(contents.toStringUtf8()).isEqualTo("[e2e::FileCreateTransaction]");
new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
use of com.hedera.hashgraph.sdk.FileContentsQuery in project hedera-sdk-java by hashgraph.
the class FileContentsIntegrationTest method getCostSmallMaxQueryFileContents.
@Test
@DisplayName("Error, max is smaller than set payment.")
void getCostSmallMaxQueryFileContents() 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 contentsQuery = new FileContentsQuery().setFileId(fileId).setMaxQueryPayment(Hbar.fromTinybars(1));
assertThatExceptionOfType(MaxQueryPaymentExceededException.class).isThrownBy(() -> {
contentsQuery.execute(testEnv.client);
});
new FileDeleteTransaction().setFileId(fileId).execute(testEnv.client).getReceipt(testEnv.client);
testEnv.close();
}
Aggregations