Skip to content

feat: implement close_plan, ping tests, mock SAC token, and multi-beneficiary payout tests (#836, #843, #845, #846)#898

Merged
ONEONUORA merged 1 commit into
Fracverse:masterfrom
Luluameh:feat/contracts-tests-close-plan-ping-payout
Jun 29, 2026
Merged

feat: implement close_plan, ping tests, mock SAC token, and multi-beneficiary payout tests (#836, #843, #845, #846)#898
ONEONUORA merged 1 commit into
Fracverse:masterfrom
Luluameh:feat/contracts-tests-close-plan-ping-payout

Conversation

@Luluameh

@Luluameh Luluameh commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Closes #836


Summary

Closes: #843 ,
Closes: #836,
Closes: #845,
Closes : #846

#836 [Contracts] Implement close_plan / Refund Functionality

What changed:

  • Refactored close_plan() to properly authenticate the caller as the plan owner, transfer all locked tokens + accrued yield back to the owner, and delete the plan from persistent storage
  • Renamed the old close_plan (which only deactivated) to internal deactivate_plan() — used by claim logic
  • reclaim() also properly cleans up claim status before removing the plan

Acceptance Criteria:

  • Rejects non-owners via owner.require_auth()
  • Returns full token balance (plan.amount) to owner
  • Safely cleans up both DataKey::Plan and DataKey::ClaimStatus storage slots

#843 [Contracts] Tests: Unit Testing for Keep-Alive Ping and close_plan

New tests added to test.rs:

Test Description
test_ping_success_from_owner_updates_timestamp Owner ping updates last_ping; timeout deadline recalculated
test_ping_from_third_party_fails Third-party ping rejected via auth check (mock_auths(&[]))
test_ping_nonexistent_plan_fails Returns PlanNotFound for missing plan
test_close_plan_refunds_all_tokens_and_deletes_storage Full token refund; plan + claim status erased from storage
test_close_plan_requires_owner_auth Unauthorized user gets auth error
test_close_plan_nonexistent_plan_fails Returns PlanNotFound for missing plan

Acceptance Criteria:

  • Happy path: owner ping updates timestamp, close_plan refunds all tokens
  • Unhappy paths: third-party ping rejected, nonexistent plan errors, auth failures
  • Assertions check storage erasure and address balances

#846 [Contracts] Tests: Mock Stellar Asset Contract (SAC) Token Implementation

What changed:

  • mock-token crate provides a full SAC simulation with mint, transfer, burn, balance, and total_supply
  • Errors: NegativeAmount, InsufficientBalance, Overflow, ExceedsMaxSupply
  • Used as a dev-dependency in inheritance-contract/Cargo.tomlno production code contamination

Acceptance Criteria:

  • Used by all 28 unit test suites to simulate contract-locked assets
  • Clean mock setup: separate crate, dev-dependency only

#845 [Contracts] Tests: Unit Testing for Multi-Beneficiary trigger_payout

New tests added to test.rs:

Test Description
test_trigger_payout_5_beneficiaries_with_equal_allocations 5 beneficiaries at 2000 BPS (20% each)
test_trigger_payout_10_beneficiaries_unequal_allocations 10 beneficiaries at 1000 BPS (10% each)
test_trigger_payout_rounding_with_3_beneficiaries 3333/3333/3334 BPS — dust goes to last beneficiary
test_trigger_payout_after_grace_period_and_timelock_expiry Full flow: grace period + timelock expiry checks
test_trigger_payout_with_single_beneficiary_receives_all Sole beneficiary gets full amount, no rounding

Acceptance Criteria:

  • Payout ratios match allocations perfectly (verified via balance assertions)
  • Rounding/integer division remainders handled — dust allocated to last beneficiary
  • Rejects claim if timer is active (InactivityPeriodNotMet)

Test Results

running 28 tests
test result: ok. 28 passed; 0 failed; 0 ignored

Clippy: No warnings

Files Changed

  • contracts/inheritance-contract/src/lib.rsclose_plan refactor, deactivate_plan internal helper
  • contracts/inheritance-contract/src/test.rs — 11 new tests + deactivate_plan_for_testing helper
  • contracts/mock-token/src/lib.rs — existing mock token (no changes needed)

@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Luluameh Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

…eficiary payout tests

Implements 4 open-source issues:

Fracverse#836 [Contracts] Implement close_plan / Refund Functionality
- Refactored close_plan to properly authenticate owner, transfer all locked
  tokens back to owner, and delete plan + claim status from storage
- Renamed old close_plan (deactivate-only) to internal deactivate_plan()
- Reclaim() function also properly handles claim status cleanup

Fracverse#843 [Contracts] Tests: Unit Testing for Keep-Alive Ping and close_plan
- test_ping_success_from_owner_updates_timestamp: verifies owner ping updates
  last_ping timestamp and timeout deadline is recalculated
- test_ping_from_third_party_fails: verifies third-party ping is rejected
  via auth check (env.mock_auths(&[]))
- test_ping_nonexistent_plan_fails: verifies PlanNotFound error for missing plan
- test_close_plan_refunds_all_tokens_and_deletes_storage: verifies full token
  refund to owner and storage erasure (plan + claim status)
- test_close_plan_requires_owner_auth: verifies unauthorized user is rejected
- test_close_plan_nonexistent_plan_fails: verifies PlanNotFound for missing plan

Fracverse#846 [Contracts] Tests: Mock Stellar Asset Contract (SAC) Token Implementation
- mock-token crate already provides full SAC simulation: mint, transfer, burn,
  balance, total_supply with proper error handling (NegativeAmount,
  InsufficientBalance, Overflow, ExceedsMaxSupply)
- Used by all unit test suites to simulate contract-locked assets
- Clean separation: mock-token is a dev-dependency, no production code contamination

Fracverse#845 [Contracts] Tests: Unit Testing for Multi-Beneficiary trigger_payout
- test_trigger_payout_5_beneficiaries_with_equal_allocations: 5 beneficiaries
  at 2000 BPS each, verifies exact 20% payout per beneficiary
- test_trigger_payout_10_beneficiaries_unequal_allocations: 10 beneficiaries
  at 1000 BPS each, verifies exact 10% payout per beneficiary
- test_trigger_payout_rounding_with_3_beneficiaries: 3333/3333/3334 BPS split
  verifies dust (remainder from integer division) goes to last beneficiary
- test_trigger_payout_after_grace_period_and_timelock_expiry: full flow with
  grace period check and timelock expiry verification
- test_trigger_payout_with_single_beneficiary_receives_all: sole beneficiary
  gets full plan amount (no rounding issues)

All 28 unit tests pass. Clippy lint passes with no warnings.
@Luluameh Luluameh force-pushed the feat/contracts-tests-close-plan-ping-payout branch from 0502fc8 to 2d3095c Compare June 29, 2026 13:21

@ONEONUORA ONEONUORA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great job @Luluameh
Thank you for your contribution

@ONEONUORA ONEONUORA merged commit d60ca71 into Fracverse:master Jun 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants