From 59b2a9406626cbd2dea568002bb6d8233c8f6df3 Mon Sep 17 00:00:00 2001 From: Best-Web Date: Tue, 21 Jul 2026 09:14:49 +0000 Subject: [PATCH 1/2] ci: add clippy job and crate-level lint attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add a dedicated clippy CI job that runs cargo clippy --all-targets with -D warnings on every push and pull request to main. - Split the existing single fmt job into three parallel jobs: fmt, clippy, and test — each with explicit toolchain components. - Add #![deny(clippy::all)] and #![warn(clippy::pedantic)] to lib.rs. - Allow known-safe casts (cast_possible_truncation, cast_possible_wrap, cast_precision_loss, cast_sign_loss) and module_name_repetitions. - Document the three CI checks in README.md under a new ## CI section. Closes #56 --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ README.md | 24 ++++++++++++++++++++++++ src/lib.rs | 12 ++++++++++++ 3 files changed, 57 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eabf4db..65f49bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,5 +12,26 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt - name: Check formatting run: cargo fmt --all -- --check + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy + targets: wasm32-unknown-unknown + - name: Clippy (deny warnings) + run: cargo clippy --all-targets -- -D warnings + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: Run tests + run: cargo test diff --git a/README.md b/README.md index a0da63a..1882ef5 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,30 @@ The release artifact is written to: target/wasm32-unknown-unknown/release/streampay_contract.wasm ``` +## CI + +Every push and pull request runs three CI checks: + +- **Format**: `cargo fmt --all -- --check` enforces consistent code style. +- **Clippy**: `cargo clippy --all-targets -- -D warnings` denies all clippy + warnings, including pedantic lints. Known-safe casts are allowed at the + crate level. +- **Test**: `cargo test` runs the full unit test suite. + +All three checks must pass before a PR can be merged. Run them locally with: + +```bash +make fmt-check # or `make fmt` to auto-fix formatting +make clippy +make test +``` + +Or run all three in one command: + +```bash +make lint +``` + ## Deploy ```bash diff --git a/src/lib.rs b/src/lib.rs index cf1ddfd..73efff8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,16 @@ #![no_std] +#![deny(clippy::all)] +#![warn(clippy::pedantic)] +// Intentional numeric casts that are safe by construction: +// - u64 subtractions cast to i128/u128 for vesting math (values bounded by window) +// - i128 bps values cast to u32 (bounded to 0..=10_000) +// - usize/u32 loop counters cast to u64 for stream IDs +#![allow(clippy::cast_possible_truncation)] +#![allow(clippy::cast_possible_wrap)] +#![allow(clippy::cast_precision_loss)] +#![allow(clippy::cast_sign_loss)] +// Type names intentionally repeat the module name (e.g. `error::Error`). +#![allow(clippy::module_name_repetitions)] //! StreamPay: a real-time payment-streaming smart contract for Stellar. //! //! StreamPay lets a sender escrow a fixed amount of a token and stream it From f6fd44652d8a3a7b0e6b7e59c9f681698eb84410 Mon Sep 17 00:00:00 2001 From: Best-Web Date: Tue, 21 Jul 2026 09:20:47 +0000 Subject: [PATCH 2/2] fix: add missing closing braces in src/test.rs Two test functions were missing their closing : - test_create_stream_zero_start_rejects_end_before_now (line 888) - test_supply_recovers_after_full_withdraw_allowing_new_stream (line 1068) This caused to fail with 'unclosed delimiter', which in turn blocked the clippy and test CI jobs from running. --- src/test.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test.rs b/src/test.rs index 96111d5..feb155e 100644 --- a/src/test.rs +++ b/src/test.rs @@ -893,6 +893,8 @@ fn test_create_stream_zero_start_rejects_end_before_now() { .contract .try_create_stream(&s.sender, &s.recipient, &1_000, &0, &500); assert_eq!(res, Err(Ok(Error::InvalidTimeRange))); +} + // --- Supply cap tests ------------------------------------------------------- #[test] @@ -1082,6 +1084,8 @@ fn test_supply_recovers_after_full_withdraw_allowing_new_stream() { .create_stream(&s.sender, &s.recipient, &500, &400, &500); assert_eq!(new_id, 1); assert_eq!(s.contract.get_total_supply(), 500); +} + // --- README content contract ----------------------------------------------- /// Verify that the README contains a "Resource Costs" section.