Skip to content

test: Add missing contract test coverage for emergency stop, error paths, and edge cases #65

Description

@grantfox-oss

Problem

The contract test file (contracts/src/test.rs) covers happy-path creation, deposit, and rebalance, but has no tests for:

  • set_emergency_stop — no test verifies non-admin callers are rejected, and no test verifies the flag actually blocks deposit and execute_rebalance
  • Calling get_portfolio, check_rebalance_needed, or execute_rebalance with a non-existent portfolio ID
  • Creating a portfolio with an empty allocations map (should fail since sum is 0, not 100)
  • Depositing to a portfolio the caller does not own
  • Rebalancing a portfolio the caller does not own

Proposed Fix

Add the following test cases to contracts/src/test.rs:

Tests for emergency stop

  • test_set_emergency_stop_unauthorized — non-admin calls set_emergency_stop(true), call is rejected
  • test_set_emergency_stop_blocks_deposit — admin enables stop, user tries to deposit, gets Error::EmergencyStop
  • test_set_emergency_stop_blocks_rebalance — admin enables stop, execute_rebalance returns Error::EmergencyStop

Tests for error paths

Tests for ownership checks

  • test_deposit_wrong_portfolio — user A creates portfolio, user B tries to deposit, rejected
  • test_execute_rebalance_not_owner — user A creates portfolio, user B tries to rebalance, rejected

Files to modify

  • contracts/src/test.rs — add new test functions

Acceptance Criteria

  • test_set_emergency_stop_unauthorized passes
  • test_set_emergency_stop_blocks_deposit passes
  • test_set_emergency_stop_blocks_rebalance passes
  • test_get_portfolio_not_found passes
  • test_create_portfolio_empty_allocations passes
  • test_deposit_wrong_portfolio passes
  • test_execute_rebalance_not_owner passes
  • All existing tests continue to pass
  • cargo test passes with no failures

Affected Area

Smart Contract (testing only)

Activity

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

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignbackendBackend relatedenhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions