Skip to content

fix: ensure byte arrays are decoded as Uint8Array #406

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

Merged
merged 3 commits into from
May 30, 2025

Conversation

joe-p
Copy link
Contributor

@joe-p joe-p commented May 23, 2025

This PR ensures all byte arrays, even nested ones, are decoded as Uint8Array. This change affects the following values

  • Composer method calls (and thus AppClient method calls)
  • Composer simulation results
  • AppClient state values
  • AppClient state keys

We ideally should have consistent decoding everywhere, so if there's other places that we are decoding ABI values that I've missed let me know!

Fixes #395

@joe-p joe-p force-pushed the fix/decoded_byte_arrays branch 2 times, most recently from 5fd4c1d to 992c756 Compare May 23, 2025 19:16
@joe-p joe-p marked this pull request as ready for review May 23, 2025 19:16
@joe-p joe-p requested a review from Copilot May 23, 2025 19:16
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a utility to recursively convert decoded ABI byte arrays into Uint8Array and applies it across method return decoding, composer results, state getters, and ARC56 struct decoding.

  • Introduce convertAbiByteArrays in src/util.ts and include extensive tests.
  • Update all code paths (transaction composer, app manager, app client, ARC56 decoding) to apply the conversion.
  • Add byte array examples and tests in tests/example-contracts/byte_arrays.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/example-contracts/byte_arrays/... Add example contract, configs, and artifacts for byte array tests
src/util.ts Implement convertAbiByteArrays to normalize byte arrays
src/util.spec.ts Add unit tests covering various ABI value conversion scenarios
src/types/composer.ts Pass ABI return types into composer’s return mapping
src/types/app-manager.ts Pass ABI return types into app manager response parsing
src/types/app-client.ts Tighten state getter error on missing metadata
src/types/app-arc56.ts Convert struct and decoded values through convertAbiByteArrays
src/transaction/transaction.ts Apply byte-array conversion in transaction composer and return decoding

@@ -2135,13 +2135,14 @@ export class TransactionComposer {
}

const transactions = atc.buildGroup().map((t) => t.txn)
const methodCalls = [...(atc['methodCalls'] as Map<number, ABIMethod>).values()]
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Accessing the private atc['methodCalls'] map is brittle and may break if the internal API changes. Consider using a public property or capturing method calls at compose time instead.

Suggested change
const methodCalls = [...(atc['methodCalls'] as Map<number, ABIMethod>).values()]
const methodCalls = [...methodCalls.values()]

Copilot uses AI. Check for mistakes.

@@ -846,12 +854,14 @@ export const sendAtomicTransactionComposer = async function (atcSend: AtomicTran
confirmations = await Promise.all(transactionsToSend.map(async (t) => await algod.pendingTransactionInformation(t.txID()).do()))
}

const methodCalls = [...(atc['methodCalls'] as Map<number, ABIMethod>).values()]
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Similar to the composer, relying on the internal methodCalls property of the ATC is fragile. It’s better to track calls through the public API or store them when invoking the composer.

Copilot uses AI. Check for mistakes.

@joe-p joe-p force-pushed the fix/decoded_byte_arrays branch from 992c756 to 56dc9d2 Compare May 23, 2025 19:21
@joe-p joe-p force-pushed the fix/decoded_byte_arrays branch from cdefa61 to b07f0fa Compare May 23, 2025 19:29
@lempira lempira self-requested a review May 29, 2025 20:23
@joe-p joe-p merged commit 864b4fb into main May 30, 2025
2 checks passed
@engineering-ci
Copy link
Contributor

🎉 This PR is included in version 9.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TS Client returns number[] instead of stated Uint8Array
2 participants