Skip to content

feat(contracts): add property-based tests with proptest (closes #692) - #896

Open
Mikolo37 wants to merge 1 commit into
ritik4ever:mainfrom
Mikolo37:add-contract
Open

feat(contracts): add property-based tests with proptest (closes #692)#896
Mikolo37 wants to merge 1 commit into
ritik4ever:mainfrom
Mikolo37:add-contract

Conversation

@Mikolo37

Copy link
Copy Markdown

Summary

Implements #692 — property-based tests for the StellarStream Soroban contract using proptest. Four invariants are checked against 10,000 randomly generated stream configurations each, with zero violations.

Property Invariant
vested_amount_always_in_bounds 0 <= vested_amount(stream, t) <= total_amount for every t
claimable_never_exceeds_vested_minus_claimed claimable(stream, t) == max(0, vested − claimed); in particular claimable <= vested − claimed whenever vested >= claimed
status_is_always_one_of_four derived status is always one of Active / Paused / Completed / Canceled and consistent with stored state
cancel_always_produces_canceled_status after cancel, stream.canceled == true and status == Canceled

Random inputs cover amounts up to 10¹⁸, timestamps up to 2×10⁶, non-zero cliffs, pre-start / mid-stream / post-end times, paused streams, and canceled streams (bounded so the vesting arithmetic cannot overflow i128).

How to run

cd contracts
cargo test --features proptest

The tests live in contracts/src/tests/property_tests.rs (new) and are gated behind a new proptest feature so normal cargo test runs are unaffected. The properties and the on-chain status model are documented in docs/CONTRACT_ABI.md.

Build repairs included (the contract crate did not compile on main)

While getting the property tests running I had to repair the contract crate, which was unbuildable on main due to a series of bad merges. These are required for "all tests pass":

  • contracts/src/lib.rs:
    • Removed duplicate use soroban_sdk::{…} imports (E0252).
    • Moved the legacy EscrowVestingContract into the test module — its claim entry point collided with StellarStreamContract::claim (E0428). It is test-only code and not part of the deployed ABI.
    • Declared the missing mod errors; (E0432).
    • Declared testutils + proptest features (fixes unexpected cfg warnings under -D warnings).
    • Added #[allow(clippy::too_many_arguments)] to the ABI-fixed create_stream/create_split_stream signatures.
  • contracts/src/test.rs:
    • Reconstructed the test section that was scrambled by the multi-token-allowlist merge — ~30 test bodies were shifted onto the wrong function headers and the file had an unclosed delimiter. Restored the correct bodies for the #593 allowlist tests and the #594 lifecycle tests from the pre-merge branches.
    • Updated tests to the SDK 21 API (mock_all_auths, register_stellar_asset_contract_v2) and to the structured event schema (actor/timestamp/claimed_amount/refunded_amount).
    • Fixed test_create_stream_rejected_after_token_removed_from_allowlist (it could never panic with a single-token allowlist under the lenient test-mode check).
  • Snapshots updated for the new event fields; the crate is now rustfmt-clean with the pinned nightly-2024-12-01 toolchain.

Verification

All checks pass on the pinned toolchain (nightly-2024-12-01):

  • cargo test114 passed, 0 failed
  • cargo test --features proptest118 passed, 0 failed (4 property tests × 10,000 cases, no violations)
  • cargo clippy --all-targets --all-features -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • cargo build --target wasm32-unknown-unknown --release — succeeds
  • RUSTFLAGS="-D warnings" cargo test --locked — clean

Closes #692

Closes ritik4ever#692. Adds 4 property-based tests (10,000 random inputs each) behind
a new `proptest` feature, run with `cargo test --features proptest`:

- vested_amount is always in [0, total_amount]
- claimable never exceeds vested - claimed (== max(0, vested - claimed))
- stream status is always one of the 4 documented values
- cancel always produces status = canceled

The properties and the on-chain status model are documented in
docs/CONTRACT_ABI.md.

Also repairs the contract crate, which did not compile on main after bad
merges: removes duplicate imports, moves the legacy EscrowVestingContract
into the test module (its `claim` collided with StellarStreamContract's),
restores the test bodies that were shifted during the multi-token allowlist
merge, updates event-struct constructions/snapshots for the actor+timestamp
schema, and fixes the rustfmt/clippy issues CI enforces.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@Mikolo37 is attempting to deploy a commit to the ritik4ever's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@Mikolo37 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 Aug 28, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a07a754-189d-4517-be34-8379db303888


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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.

[FEATURE] Add contract property-based tests with proptest

1 participant