Skip to content

feat: add contract tests and consolidate stream parameter structs (issues #658-661) - #711

Open
soma-enyi wants to merge 4 commits into
FlowwStar:mainfrom
soma-enyi:feat/issues-658-659-660-661
Open

feat: add contract tests and consolidate stream parameter structs (issues #658-661)#711
soma-enyi wants to merge 4 commits into
FlowwStar:mainfrom
soma-enyi:feat/issues-658-659-660-661

Conversation

@soma-enyi

Copy link
Copy Markdown

Summary

This PR addresses four GitHub issues by adding comprehensive contract tests for edge cases and consolidating duplicate type definitions in the FlowStar streaming contract.

Changes Implemented

Issue #658: Test bump_stream() on Nonexistent Stream

  • File: contracts/streaming/src/test_security.rs
  • Change: Added test_bump_stream_nonexistent_stream_returns_stream_not_found() test
  • Purpose: Validates that calling bump_stream() with a nonexistent stream ID properly returns StreamError::StreamNotFound
  • Pattern: Follows established security test patterns for negative-path validation
  • Details: Tests the scenario where a stream has either never been created or has expired from persistent storage

Issue #659: Test Batch Creation Rejects Contract as Recipient

  • File: contracts/streaming/src/test_batch.rs
  • Change: Added test_batch_rejects_contract_as_recipient() test
  • Purpose: Ensures create_streams_batch() has the same security guard as create_stream() to prevent the contract itself from being a stream recipient
  • Implementation: Creates a batch with one valid stream and one invalid entry (contract as recipient), verifies the entire batch is rejected with StreamError::InvalidRecipient
  • Atomicity: Validates that batch validation is atomic — no partial state is created on error
  • Security: Prevents accidental or malicious configuration where the contract could be recipient of a stream

Issue #660: Test Batch Creation Rejects Dust/Zero-Rate Streams

  • File: contracts/streaming/src/test_batch.rs
  • Change: Added test_batch_rejects_dust_stream() test
  • Purpose: Validates that batch creation properly rejects streams with dust amounts (where per-second rate becomes zero due to integer division)
  • Test Case: Creates a batch with both valid and dust stream entries (100 stroops over 1 year = 0 per second)
  • Expected: Batch is rejected with StreamError::RateIsZero before any funds are transferred
  • Consistency: Mirrors the existing single-stream dust validation logic adapted for batch operations

Issue #661: Consolidate CreateStreamInput and CreateStreamParams Structs

  • File: contracts/streaming/src/lib.rs
  • Changes:
    • Removed duplicate CreateStreamInput struct definition (lines 178-192)
    • Updated create_streams_batch() function signature to accept Vec<CreateStreamParams> instead of Vec<CreateStreamInput>
    • Both single-stream and batch-create operations now share the same parameter type
  • Consistency: Eliminates redundant struct definitions while maintaining identical functionality
  • API Surface: Single-stream and batch APIs are now clearly unified in terms of parameter structure
  • Future Evolution: Both APIs can now evolve in lock-step without diverging type definitions

Bonus Fix

  • File: contracts/streaming/src/test_features.rs
  • Change: Removed duplicate import of Address and Env in line 10
  • Issue: Pre-existing duplicate that was causing compilation warnings
  • Resolution: Cleaned up to follow Rust import best practices

Files Modified

  • contracts/streaming/src/test_security.rs (+14 lines)

    • Added test for bump_stream() edge case
  • contracts/streaming/src/test_batch.rs (+71 lines)

    • Added two batch validation tests
    • Updated all CreateStreamInput references to CreateStreamParams
  • contracts/streaming/src/lib.rs (-16 lines)

    • Removed duplicate CreateStreamInput struct
    • Updated function signature for create_streams_batch()
  • contracts/streaming/src/test_features.rs (-1 line)

    • Removed duplicate import statement

Test Results

All new tests pass successfully:
test_bump_stream_nonexistent_stream_returns_stream_not_found
test_batch_rejects_contract_as_recipient
test_batch_rejects_dust_stream

Validation

  • All changes compile without errors
  • Existing tests continue to pass (160 passed)
  • New security tests validate edge cases properly
  • Type consolidation maintains backward compatibility at the contract interface level

Closes #658
Closes #659
Closes #660
Closes #661

@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@soma-enyi 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment