-
Added validation in
create_vaultfunction (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
- Validates that
-
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
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
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.
- 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
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:
test/create-vault-zero-amount - Commits:
test: create_vault with zero amountci: add GitHub Actions workflow and fix linting issues
GitHub Actions workflow created (.github/workflows/ci.yml):
- Triggers on push/PR to main/master branches
- Runs on ubuntu-latest
- Steps:
- Checkout code
- Install Rust stable toolchain
- Build with
cargo build --verbose - Run tests with
cargo test --verbose - Check formatting with
cargo fmt -- --check - 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 fmtfor consistent code formatting - All clippy warnings resolved