Skip to content

fix(spec-tools): full support for ScType::Val in argument parsing and output formatting (#2438) - #2867

Closed
jdjioe5-cpu wants to merge 1 commit into
stellar:mainfrom
jdjioe5-cpu:fix/issue-2438-val-spec-type-support
Closed

jdjioe5-cpu wants to merge 1 commit into
stellar:mainfrom
jdjioe5-cpu:fix/issue-2438-val-spec-type-support

Conversation

@jdjioe5-cpu

Copy link
Copy Markdown

Summary

Fixes #2438
Also addresses #691

When a Soroban contract function declares return or input parameters typed as generic Val (represented as SC_SPEC_TYPE_VAL / ScType::Val in contract specs), calling the function or passing parameters via stellar contract invoke caused panics or parsing failures:

  1. Output formatting: Returning Bool(false) or other primitives previously panicked with not yet implemented: Bool(false,) doesn't have a matching Val or InvalidPair(..., Val) when falling through spec object dispatch.
  2. Argument parsing: from_json fell back directly to serde_json::from_value which fails on primitive JSON values like booleans, integers, or bare strings for ScType::Val.

Changes

  • cmd/crates/soroban-spec-tools/src/lib.rs:
    • Implemented val_from_json to recursively infer and convert any JSON value (null/void, bool, numbers, addresses, strings, arrays, objects) to its corresponding ScVal representation, while maintaining backwards compatibility with serialized ScVal formats.
    • Added (ScType::Val, _) => val_from_json(v)? in Spec::from_json.
    • Added fallback string parsing for ScType::Val in Spec::from_string.
    • Added (val, ScType::Val) => to_json(val)? safeguard in Spec::sc_object_to_json.
    • Provided descriptive placeholders in arg_value_name (Some("val")) and example (Some("\"any_value\"")).
    • Added regression unit tests for ScVal::Bool(false)/true, all scalar variants, bare strings, numbers, and collections with ScType::Val.
  • cmd/soroban-cli/src/commands/contract/arg_parsing.rs:
    • Registered ScSpecTypeDef::Val in is_primitive_type to allow natural command-line inputs.
    • Added context suggestions for ScSpecTypeDef::Val.
    • Added unit test test_val_arg_parsing verifying argument parsing for booleans, integers, and strings.

Evidence

  • cargo fmt --check --all: Passed (0 errors).
  • cargo test -p soroban-spec-tools: 113/113 passed.
  • cargo test -p soroban-cli --lib commands::contract::arg_parsing: 31/31 passed.

@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Oct 23, 2026
@github-project-automation github-project-automation Bot moved this from Backlog (Not Ready) to Done in DevX Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

stellar contract invoke panics when contract function returns spec type SC_SPEC_TYPE_VAL

2 participants