Skip to content

WASM parsing with complex nested structs - #387

Merged
codeZe-us merged 5 commits into
Toolbox-Lab:mainfrom
quickweb-stack:unit-test
Jul 29, 2026
Merged

WASM parsing with complex nested structs#387
codeZe-us merged 5 commits into
Toolbox-Lab:mainfrom
quickweb-stack:unit-test

Conversation

@quickweb-stack

@quickweb-stack quickweb-stack commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Close: #374

Here's a summary of what was done:
Changes Made
New files

  • crates/core/src/spec/tests/mod.rs — Test module declaration
  • crates/core/src/spec/tests/wasm_tests.rs — 5 unit tests for nested struct WASM parsing
    Modified files
  • crates/core/src/spec/mod.rs — Added #[cfg(test)] mod tests;
  • crates/core/src/spec/decoder.rs — Removed unreachable StructV0 union case arm (doesn't exist in stellar-xdr 21.2.0) and fixed missing enums/unions fields in existing test
  • crates/core/src/decode/mod.rs — Removed pub mod context; (contained TypeScript code)
  • crates/core/src/decode/function_call_decoder.rs — Added missing imports and FunctionCallDecoder stub
  • crates/core/src/decode/return_decoder.rs — Fixed from_sc_address → addr.to_string(), fixed ScString/ScSymbol type construction in tests, cleaned unused imports
    Tests added
  1. test_deeply_nested_structs_extracted_correctly — Validates 3-level nesting (Inner → Middle → Outer) with field types and doc strings
  2. test_nested_struct_type_defs_preserved — Verifies type_def fields contain correct ScSpecTypeDef::Udt variants
  3. test_vec_of_nested_struct_type_def — Validates Vec type references are parsed correctly
  4. test_three_deep_nesting_chain — Validates the full nesting chain Outer → Middle → Inner
  5. test_struct_with_no_nesting — Baseline test for a simple struct
    All 9 spec tests pass (5 new + 4 existing).

Summary by CodeRabbit

  • New Features

    • Added support for decoding function calls and their arguments into structured results.
    • Improved contract specification decoding for nested structs, vectors, enums, and unions.
    • Preserved nested type names, documentation, and field definitions when reading WASM contract specifications.
  • Bug Fixes

    • Improved address and return-value decoding for more consistent output.
    • Corrected handling of structured union cases and contract specification fields.
  • Tests

    • Added coverage for nested contract definitions and WASM-embedded specifications.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@quickweb-stack Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Decoder and contract-spec updates

Layer / File(s) Summary
Decode API and return handling
crates/core/src/decode/function_call_decoder.rs, crates/core/src/decode/mod.rs, crates/core/src/decode/return_decoder.rs
Adds JSON-backed function-call types and a constructor, removes the public decode context module, and updates address and test value conversions.
Contract-spec decoding behavior
crates/core/src/spec/decoder.rs
Narrows union-case decoding to void and tuple variants while preserving struct decoding and updating a test fixture.
Nested WASM specification tests
crates/core/src/spec/mod.rs, crates/core/src/spec/tests/*
Adds WASM payload construction and tests for nested structs, vectorized nested types, type definitions, documentation, and non-nested structs.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant wasm_tests
  participant decode_contract_spec
  participant ContractSpec
  wasm_tests->>decode_contract_spec: provide synthesized contractspecv0 WASM payload
  decode_contract_spec->>ContractSpec: decode nested ScSpecEntry definitions
  ContractSpec-->>wasm_tests: return decoded structs and type definitions
Loading

Possibly related PRs

Suggested reviewers: emrys02

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Several unrelated decoder and module cleanup changes were included outside the nested WASM parsing scope, including a new FunctionCallDecoder stub and return decoding edits. Move unrelated decoder and module cleanup into a separate PR, and keep this one limited to the WASM nested-struct parsing tests and supporting decoder fixes.
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: adding coverage for parsing complex nested structs in WASM.
Linked Issues check ✅ Passed The added WASM tests cover deeply nested structs and arrays and verify decoded XDR structure, matching #374.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@quickweb-stack

Copy link
Copy Markdown
Contributor Author

Done, Close: #387

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/core/src/spec/decoder.rs (1)

538-546: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Duplicate enums/unions fields in struct literal — will not compile.

enums: Vec::new() and unions: Vec::new() are already set at Lines 540-541; the newly added Lines 544-545 set them again in the same ContractSpec { ... } literal. Rust rejects duplicate field initializers in a struct literal (E0062), so this fixture will fail to compile, contradicting the PR's claim that all spec tests pass.

🐛 Proposed fix
             functions: Vec::new(),
             structs: Vec::new(),
             enums: Vec::new(),
             unions: Vec::new(),
             name: None,
             version: None,
-            enums: Vec::new(),
-            unions: Vec::new(),
         };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/core/src/spec/decoder.rs` around lines 538 - 546, Remove the duplicate
enums and unions initializers from the ContractSpec struct literal in the
fixture, leaving each field initialized exactly once alongside functions and
structs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@crates/core/src/spec/decoder.rs`:
- Around line 538-546: Remove the duplicate enums and unions initializers from
the ContractSpec struct literal in the fixture, leaving each field initialized
exactly once alongside functions and structs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 05f7c464-a370-4171-a9f9-409324cfd15a

📥 Commits

Reviewing files that changed from the base of the PR and between c354c19 and 4660d67.

📒 Files selected for processing (7)
  • crates/core/src/decode/function_call_decoder.rs
  • crates/core/src/decode/mod.rs
  • crates/core/src/decode/return_decoder.rs
  • crates/core/src/spec/decoder.rs
  • crates/core/src/spec/mod.rs
  • crates/core/src/spec/tests/mod.rs
  • crates/core/src/spec/tests/wasm_tests.rs
💤 Files with no reviewable changes (1)
  • crates/core/src/decode/mod.rs

@codeZe-us
codeZe-us self-requested a review July 29, 2026 17:02
@codeZe-us
codeZe-us merged commit 130c7de into Toolbox-Lab:main Jul 29, 2026
1 check passed
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.

Unit test: WASM parsing with complex nested structs

3 participants