Handle scSpecTypeVal in Spec.nativeToScVal for raw JS types #1485
Handle scSpecTypeVal in Spec.nativeToScVal for raw JS types #1485Shadow-MMN wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for converting JS “val”-typed inputs (scSpecTypeVal) into appropriate ScVal variants, with tests and updated reference docs.
Changes:
- Implement
scSpecTypeValhandling inSpec.nativeToScVal(string/address, i128, bool). - Add unit tests covering
nativeToScValandfuncArgsToScValswith val-typed inputs. - Replace
@ts-ignorewith@ts-expect-errorand update docs source links.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/unit/spec/contract_spec.test.ts | Adds tests for scSpecTypeVal conversions and tightens TS suppression directives. |
| src/contract/spec.ts | Implements conversion logic for scSpecTypeVal in nativeToScVal. |
| docs/reference/contracts-client.md | Updates generated “Source” links to match new line numbers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: deb6c38476
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5217f20576
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8de3fc3edb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7f3e9fda73
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e33b4475c0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1120c1a8da
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c0e714406
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
9c0e714 to
599d394
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 599d3947e4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 599d3947e4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
What
Spec.prototype.nativeToScValcurrently throws when the target Soroban type isscSpecTypeVal(value 0) and the input is a raw JavaScript primitive (string, number, or boolean). This makes it impossible to pass contract function arguments typed asValwithout manually constructingxdr.ScValobjects.This PR adds handling for
scSpecTypeValby converting JS primitives to their correspondingxdr.ScValtypes:Conversion table (scSpecTypeVal → ScVal)
stringscvAddress(try/catch fallback toscvString)number/bigintScInt(u64 → u128 → u256 → i64 → i128 → i256)booleanscvBoolundefined/nullscvVoidarrayscvVecMapscvMap(sorted){}scvMapwith string keys (sorted)Address/ContractscvAddressUint8Array/BufferscvBytesxdr.ScValTypeError(prevents private field leaks)Why
When a smart contract defines a function parameter as
Val(i.e.,scSpecTypeVal), the type is unconstrained — it accepts any ScVal. The SDK should be able to convert native JS values to the appropriate ScVal without the user having to manually construct XDR objects.This was originally discovered and monkey-patched in the tansu project (see Consulting-Manao/tansu#174) and @chadoh requested the fix be pushed upstream. (Closes #1480)
Testing
Added 9 unit tests covering string, Stellar address, contract ID, number, bigint, boolean, and
funcArgsToScValsintegration. All 2,058 existing tests continue to pass.Files changed
src/contract/spec.ts— AddedscSpecTypeValhandler innativeToScVal()with all conversions above; plain-object guard usesObject.prototype.toString.call+ prototype check to exclude class instancestest/unit/spec/contract_spec.test.ts— Added tests for all conversion pathsSited from Consulting-Manao/tansu#174
Closes #1480