This document describes the continuous integration (CI) checks that run on every pull request and push to the main branch for Access Layer contracts.
The CI pipeline ensures code quality, correctness, and consistency across the contract codebase. All checks must pass before a pull request can be merged.
The CI workflow is defined in .github/workflows/ci.yml and runs three primary checks:
Command: cargo fmt --all -- --check
Purpose: Ensures all Rust code follows consistent formatting rules defined by rustfmt.
What it checks:
- Indentation and spacing
- Line length limits
- Import ordering
- Code structure formatting
How to fix failures:
# Auto-format all code
cargo fmt --all
# Or use the Makefile helper
make fmtLocal verification:
# Check formatting without modifying files
cargo fmt --all -- --check
# Or use the Makefile helper
make fmt-checkCommand: cargo clippy --workspace --all-targets -- -D warnings
Purpose: Catches common mistakes, anti-patterns, and potential bugs using Rust's official linter.
What it checks:
- Unused variables and imports
- Inefficient code patterns
- Potential logic errors
- Type conversion issues
- Idiomatic Rust violations
How to fix failures:
# Run clippy and see warnings
cargo clippy --workspace --all-targets
# Or use the Makefile helper
make clippyCommon issues:
- Unused imports: Remove them or use
#[allow(unused_imports)]if needed for conditional compilation - Unnecessary clones: Clippy suggests when cloning can be avoided
- Complex boolean expressions: Simplify or add comments explaining the logic
Command: cargo test --workspace
Purpose: Runs all unit tests and integration tests to verify contract behavior.
What it checks:
- Unit tests in
src/modules (marked with#[test]) - Integration tests in
tests/directory - Doc tests in code comments
- Test snapshots for deterministic behavior
How to fix failures:
# Run all tests
cargo test --workspace
# Run tests for a specific package
cargo test -p creator-keys
# Run a specific test file
cargo test --test buy_quote_monotonicity
# Run a specific test
cargo test test_buy_quote_is_identical_across_consecutive_calls
# Or use the Makefile helper
make testTest categories:
- Unit tests: Test individual functions and modules in isolation
- Integration tests: Test contract behavior end-to-end with mocked Soroban environment
- Snapshot tests: Verify deterministic output by comparing against stored snapshots
Before pushing code, run all CI checks locally:
# Run all checks individually
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
# Or use the Makefile to run all checks
make verifyPlatform: Ubuntu Latest (GitHub Actions runner)
Rust toolchain: Stable channel (specified in rust-toolchain.toml)
Components: rustfmt, clippy (installed automatically)
Symptom: CI shows formatting differences
Solution:
- Run
cargo fmt --alllocally - Commit the formatting changes
- Push the updated code
Symptom: CI shows clippy warnings treated as errors
Solution:
- Run
cargo clippy --workspace --all-targetslocally - Fix the reported issues
- If a warning is intentional, add
#[allow(clippy::lint_name)]with a comment explaining why - Commit and push the fixes
Note: Never use #[allow(clippy::all)] or disable all warnings. Address each warning individually.
Symptom: One or more tests fail in CI
Solution:
- Run the failing test locally:
cargo test <test_name> - Check the test output for assertion failures or panics
- Review recent changes that might have affected the test
- Fix the code or update the test if behavior intentionally changed
- For snapshot tests, regenerate snapshots if the new behavior is correct
- Commit and push the fixes
Common causes:
- Logic errors in contract code
- Incorrect test assertions
- Missing test setup (e.g., fee config not set)
- Outdated test snapshots
When adding new tests, ensure they:
- Are deterministic: Tests should produce the same result every run
- Are isolated: Tests should not depend on execution order
- Have clear names: Use descriptive test function names like
test_buy_quote_monotonic_with_zero_protocol_fee - Include assertions: Every test should verify expected behavior with
assert!,assert_eq!, orassert_ne! - Use test helpers: Import from
contract_test_envto reduce boilerplate
See docs/deterministic-quote-tests.md for guidance on writing quote tests.
Typical run time: 2-3 minutes for all checks
Optimization tips:
- CI uses caching for Rust dependencies
- Tests run in parallel by default
- Format and clippy checks are fast (<30 seconds each)
The CI status badge is displayed in the README:
A green badge indicates all checks are passing.
Potential additions to the CI pipeline:
- Code coverage: Track test coverage percentage
- Security audits: Run
cargo auditto check for vulnerable dependencies - Benchmark tests: Detect performance regressions
- Contract size checks: Ensure WASM output stays within size limits
- Gas/instruction cost analysis: Monitor computational costs
If CI checks are failing and you're unsure how to fix them:
- Read the CI log output carefully
- Run the failing check locally to reproduce
- Check recent commits for changes that might have caused the failure
- Ask in pull request comments for help from maintainers