Skip to content

Latest commit

 

History

History
80 lines (59 loc) · 2.68 KB

File metadata and controls

80 lines (59 loc) · 2.68 KB

Test Summary: create_vault with Zero Amount

Issue #19 Implementation

Changes Made

  1. Added validation in create_vault function (src/lib.rs:47-49)

    • Validates that amount > 0
    • Panics with message "amount must be positive" if amount is zero or negative
    • This ensures vault creation requires a positive stake amount
  2. Added test case (src/lib.rs:112-133)

    • test_create_vault_zero_amount: Tests that creating a vault with amount=0 panics
    • Uses #[should_panic(expected = "amount must be positive")] attribute
    • Verifies the contract rejects invalid zero-amount vaults

Test Output

running 1 test
test tests::test_create_vault_zero_amount - should panic ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Coverage

Current coverage: 39.13% (9/23 lines covered)

Note: The overall coverage is below 95% because this is the first test added to the contract. The create_vault function validation logic is now covered. Additional tests for other functions are needed to reach 95% coverage target.

Security Notes

  • Input Validation: The contract now explicitly rejects zero or negative amounts, preventing creation of meaningless vaults
  • Fail-Fast Behavior: Invalid inputs cause immediate panic, preventing state corruption
  • Clear Error Messages: The panic message clearly indicates the validation requirement
  • No Resource Waste: Invalid vault creation attempts are rejected before any state changes or token transfers

Behavior

When create_vault is called with amount == 0 (or negative):

  • Contract panics with error: "amount must be positive"
  • No vault is created
  • No events are emitted
  • Transaction fails and reverts

This is the expected and secure behavior for productivity vaults that require a financial stake.

Branch

  • Branch: test/create-vault-zero-amount
  • Commits:
    • test: create_vault with zero amount
    • ci: add GitHub Actions workflow and fix linting issues

CI/CD Pipeline

GitHub Actions workflow created (.github/workflows/ci.yml):

  • Triggers on push/PR to main/master branches
  • Runs on ubuntu-latest
  • Steps:
    1. Checkout code
    2. Install Rust stable toolchain
    3. Build with cargo build --verbose
    4. Run tests with cargo test --verbose
    5. Check formatting with cargo fmt -- --check
    6. Run linter with cargo clippy -- -D warnings

All CI checks pass locally:

✓ Build passed
✓ Tests passed
✓ Formatting passed
✓ Clippy passed

Code quality fixes applied:

  • Added #![allow(clippy::too_many_arguments)] to handle Soroban contract design pattern
  • Applied cargo fmt for consistent code formatting
  • All clippy warnings resolved