fix(calldata): align toString output with the reference format - #211
Open
memosr wants to merge 1 commit into
Open
fix(calldata): align toString output with the reference format#211memosr wants to merge 1 commit into
memosr wants to merge 1 commit into
Conversation
`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.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #210
What
Fixes three defects in
abi.calldata.toString()(src/abi/calldata/string.ts):Adds
tests/calldata-to-string.test.ts, mirroring the reference test suite atrunners/genlayer-py-std/tests/test_calldata_to_str.pyin the genvm repo.Why
The output did not match the reference implementation (
runners/genlayer-py-std/src/genlayer/calldata/__init__.py,to_str):new Uint8Array([0x01, 0x02])b#12b#01020x01addr#11111111111111111111{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])andUint8Array([0x12])both rendered asb#12, so distinct values collapsed to the same string. Addresses rendered shorter than 40 characters whenever a byte was below0x10.This is public API and also feeds the
readablefield ofdecodeTransaction/simplifyTransactionReceiptviacalldataToUserFriendlyJson, so the malformed output was user visible.Testing done
v1before the fix and pass after.npx vitest run --typecheckgives 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.tsis clean.Decisions made
src/abi/calldata/string.tsdoes not satisfyprettier --checkonv1today, before this change. I left the formatting untouched so the diff stays reviewable. Happy to add a separate formatting commit if you'd prefer.v1per CONTRIBUTING, since this is a bug fix. The same defects are present onv2,v2-devandmain; let me know if you want a companion PR.Checks
Reviewing tips
The diff is 15 lines in
string.ts. The comma changes follow the samefirstflag pattern the reference uses. The twopadStart(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 thereadablefield returned bydecodeTransactionandsimplifyTransactionReceipt.