Skip to content

fix: stream validation and test coverage#392

Merged
ogazboiz merged 2 commits into
LabsCrypt:mainfrom
overprodigy:fix/stream-validations-364-365-366-367
Apr 28, 2026
Merged

fix: stream validation and test coverage#392
ogazboiz merged 2 commits into
LabsCrypt:mainfrom
overprodigy:fix/stream-validations-364-365-366-367

Conversation

@overprodigy
Copy link
Copy Markdown
Contributor

Summary

This PR addresses 4 stream-related issues: event filtering, test coverage, and financial invariants.

Changes

#364 - Stream Events Endpoint

  • Add FEE_COLLECTED to valid event types in stream events filter
  • Endpoint already has pagination (limit/offset), total count, and hasMore flag
  • Endpoint supports eventType filtering with all 8 event types

#365 - Pause/Resume Edge Cases

  • Add 5 new test cases covering pause/resume scenarios:
    • Cancel while paused keeps stream inactive
    • Top-up while paused increases deposited amount
    • Withdraw after long runtime is bounded
    • Withdraw then resume preserves state
    • Multiple pause/resume cycles maintain active state

#366 - Overflow Protection

  • Overflow protection already implemented in contract (checked_mul with saturation)
  • Backend service uses saturatingMulI128 to clamp values at i128 limits
  • Both implementations cap claimable at remaining balance on overflow

#367 - Fuzz Tests

  • Add 5 property-based fuzz tests covering financial invariants:
    • Withdrawn amount never exceeds deposited amount
    • Claimable amount never exceeds remaining balance
    • Cancel early refunds correctly
    • Pause/resume cycles maintain active state
    • Large amounts don't overflow claimable calculation

Testing

  • All 78 contract tests pass
  • New tests validate edge cases and invariants
  • Tests use deterministic pseudorandom seed for reproducibility

Closes #364
Closes #365
Closes #366
Closes #367

Include FEE_COLLECTED in the list of valid event types for the
stream events endpoint pagination and filtering feature.

Refs LabsCrypt#364
Add 5 new test cases covering pause/resume edge cases:
- Cancel while paused keeps stream inactive
- Top-up while paused increases deposited amount
- Withdraw after long stream runtime is bounded
- Withdraw then resume stream state preservation
- Multiple pause/resume cycles preserve stream active state

Add fuzz tests covering financial invariants:
- Withdrawn amount never exceeds deposited
- Claimable amount never exceeds remaining balance
- Cancel early refunds correctly
- Pause/resume cycles maintain active state
- Large amounts don't overflow claimable calculation

All tests pass with 78/78 passing.

Refs LabsCrypt#365
Refs LabsCrypt#367
@ogazboiz ogazboiz merged commit 1655284 into LabsCrypt:main Apr 28, 2026
6 of 9 checks 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

2 participants