Skip to content

fix(calldata): align toString output with the reference format - #211

Open
memosr wants to merge 1 commit into
genlayerlabs:v1from
memosr:fix/calldata-to-string-format
Open

fix(calldata): align toString output with the reference format#211
memosr wants to merge 1 commit into
genlayerlabs:v1from
memosr:fix/calldata-to-string-format

Conversation

@memosr

@memosr memosr commented Aug 22, 2026

Copy link
Copy Markdown

Fixes #210

What

Fixes three defects in abi.calldata.toString() (src/abi/calldata/string.ts):

  • Bytes and addresses are now zero padded to two hex digits per byte
  • Map entries are now separated by commas
  • Arrays no longer emit a trailing comma

Adds tests/calldata-to-string.test.ts, mirroring the reference test suite at runners/genlayer-py-std/tests/test_calldata_to_str.py in the genvm repo.

Why

The output did not match the reference implementation (runners/genlayer-py-std/src/genlayer/calldata/__init__.py, to_str):

Input before reference
new Uint8Array([0x01, 0x02]) b#12 b#0102
20-byte address of 0x01 addr#11111111111111111111 40 hex chars
{x: true, y: null} {"x":true"y":null} {"x":true,"y":null}
[1, 2, 3] [1,2,3,] [1,2,3]

The missing hex padding is lossy rather than cosmetic: Uint8Array([0x01, 0x02]) and Uint8Array([0x12]) both rendered as b#12, so distinct values collapsed to the same string. Addresses rendered shorter than 40 characters whenever a byte was below 0x10.

This is public API and also feeds the readable field of decodeTransaction / simplifyTransactionReceipt via calldataToUserFriendlyJson, so the malformed output was user visible.

Testing done

  • Added 6 tests covering bytes, addresses, maps, arrays, nesting, and the byte-array collision case. All fail on v1 before the fix and pass after.
  • Full suite: npx vitest run --typecheck gives 82 passed, no type errors. Baseline before the change was 76 passed, so no regressions.
  • npx eslint src/abi/calldata/string.ts tests/calldata-to-string.test.ts is clean.

Decisions made

  • Expected values were taken from the genvm reference rather than invented, so the SDK matches genlayer-py output.
  • src/abi/calldata/string.ts does not satisfy prettier --check on v1 today, before this change. I left the formatting untouched so the diff stays reviewable. Happy to add a separate formatting commit if you'd prefer.
  • Targeting v1 per CONTRIBUTING, since this is a bug fix. The same defects are present on v2, v2-dev and main; let me know if you want a companion PR.

Checks

  • I have tested this code
  • I have reviewed my own PR
  • I have created an issue for this PR
  • I have set a descriptive PR title compliant with conventional commits

Reviewing tips

The diff is 15 lines in string.ts. The comma changes follow the same first flag pattern the reference uses. The two padStart(2, "0") calls are the lossy part worth checking first.

User facing release notes

abi.calldata.toString() now produces output matching the GenVM reference format. Byte and address values are zero padded, map entries are comma separated, and arrays no longer include a trailing comma. This also affects the readable field returned by decodeTransaction and simplifyTransactionReceipt.

`abi.calldata.toString` produced output that does not match the reference
implementation in genvm (runners/genlayer-py-std, calldata/__init__.py::to_str).
Three defects:

- Bytes and addresses were serialised with `toString(16)` and no zero padding,
  so `0x0a` became `a`. This is lossy: `Uint8Array([0x01, 0x02])` and
  `Uint8Array([0x12])` both rendered as `b#12`, and a 20-byte address could
  render as fewer than 40 hex characters.
- Map entries had no separator at all, producing `{"a":1"b":2}`.
- Arrays emitted a trailing comma, producing `[1,2,3,]`.

The function is public API and also feeds the `readable` field of
`decodeTransaction` / `simplifyTransactionReceipt` via
`calldataToUserFriendlyJson`, so the malformed output is user visible.

Adds tests mirroring the reference test suite
(runners/genlayer-py-std/tests/test_calldata_to_str.py).

Note: `string.ts` does not satisfy prettier on `v1` either; left untouched to
keep the diff reviewable.
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 271a33b4-71df-417e-b0c7-357ddfad03ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant