Skip to content

Add test for recurring disbursement failure without mutating schedule… - #546

Merged
thegreatfeez merged 1 commit into
Ac0rdP:mainfrom
akprinciple:Return_TransferFailed_cleanly
Aug 31, 2026
Merged

Add test for recurring disbursement failure without mutating schedule…#546
thegreatfeez merged 1 commit into
Ac0rdP:mainfrom
akprinciple:Return_TransferFailed_cleanly

Conversation

@akprinciple

Copy link
Copy Markdown
Contributor

closes #448

Guard recurring disbursements against insufficient balance before state mutation

Summary

This PR ensures recurring disbursements fail early with the existing TransferFailed error variant before mutating any schedule state when the contract treasury lacks sufficient token balance to cover the scheduled disbursement period.


Changes

  • Pre-Execution Balance Check: Added an upfront contract balance verification in disburse_recurring prior to initiating the token transfer.
  • Early Exit on Low Funds: Returns Error::TransferFailed immediately if the contract treasury balance is lower than the scheduled amount.
  • State Mutation Guard: Guarantees that no recurring schedule state fields are updated on insufficient balance failures.
  • Error Variant Reuse: Reused the existing TransferFailed error variant defined in the contract error enum.

Why

Previously, the recurring disbursement flow could progress toward the transfer operation without validating available treasury liquidity. In low-balance scenarios, the transaction could abort after entering a state-mutation path, risking schedule state corruption and inconsistent accounting.

This pre-check ensures strict check-effects-interactions safety and protects schedule state integrity.


Validation

Added a targeted regression test verifying behavior under insufficient contract balance:

  • Asserts Error::TransferFailed is returned deterministically.
  • Asserts last_disbursed_at, total_disbursed, and periods_disbursed remain completely unchanged.
  • Asserts the recurring schedule remains in an active state.

@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown

@akprinciple is attempting to deploy a commit to the thegreatfeez's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@akprinciple 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

@thegreatfeez
thegreatfeez merged commit a96585e into Ac0rdP:main Aug 31, 2026
2 of 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

Development

Successfully merging this pull request may close these issues.

Return TransferFailed cleanly without mutating schedule state when the treasury balance is insufficient for a disbursement

2 participants