Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/invariant-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Contract Invariant Tests

on:
push:
branches: [main, dev, develop, 'feature/*']
paths:
- 'contracts/**'
pull_request:
branches: [main, dev, develop, 'feature/*']
paths:
- 'contracts/**'

env:
RUST_VERSION: '1.85'
# Number of proptest cases per property. Increase for deeper fuzzing.
PROPTEST_CASES: 200

jobs:
# ─────────────────────────────────────────────────────────────────────────
# Invariant & Property-Based Tests
# ─────────────────────────────────────────────────────────────────────────
contract-invariants:
name: Subscription Contract Invariant Tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: './contracts -> target'

# ── Run the full invariant test suite ──────────────────────────────
- name: Run invariant tests (deterministic scenarios)
working-directory: ./contracts
env:
PROPTEST_CASES: ${{ env.PROPTEST_CASES }}
run: |
cargo test --test invariants -- --nocapture 2>&1 | tee invariant-test-results.txt

# ── Run all contract tests to ensure nothing regressed ─────────────
- name: Run full contract test suite
working-directory: ./contracts
run: cargo test --verbose

# ── Upload test results as artifact ───────────────────────────────
- name: Upload invariant test results
if: always()
uses: actions/upload-artifact@v4
with:
name: invariant-test-results
path: contracts/invariant-test-results.txt
retention-days: 30

# ─────────────────────────────────────────────────────────────────────────
# Extended Fuzz Run (only on pushes to main/dev — not every PR)
# ─────────────────────────────────────────────────────────────────────────
contract-invariants-extended:
name: Extended Invariant Fuzz (1000 cases)
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev')

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: './contracts -> target'

- name: Run extended invariant fuzz (1000 cases)
working-directory: ./contracts
env:
PROPTEST_CASES: 1000
run: |
cargo test --test invariants -- --nocapture 2>&1 | tee extended-fuzz-results.txt

- name: Upload extended fuzz results
if: always()
uses: actions/upload-artifact@v4
with:
name: extended-fuzz-results
path: contracts/extended-fuzz-results.txt
retention-days: 30
6 changes: 6 additions & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
target/
Cargo.lock

# Soroban test snapshots (generated at runtime, not source)
test_snapshots/

# Proptest regression files (generated at runtime)
**/*.proptest-regressions
Loading
Loading