Skip to content

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

Closed

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

  1. Oshone87 commented on Aug 22, 2026

    @Oshone87
    Contributor

    please can i work on this ?

  2. grantfox-oss commented on Aug 22, 2026

    @grantfox-oss
    Author

    🦊 GrantFox — @Oshone87 has been assigned to this issue as part of the Third Campaign campaign!

    Next steps:

    1. Open a Pull Request referencing this issue (e.g., Closes #65)
    2. Your PR will be reviewed by the grantFoxin maintainers

    Good luck! Track your progress on GrantFox.

  3. grantfox-oss commented on Aug 23, 2026

    @grantfox-oss
    Author

    🎉 This issue has been marked as completed on GrantFox as part of the Third Campaign campaign!

    @Oshone87's PR #70 was approved and merged by @Uchechukwu-Ekezie.

    🏆 @Oshone87: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (201 total points). Track your full progress on GrantFox.

    👏 Great work, @Oshone87! Keep contributing to grantFoxin.

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