Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileAppendTransaction incorrect content after deserialization #2167

Closed
SvetBorislavov opened this issue Feb 24, 2024 · 2 comments · Fixed by #2532
Closed

FileAppendTransaction incorrect content after deserialization #2167

SvetBorislavov opened this issue Feb 24, 2024 · 2 comments · Fixed by #2532
Assignees
Labels
bug Something isn't working p1
Milestone

Comments

@SvetBorislavov
Copy link
Contributor

Description

Serializing and then deserializing a FileAppendTransaction causes incorrect content to be set.
After the deserialization, the content is sliced to the chunk size.
Ex. If you have a content length of 100_000 after the deserialization, the content will consist only of the first {chunkSize} bytes.

Steps to reproduce

  1. Run this snippet
const { FileAppendTransaction } = require('@hashgraph/sdk');

async function run() {
  const contentLength = 632421;
  const content = generateUInt8Array(contentLength);

  const transaction = new FileAppendTransaction()
    .setTransactionValidDuration(180)
    .setContents(content);

  console.log(transaction.contents.length); //632421 (content length)

  const transactionBytes = transaction.toBytes();

  const transactionFromBytes =
    FileAppendTransaction.fromBytes(transactionBytes);

  console.log(transactionFromBytes.contents.length); //4096 (default chunk size)
}
run();

function generateUInt8Array(length) {
  const uint8Array = new Uint8Array(length);

  for (let i = 0; i < length; i++) {
    uint8Array[i] = Math.floor(Math.random() * 256);
  }

  return uint8Array;
}

Additional context

No response

Hedera network

other

Version

v2.42.0-beta.4

Operating system

None

@SvetBorislavov
Copy link
Contributor Author

Currently testing with version 2.52.0-beta.3 and the following issue has been found:
After serializing and deserializing the FileAppendTransaction the following properties have been reset to their default values: transactionId, maxChunks, chunkSize.
To reproduce, please run the following snippet:

/* imports */
const {
  Client,
  AccountId,
  Transaction,
  FileAppendTransaction,
  TransactionId,
  Timestamp,
  Hbar,
} = require('@hashgraph/sdk');

async function run() {
  const accountId = AccountId.fromString('0.0.2159149');
  const client = Client.forTestnet();

  // Generate random contents
  const contents = generateUInt8Array(10 * 1024);

  // Create a File Append Transaction
  let transaction = new FileAppendTransaction()
    .setTransactionId(
      TransactionId.withValidStart(accountId, Timestamp.fromDate(new Date()))
    )
    .setMaxChunks(999)
    .setChunkSize(1024)
    .setFileId('0.0.111')
    .setMaxTransactionFee(Hbar.fromTinybars(3333333))
    .setTransactionMemo('File Append Test')
    .setTransactionValidDuration(180)
    .setContents(contents);

  // Serialize
  const transactionBytes = transaction.toBytes();

  // Deserialize
  transaction = Transaction.fromBytes(transactionBytes);

  // Verify the bug
  console.log('transactionId', transaction.transactionId.toString());
  console.log('maxChunks', transaction.maxChunks);
  console.log('chunkSize', transaction.chunkSize);
  console.log('fileId', transaction.fileId.toString());
  console.log('maxTransactionFee', transaction.maxTransactionFee.toString());
  console.log('transactionMemo', transaction.transactionMemo);
  console.log('transactionValidDuration', transaction.transactionValidDuration);
  console.log('contents', transaction.contents.length);

  client.close();
}

function generateUInt8Array(length) {
  const uint8Array = new Uint8Array(length);

  for (let i = 0; i < length; i++) {
    uint8Array[i] = Math.floor(Math.random() * 256);
  }

  return uint8Array;
}

run();

As you can see from the logs, the properties have incorrect values

@SimiHunjan
Copy link
Contributor

Closing as this should be released in 0.52.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants