This document describes the automated CI/CD pipeline for Soroban smart contracts. The pipeline ensures that every Pull Request is "Mainnet-Ready" by verifying code formatting, linting, building, and WASM size constraints.
Rust Version: 1.79.0
Soroban SDK: 21.7.6
Target: wasm32-unknown-unknown
The toolchain version is pinned in rust-toolchain.toml to ensure consistency across all environments (local development, CI, and production).
Verifies code quality and formatting standards.
-
Formatting Check:
cargo fmt --check- Ensures all Rust code follows the project's formatting standards
- Configuration:
rustfmt.toml - Fails if any file needs formatting
-
Clippy Lints:
cargo clippy -- -D warnings- Runs Rust's official linter
- Treats all warnings as errors (
-D warnings) - Configuration:
clippy.toml - Checks for common mistakes, performance issues, and style violations
-
Common Issues Check:
- Detects
println!ordbg!macros (should usesoroban_sdk::log!) - Warns about TODO/FIXME comments
- Ensures production-ready code
- Detects
- β All files properly formatted
- β Zero Clippy warnings
- β No forbidden macros in production code
Builds the smart contract and validates WASM output.
-
Debug Build:
cargo build --target wasm32-unknown-unknown- Quick build for validation
- Ensures code compiles without errors
-
Release Build:
cargo build --target wasm32-unknown-unknown --release- Optimized build with
opt-level = "z" - Produces production-ready WASM
- Configuration in
Cargo.tomlprofile
- Optimized build with
-
Size Validation:
- Checks WASM file size against Soroban's 64KB limit
- Calculates size percentage
- Fails if size exceeds limit
- Generates size report in job summary
[profile.release]
opt-level = "z" # Optimize for size
overflow-checks = true # Keep safety checks
debug = 0 # No debug info
strip = "symbols" # Strip symbols
debug-assertions = false # Disable debug assertions
panic = "abort" # Smaller panic handler
codegen-units = 1 # Better optimization
lto = true # Link-time optimization- β Debug build succeeds
- β Release build succeeds
- β WASM size β€ 64KB
- β WASM artifact uploaded
Executes all unit and integration tests.
- Unit Tests: Tests within
src/lib.rsand modules - Integration Tests: Tests in
tests/directory - Test Output: Captured with
--nocapturefor debugging
- Initialization tests
- Market creation tests
- Bet placement tests
- Market resolution tests
- Edge cases and error conditions
- β All unit tests pass
- β All integration tests pass
- β Test report generated
Performs security checks on dependencies and code.
-
Dependency Audit:
cargo audit- Checks for known security vulnerabilities
- Scans all dependencies
- Non-blocking (warnings only)
-
Unsafe Code Detection:
- Scans for
unsafeblocks - Warns if unsafe code is found
- Ensures code safety
- Scans for
- β Security audit completed
- β Unsafe code documented (if any)
Aggregates results from all jobs and generates final report.
- Overall status of all checks
- Rust toolchain version
- Soroban SDK version
- WASM size metrics
- Test results
- Deployment readiness
-
Pull Requests to
main,dev, orstaging:on: pull_request: branches: [main, dev, staging] paths: - 'contracts/**' - '.github/workflows/soroban-ci.yml'
-
Push to
mainbranch:on: push: branches: [main] paths: - 'contracts/**'
Pipeline only runs when relevant files change:
contracts/**- Any contract code.github/workflows/soroban-ci.yml- Workflow itselfclippy.toml- Clippy configurationrustfmt.toml- Formatting configuration
The Soroban blockchain enforces a strict 64KB limit on WASM contract size.
- Build WASM in release mode with optimizations
- Get file size:
stat -c%s prediction_market.wasm - Convert to KB:
SIZE_KB = SIZE_BYTES / 1024 - Compare against limit:
SIZE_KB β€ 64 - Calculate percentage:
(SIZE_KB / 64) * 100
π¦ WASM file size: 42 KB (43,008 bytes)
π Size limit: 64 KB
β
WASM size is within limits (65% of maximum)
β WASM file exceeds Soroban limit!
Current: 68 KB
Limit: 64 KB
Exceeded by: 4 KB
- Use
opt-level = "z"in release profile - Enable LTO (Link-Time Optimization)
- Strip symbols and debug info
- Minimize dependencies
- Use
wasm-optfor additional optimization - Avoid large data structures
- Use references instead of cloning
Install Just: cargo install just
# Format code
just fmt
# Check formatting
just fmt-check
# Run Clippy
just clippy
# Run all lints
just lint
# Build WASM
just build-release
# Check WASM size
just check-size
# Run tests
just test
# Run all CI checks locally
just ci
# Fix auto-fixable issues
just fix# Format code
cd contracts/prediction_market
cargo fmt --all
# Check formatting
cargo fmt --all -- --check
# Run Clippy
cargo clippy --all-targets --all-features -- -D warnings
# Build WASM
cargo build --target wasm32-unknown-unknown --release
# Run tests
cargo test --lib -- --nocapture
# Check WASM size
stat -c%s target/wasm32-unknown-unknown/release/prediction_market.wasm-
Run Local Checks:
just ci
-
Ensure All Checks Pass:
- β
Code is formatted (
just fmt) - β
No Clippy warnings (
just clippy) - β
Tests pass (
just test) - β
WASM builds (
just build-release) - β
WASM size β€ 64KB (
just check-size)
- β
Code is formatted (
-
Commit Changes:
git add . git commit -m "feat: your feature description" git push origin your-branch
-
Create PR:
- GitHub Actions will automatically run CI
- All checks must pass before merge
- Review the "Checks" tab for details
- β All CI jobs must pass
- β Code review approved
- β No merge conflicts
- β Branch up to date with base
Error: cargo fmt --check fails
Solution:
just fmt
git add .
git commit -m "style: format code"Error: Clippy finds warnings
Solution:
# See warnings
just clippy
# Auto-fix if possible
just fix
# Manual fixes required for some warningsError: WASM file > 64KB
Solutions:
- Review dependencies - remove unused crates
- Optimize data structures
- Use references instead of cloning
- Enable all optimization flags
- Use
wasm-optfor additional optimization:just optimize
Error: Tests fail
Solution:
# Run tests locally with output
just test
# Debug specific test
cd contracts/prediction_market
cargo test test_name -- --nocaptureError: Compilation errors
Solution:
- Check Rust version:
rustc --version(should be 1.79.0) - Update toolchain:
rustup update - Clean and rebuild:
just clean just build-release
- rust-checks: ~2-3 minutes
- build-wasm: ~3-5 minutes
- run-tests: ~1-2 minutes
- security-audit: ~1-2 minutes
- Total: ~7-12 minutes
The pipeline uses multiple caching strategies:
- Rust toolchain cache:
actions-rust-lang/setup-rust-toolchain - Cargo dependencies cache:
Swatinem/rust-cache - Cache on failure: Enabled for faster retries
- Dependency Auditing:
cargo auditchecks for vulnerabilities - Unsafe Code Detection: Warns about unsafe blocks
- Clippy Security Lints: Catches common security issues
- Pinned Toolchain: Consistent Rust version
- Locked Dependencies:
Cargo.lockcommitted
- Keep dependencies up to date
- Review security advisories
- Minimize use of unsafe code
- Use Soroban SDK security features
- Follow Rust security guidelines
A PR is ready to merge when:
- β All CI jobs pass (green checkmarks)
- β Code review approved
- β WASM size within 64KB limit
- β Zero Clippy warnings
- β All tests passing
- β Security audit clean
- β Code properly formatted
Add to README.md:
[](https://github.com/YOUR_USERNAME/Stellar-PolyMarket/actions/workflows/soroban-ci.yml)Pipeline Version: 1.0.0
Last Updated: 2026-03-24
Rust Toolchain: 1.79.0
Soroban SDK: 21.7.6