feat(contracts): add property-based tests with proptest (closes #692) - #896
feat(contracts): add property-based tests with proptest (closes #692)#896Mikolo37 wants to merge 1 commit into
Conversation
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>
|
@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. |
|
@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! 🚀 |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 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. Comment |
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.vested_amount_always_in_bounds0 <= vested_amount(stream, t) <= total_amountfor everytclaimable_never_exceeds_vested_minus_claimedclaimable(stream, t) == max(0, vested − claimed); in particularclaimable <= vested − claimedwhenevervested >= claimedstatus_is_always_one_of_fourActive/Paused/Completed/Canceledand consistent with stored statecancel_always_produces_canceled_statuscancel,stream.canceled == trueand status ==CanceledRandom 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
The tests live in
contracts/src/tests/property_tests.rs(new) and are gated behind a newproptestfeature so normalcargo testruns are unaffected. The properties and the on-chain status model are documented indocs/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
maindue to a series of bad merges. These are required for "all tests pass":contracts/src/lib.rs:use soroban_sdk::{…}imports (E0252).EscrowVestingContractinto the test module — itsclaimentry point collided withStellarStreamContract::claim(E0428). It is test-only code and not part of the deployed ABI.mod errors;(E0432).testutils+proptestfeatures (fixesunexpected cfgwarnings under-D warnings).#[allow(clippy::too_many_arguments)]to the ABI-fixedcreate_stream/create_split_streamsignatures.contracts/src/test.rs:#593allowlist tests and the#594lifecycle tests from the pre-merge branches.mock_all_auths,register_stellar_asset_contract_v2) and to the structured event schema (actor/timestamp/claimed_amount/refunded_amount).test_create_stream_rejected_after_token_removed_from_allowlist(it could never panic with a single-token allowlist under the lenient test-mode check).rustfmt-clean with the pinnednightly-2024-12-01toolchain.Verification
All checks pass on the pinned toolchain (
nightly-2024-12-01):cargo test— 114 passed, 0 failedcargo test --features proptest— 118 passed, 0 failed (4 property tests × 10,000 cases, no violations)cargo clippy --all-targets --all-features -- -D warnings— cleancargo fmt --all -- --check— cleancargo build --target wasm32-unknown-unknown --release— succeedsRUSTFLAGS="-D warnings" cargo test --locked— cleanCloses #692