Skip to content

Conversation

@dinahmaccodes
Copy link
Contributor

Description

Add Project Termination Feature

This pull request introduces functionality to manage project termination within the Budget module, including the ability to mark projects as terminated and enforce project status checks across various operations. It also updates the test suite to accommodate these changes.

Below are the key changes grouped by theme:

Core Functionality Enhancements

  • Added project_status mapping to track the active or terminated state of projects (src/budgetchain/Budget.cairo).
  • Introduced the terminate_project function to allow admins to terminate projects and emit a ProjectTerminated event (src/budgetchain/Budget.cairo).
  • Added _assert_project_active helper function to ensure operations are only performed on active projects (src/budgetchain/Budget.cairo).

🔴 Project Termination System

  • New Functions:

    • terminate_project() - Allows admin to terminate projects
    • assert_status() - Check project active/terminated status
    • is_project_terminated() - Query project termination state
    • _assert_project_active() - Internal validation for active projects
  • Project Status Tracking:

    • Added project_status storage mapping for tracking project states
    • Projects default to active (true) when created via allocate_project_budget

    🔒 Security Enhancements

Project Termination Safeguards

  • Function Protection: Added termination checks to:

    • create_fund_request() - Cannot request funds for terminated projects
    • create_milestone() - Cannot create milestones for terminated projects (optional)
    • release_funds() - Cannot release funds for terminated projects
  • Status Integrity:

    • Once terminated, projects cannot be reactivated
    • Prevents accidental fund releases on closed projects
    • Maintains audit trail of project states

Admin Controls

  • Only admin can terminate projects
  • Proper authorization checks on all new functions

New Error Messages

pub const ERROR_PROJECT_TERMINATED: felt252 = 'Project is terminated';
pub const ERROR_PROJECT_ALREADY_TERMINATED: felt252 = 'Project already terminated';
pub const ERROR_CONTRACT_PAUSED: felt252 = 'Contract is paused';
pub const ERROR_ALREADY_PAUSED: felt252 = 'Contract already paused';

Interface Updates

  • Updated IBudget interface to include terminate_project and assert_status functions for project management (src/interfaces/IBudget.cairo).

Technical Details

Storage Changes:

Function Modifications:

  • Updated allocate_project_budget() to set project status to true
  • Added pause checks to all state-changing functions
  • Enhanced project validation in fund-related operations

Test Suite Updates

  • Modified tests to use the setup_project_with_milestones helper, ensuring projects are initialized with proper status checks (tests/test_budgetchain.cairo). [1] [2] [3]
  • Added test cases for project isolation, ensuring transactions are correctly associated with their respective projects (tests/test_budgetchain.cairo).

Testing Status

  • All existing tests pass ✅
  • New functionality fully tested ✅
  • Edge cases covered ✅
  • Error conditions validated ✅

Closes #51

image

@dinahmaccodes
Copy link
Contributor Author

Please review @anonfedora

Copy link
Contributor

@anonfedora anonfedora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM...

@anonfedora anonfedora merged commit 1876cc4 into BudgetChain:main Jul 3, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SC]: Implement Project Termination/Cancellation Feature

2 participants