text: import {
      FileAppendTransaction,
      FileCreateTransaction,
      FileDeleteTransaction,
      FileInfoQuery,
      Hbar,
      Status,
  } from "../../src/exports.js";
  import { bigContents } from "./contents.js";
  import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js";
  
  describe("FileAppend", function () {
      it("should be executable", async function () {
          this.timeout(120000);
  
          const env = await IntegrationTestEnv.new();
          const operatorKey = env.operatorKey.publicKey;
  
          let response = await new FileCreateTransaction()
              .setKeys([operatorKey])
              .setContents("[e2e::FileCreateTransaction]")
              .execute(env.client);
  
          let receipt = await response.getReceipt(env.client);
  
          expect(receipt.fileId).to.not.be.null;
          expect(receipt.fileId != null ? receipt.fileId.num > 0 : false).to.be
              .true;
  
          const file = receipt.fileId;
  
          let info = await new FileInfoQuery()
              .setFileId(file)
              .setQueryPayment(new Hbar(22))
              .execute(env.client);
  
          expect(info.fileId.toString()).to.be.equal(file.toString());
          expect(info.size.toInt()).to.be.equal(28);
          expect(info.isDeleted).to.be.false;
          expect(info.keys.toArray().length).to.be.equal(1);
  
          // There should only be one key
          for (const key of info.keys) {
              expect(key.toString()).to.be.equal(operatorKey.toString());
          }
  
          await (
              await new FileAppendTransaction()
                  .setFileId(file)
                  .setContents("[e2e::FileAppendTransaction]")
                  .execute(env.client)
          ).getReceipt(env.client);
  
          info = await new FileInfoQuery()
              .setFileId(file)
              .setQueryPayment(new Hbar(1))
              .execute(env.client);
  
          expect(info.fileId.toString()).to.be.equal(file.toString());
          expect(info.size.toInt()).to.be.equal(56);
          expect(info.isDeleted).to.be.false;
          expect(info.keys.toArray().length).to.be.equal(1);
  
          // There should only be one key
          for (const key of info.keys) {
              expect(key.toString()).to.be.equal(operatorKey.toString());
          }
  
          await (
              await new FileDeleteTransaction()
                  .setFileId(file)
                  .execute(env.client)
          ).getReceipt(env.client);
  
          await env.close();
      });
  
      it("should be chunk contents", async function () {
          this.timeout(120000 * 2);
  
          const env = await IntegrationTestEnv.new();
          const operatorKey = env.operatorKey.publicKey;
  
          let response = await new FileCreateTransaction()
              .setKeys([operatorKey])
              .setContents("[e2e::FileCreateTransaction]")
              .execute(env.client);
  
          let receipt = await response.getReceipt(env.client);
  
          expect(receipt.fileId).to.not.be.null;
          expect(receipt.fileId != null ? receipt.fileId.num > 0 : false).to.be
              .true;
  
          const file = receipt.fileId;
  
          let info = await new FileInfoQuery()
              .setFileId(file)
              .setQueryPayment(new Hbar(22))
              .execute(env.client);
  
          expect(info.fileId.toString()).to.be.equal(file.toString());
          expect(info.size.toInt()).to.be.equal(28);
          expect(info.isDeleted).to.be.false;
          expect(info.keys.toArray().length).to.be.equal(1);
  
          // There should only be one key
          for (const key of info.keys) {
              expect(key.toString()).to.be.equal(operatorKey.toString());
          }
  
          await (
              await new FileAppendTransaction()
                  .setFileId(file)
                  .setContents(bigContents)
                  .execute(env.client)
          ).getReceipt(env.client);
  
          info = await new FileInfoQuery()
              .setFileId(file)
              .setQueryPayment(new Hbar(1))
              .execute(env.client);
  
          expect(info.fileId.toString()).to.be.equal(file.toString());
          expect(info.size.toInt()).to.be.equal(13523);
          expect(info.isDeleted).to.be.false;
          expect(info.keys.toArray().length).to.be.equal(1);
  
          // There should only be one key
          for (const key of info.keys) {
              expect(key.toString()).to.be.equal(operatorKey.toString());
          }
  
          await (
              await new FileDeleteTransaction()
                  .setFileId(file)
                  .execute(env.client)
          ).getReceipt(env.client);
  
          await env.close();
      });
  
      it("should error with no file ID set", async function () {
          this.timeout(120000);
  
          const env = await IntegrationTestEnv.new();
          const operatorKey = env.operatorKey.publicKey;
  
          let response = await new FileCreateTransaction()
              .setKeys([operatorKey])
              .setContents("[e2e::FileCreateTransaction]")
              .execute(env.client);
  
          let receipt = await response.getReceipt(env.client);
  
          expect(receipt.fileId).to.not.be.null;
          expect(receipt.fileId != null ? receipt.fileId.num > 0 : false).to.be
              .true;
  
          const file = receipt.fileId;
  
          let err = false;
  
          try {
              await (
                  await new FileAppendTransaction()
                      .setContents("[e2e::FileAppendTransaction]")
                      .execute(env.client)
              ).getReceipt(env.client);
          } catch (error) {
              err = error.toString().includes(Status.InvalidFileId);
          }
  
          await (
              await new FileDeleteTransaction()
                  .setFileId(file)
                  .execute(env.client)
          ).getReceipt(env.client);
  
          if (!err) {
              throw new Error("file append transaction did not error");
          }
  
          await env.close();
      });
  
      it("should not error with no contents appended", async function () {
          this.timeout(120000);
  
          const env = await IntegrationTestEnv.new();
          const operatorKey = env.operatorKey.publicKey;
  
          let response = await new FileCreateTransaction()
              .setKeys([operatorKey])
              .setContents("[e2e::FileCreateTransaction]")
              .execute(env.client);
  
          let receipt = await response.getReceipt(env.client);
  
          expect(receipt.fileId).to.not.be.null;
          expect(receipt.fileId != null ? receipt.fileId.num > 0 : false).to.be
              .true;
  
          const file = receipt.fileId;
  
          await (
              await new FileAppendTransaction()
                  .setFileId(file)
                  .execute(env.client)
          ).getReceipt(env.client);
  
          await (
              await new FileDeleteTransaction()
                  .setFileId(file)
                  .execute(env.client)
          ).getReceipt(env.client);
  
          await env.close();
      });
  });
  