Skip to content

test(streams): add contract schema validation and flags u32 round-trip for parseStreamInfo (closes #595) - #698

Open
martinss16kf wants to merge 1 commit into
conduit-protocol:mainfrom
martinss16kf:test/parse-stream-info-contract-schema-595
Open

martinss16kf wants to merge 1 commit into
conduit-protocol:mainfrom
martinss16kf:test/parse-stream-info-contract-schema-595

Conversation

@martinss16kf

@martinss16kf martinss16kf commented Sep 9, 2026

Copy link
Copy Markdown

Summary

Closes #595

Adds explicit schema tests against the on-chain Soroban contract's actual StreamInfo structure (contracts/stream/src/storage.rs) to prevent model drift in parseStreamInfo. Specifically tests that flags are decoded strictly from the flags: u32 bitmask and that standalone boolean fields are ignored.

Key Changes

  • src/streams.ts:
    • Exported parseStreamInfo to enable direct unit testing and contract schema verification.
    • Hardened key extraction in parseStreamInfo to reliably handle both scvSymbol and scvString ScVal key types.
  • src/tests/parse-stream-info.test.ts:
    • Added comprehensive test suite: parseStreamInfo — contract schema validation and flags: u32 round-trip (#595).
    • Added helper buildContractStreamInfoScVal reflecting exact Soroban contract storage layout.
    • Tests canonical StreamInfo ScVal map round-trip.
    • Tests model drift prevention (ensures standalone bool fields are ignored in favor of flags: u32).
    • Tests all permutations of flags: u32 bitmask flags (FLAG_PAUSED, FLAG_CANCELLED, FLAG_CLAWBACK_ENABLED) and higher bits.
    • Verifies 128-bit integer precision preservation for rate_per_second and withdrawn.
    • Verifies parity between symbol and string ScVal keys.
    • Verifies clean serialization via .toJSON().
    • Tests end-to-end contract round-trip via StreamsModule.get().

Verification

  • npx vitest run src/tests/parse-stream-info.test.ts -> 13/13 passed (100%).
  • npx vitest run -> 81/81 files passed (1028 passed, 0 failures).
  • npx tsc --noEmit -> Clean (0 errors).

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.

parseStreamInfo model drift: no schema test against the contract

2 participants