In a rotating savings and credit association (ROSCA), once all members have contributed in a round, the member designated to receive the pooled funds (based on the predefined payout_order) becomes eligible to collect the total contribution for that round.
The collect_payout function allows the current payout recipient to withdraw the accumulated funds for their round.
/// Withdraw funds if it's the member's turn to collect
fn collect_payout(
ref self: TContractState,
group_id: felt252,
member: ContractAddress
);
🎯 Function Responsibilities
The collect_payout function should:
-
Validate that the specified group_id exists and is in an Active state.
-
Ensure all contributions for the current round have been received.
-
Confirm that the member calling the function is the designated recipient for this round.
-
Transfer or mark the funds as withdrawn by the member.
-
Prevent duplicate collections by the same member in a single round.
-
Automatically advance to the next round or mark the group as Completed if it was the final round.
⚠️ Constraints & Rules
-
Group must be Active.
-
All expected contributions for the current round must be completed.
-
Only the current round’s designated recipient (based on payout_order) can call this function.
-
Once collected, funds cannot be collected again for the same round.
-
If it's the final round, update the group status to Completed.
🧪 Unit Tests
Ensure robust testing of the payout logic with the following test cases:
✅ Positive Test Cases
Valid recipient successfully collects payout.
After payout, the round advances and the next recipient is queued.
Group is marked as Completed after final round payout.
❌ Negative Test Cases
Member tries to collect before all contributions are received — fails.
Member not in the payout queue tries to collect — fails.
Duplicate collection attempts by the same member — fail.
Collection attempt on non-existent or completed group — fails.
In a rotating savings and credit association (ROSCA), once all members have contributed in a round, the member designated to receive the pooled funds (based on the predefined payout_order) becomes eligible to collect the total contribution for that round.
The collect_payout function allows the current payout recipient to withdraw the accumulated funds for their round.
🎯 Function Responsibilities
The collect_payout function should:
Validate that the specified group_id exists and is in an Active state.
Ensure all contributions for the current round have been received.
Confirm that the member calling the function is the designated recipient for this round.
Transfer or mark the funds as withdrawn by the member.
Prevent duplicate collections by the same member in a single round.
Automatically advance to the next round or mark the group as Completed if it was the final round.
Group must be Active.
All expected contributions for the current round must be completed.
Only the current round’s designated recipient (based on payout_order) can call this function.
Once collected, funds cannot be collected again for the same round.
If it's the final round, update the group status to Completed.
🧪 Unit Tests
Ensure robust testing of the payout logic with the following test cases:
✅ Positive Test Cases
Valid recipient successfully collects payout.
After payout, the round advances and the next recipient is queued.
Group is marked as Completed after final round payout.
❌ Negative Test Cases
Member tries to collect before all contributions are received — fails.
Member not in the payout queue tries to collect — fails.
Duplicate collection attempts by the same member — fail.
Collection attempt on non-existent or completed group — fails.