Skip to content

Implement contribute Function for Active Group Participation #178

@mubarak23

Description

@mubarak23

During each round of the rotating savings and credit association (ROSCA), all members contribute a predefined amount of funds. The contribute function handles these deposits, ensuring that each member contributes only once per round, and triggers the payout once all contributions for that round are collected.

This function is called by group members to send in their share for the ongoing round.

/// Contribute to the group for the current round
fn contribute(
    ref self: TContractState,
    group_id: felt252,
    member: ContractAddress,
    amount: u128
);

🎯 Function Responsibilities
The contribute function should:

Validate that the group exists and is in an Active state.

Confirm that the member is part of the group.

Ensure the contribution amount matches the predefined contribution_amount.

Track the contribution for the current round.

Prevent double contributions by the same member within the same round.

Once all members have contributed:

Trigger a payout to the current recipient (based on payout_order).

Advance to the next round or mark the group as Completed if it's the final round.

⚠️ Constraints & Rules
Group must be Active and not Completed.

member must be a valid participant in the group.

Contribution amount must exactly match the group’s contribution_amount.

Each member can contribute only once per round.

Payout must only occur once all expected contributions for the round are received.

If the group reaches its final round, update status to Completed.

🧪 Unit Tests
Cover the function thoroughly with the following test cases:

✅ Positive Test Cases
Valid member contributes the exact amount successfully.

All members contribute and payout is issued to the correct recipient.

Group progresses to the next round after full contributions.

❌ Negative Test Cases
Contributing to a non-existent group fails.

Contributing to a group that is not active fails.

Contributions by non-members are rejected.

Contributions of incorrect amounts are rejected.

Double contributions by the same member in a single round are prevented.

Contribution fails if the group is already completed.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions