fix(sorobanUtils): decode Bytes struct fields so struct args build - #2193
Open
yigitcangokmen wants to merge 1 commit into
Open
fix(sorobanUtils): decode Bytes struct fields so struct args build#2193yigitcangokmen wants to merge 1 commit into
yigitcangokmen wants to merge 1 commit into
Conversation
convertPrimitiveField special-cased only bool, so a bytes field in a struct argument was passed to nativeToScVal as a raw string with type bytes and rejected with "invalid type (bytes) specified for string value". Top-level bytes and bytes inside vecs/tuples already decode the string to a Uint8Array first; only the struct-field path was missed. Add a bytes case mirroring getScValFromPrimitive (reusing detectBytesEncoding). Covers BytesN struct fields too, and adds a getScValsFromArgs test for a struct with a bytes field.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes struct arguments containing Bytes/BytesN fields by decoding byte strings before Soroban XDR conversion.
Changes:
- Adds byte-encoding detection and
Uint8Arrayconversion for struct fields. - Adds a regression test for hexadecimal bytes within a struct.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/helpers/sorobanUtils.ts |
Converts struct byte fields before nativeToScVal. |
tests/unit/getScValsFromArgs.test.ts |
Tests struct-to-scvMap byte encoding. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Resolves #2192
Problem
Invoking a contract function, or deploying a contract, with a struct argument that contains a
Bytesfield fails to build in the Lab with:convertPrimitiveField(the struct-encoding path insrc/helpers/sorobanUtils.ts) special-cases onlybool; abytesfield is passed through as a raw string with typeHintbytes, andnativeToScVal(string, { type: "bytes" })rejects it. Top-levelbytesargs, andbytesinside vecs/tuples, all work because those paths decode the string to aUint8Arrayfirst (viagetScValFromPrimitiveanddetectBytesEncoding); only the struct-field path was missed. This has been the case sinceconvertPrimitiveFieldwas introduced.The operation is hard-blocked with no UI workaround: the value passes
DataUrlvalidation, thengetTxnToSimulatecatches the error and surfaces it as an error string. Reachable from the Contract Explorer invoke form, the JSON-schema invoke path, and the deploy-contract constructor args.Fix
Add a
bytescase inconvertPrimitiveFieldthat decodes with the existingdetectBytesEncodinghelper, mirroring exactly whatgetScValFromPrimitiveand the vec/tuple paths already do. This also covers fixed-lengthBytesN<N>struct fields, since the form maps bothBytesandBytesNtotype: "bytes".Tests
Adds a
getScValsFromArgscase: a struct with abytesfield (hex) encodes to the expectedscvMapcontainingscvBytes. It fails onmain(theinvalid type ("bytes")throw) and passes with this change; the existinggetScValsFromArgssuite and the full unit suite stay green.