|
| 1 | +name: Contract Invariant Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, dev, develop, 'feature/*'] |
| 6 | + paths: |
| 7 | + - 'contracts/**' |
| 8 | + pull_request: |
| 9 | + branches: [main, dev, develop, 'feature/*'] |
| 10 | + paths: |
| 11 | + - 'contracts/**' |
| 12 | + |
| 13 | +env: |
| 14 | + RUST_VERSION: '1.85' |
| 15 | + # Number of proptest cases per property. Increase for deeper fuzzing. |
| 16 | + PROPTEST_CASES: 200 |
| 17 | + |
| 18 | +jobs: |
| 19 | + # ───────────────────────────────────────────────────────────────────────── |
| 20 | + # Invariant & Property-Based Tests |
| 21 | + # ───────────────────────────────────────────────────────────────────────── |
| 22 | + contract-invariants: |
| 23 | + name: Subscription Contract Invariant Tests |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Install Rust toolchain |
| 31 | + uses: dtolnay/rust-toolchain@master |
| 32 | + with: |
| 33 | + toolchain: ${{ env.RUST_VERSION }} |
| 34 | + |
| 35 | + - name: Cache Rust dependencies |
| 36 | + uses: Swatinem/rust-cache@v2 |
| 37 | + with: |
| 38 | + workspaces: './contracts -> target' |
| 39 | + |
| 40 | + # ── Run the full invariant test suite ────────────────────────────── |
| 41 | + - name: Run invariant tests (deterministic scenarios) |
| 42 | + working-directory: ./contracts |
| 43 | + env: |
| 44 | + PROPTEST_CASES: ${{ env.PROPTEST_CASES }} |
| 45 | + run: | |
| 46 | + cargo test --test invariants -- --nocapture 2>&1 | tee invariant-test-results.txt |
| 47 | +
|
| 48 | + # ── Run all contract tests to ensure nothing regressed ───────────── |
| 49 | + - name: Run full contract test suite |
| 50 | + working-directory: ./contracts |
| 51 | + run: cargo test --verbose |
| 52 | + |
| 53 | + # ── Upload test results as artifact ─────────────────────────────── |
| 54 | + - name: Upload invariant test results |
| 55 | + if: always() |
| 56 | + uses: actions/upload-artifact@v4 |
| 57 | + with: |
| 58 | + name: invariant-test-results |
| 59 | + path: contracts/invariant-test-results.txt |
| 60 | + retention-days: 30 |
| 61 | + |
| 62 | + # ───────────────────────────────────────────────────────────────────────── |
| 63 | + # Extended Fuzz Run (only on pushes to main/dev — not every PR) |
| 64 | + # ───────────────────────────────────────────────────────────────────────── |
| 65 | + contract-invariants-extended: |
| 66 | + name: Extended Invariant Fuzz (1000 cases) |
| 67 | + runs-on: ubuntu-latest |
| 68 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: Checkout code |
| 72 | + uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: Install Rust toolchain |
| 75 | + uses: dtolnay/rust-toolchain@master |
| 76 | + with: |
| 77 | + toolchain: ${{ env.RUST_VERSION }} |
| 78 | + |
| 79 | + - name: Cache Rust dependencies |
| 80 | + uses: Swatinem/rust-cache@v2 |
| 81 | + with: |
| 82 | + workspaces: './contracts -> target' |
| 83 | + |
| 84 | + - name: Run extended invariant fuzz (1000 cases) |
| 85 | + working-directory: ./contracts |
| 86 | + env: |
| 87 | + PROPTEST_CASES: 1000 |
| 88 | + run: | |
| 89 | + cargo test --test invariants -- --nocapture 2>&1 | tee extended-fuzz-results.txt |
| 90 | +
|
| 91 | + - name: Upload extended fuzz results |
| 92 | + if: always() |
| 93 | + uses: actions/upload-artifact@v4 |
| 94 | + with: |
| 95 | + name: extended-fuzz-results |
| 96 | + path: contracts/extended-fuzz-results.txt |
| 97 | + retention-days: 30 |
0 commit comments