Skip to content

[FEATURE] Add contract unit test suite: no tests exist for any contract #17

Description

@derbydaniels9-cpu

Summary

There are no contract unit tests. Without a test suite, there is no way to verify that the savings lock contract correctly enforces maturity dates, penalty calculations, or target amount conditions before deployment to mainnet.

Impact

A bug in the withdrawal logic (e.g. penalty not applied on early exit, or lock not enforced) directly causes financial loss — either to users or to the protocol.

Proposed test setup using the Soroban test framework

// tests/savings_lock_test.rs
#[cfg(test)]
mod tests {
    use soroban_sdk::{testutils::Address as _, Env, Address};
    use crate::SavingsLockContract;

    #[test]
    fn test_early_withdrawal_applies_penalty() {
        let env = Env::default();
        let contract_id = env.register_contract(None, SavingsLockContract);
        let user = Address::generate(&env);
        // deposit with 30-day lock
        // attempt withdrawal on day 5
        // assert penalty of 10% was applied
        // assert net payout = amount * 0.9
    }

    #[test]
    fn test_withdrawal_blocked_before_maturity() { ... }

    #[test]
    fn test_full_withdrawal_after_maturity_no_penalty() { ... }

    #[test]
    fn test_target_lock_blocked_before_target_reached() { ... }
}

Coverage targets

  • All lock types: FLEXIBLE, FIXED, TARGET
  • Early withdrawal penalty
  • Maturity date enforcement
  • Interest accrual accuracy
  • Edge case: deposit of 0 should be rejected

Files affected:

  • New: tests/savings_lock_test.rs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions