Search in sources :

Example 1 with FileUpdateTransaction

use of com.hedera.hashgraph.sdk.FileUpdateTransaction in project hedera-mirror-node by hashgraph.

the class FileClient method updateFile.

public NetworkTransactionResponse updateFile(FileId fileId, byte[] byteCode) {
    log.debug("Update file");
    String memo = getMemo("Update file");
    FileUpdateTransaction fileUpdateTransaction = new FileUpdateTransaction().setFileId(fileId).setFileMemo(memo).setTransactionMemo(memo);
    if (byteCode != null) {
        fileUpdateTransaction.setContents(byteCode);
    }
    NetworkTransactionResponse networkTransactionResponse = executeTransactionAndRetrieveReceipt(fileUpdateTransaction);
    log.debug("Updated file {}", fileId);
    return networkTransactionResponse;
}
Also used : FileUpdateTransaction(com.hedera.hashgraph.sdk.FileUpdateTransaction) NetworkTransactionResponse(com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)

Example 2 with FileUpdateTransaction

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

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

Aggregations

FileUpdateTransaction (com.hedera.hashgraph.sdk.FileUpdateTransaction)3 FileCreateTransaction (com.hedera.hashgraph.sdk.FileCreateTransaction)2 FileInfoQuery (com.hedera.hashgraph.sdk.FileInfoQuery)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 Var (com.google.errorprone.annotations.Var)1 FileDeleteTransaction (com.hedera.hashgraph.sdk.FileDeleteTransaction)1 NetworkTransactionResponse (com.hedera.mirror.test.e2e.acceptance.response.NetworkTransactionResponse)1