fix(subscription): validate create_plan amount and interval_days - #1501
Merged
aji70 merged 1 commit intoJul 24, 2026
Merged
Conversation
- Add Error::InvalidPlanParams (code 11) to the subscription contract error enum, appended after the existing PlanNotFound (code 10). - create_plan() now rejects amount <= 0 and interval_days == 0 with the typed error, after the paused check and before persisting the plan. Previously these were accepted unvalidated, allowing zero/negative-amount or zero-interval plans to be created. - Document the new error code and behavior in the subscription README. - Add unit tests covering zero amount, negative amount, zero interval_days, and confirm a valid plan still succeeds. Closes MyFanss#1377
|
@priscaenoch 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
closes #1377
MyfansContract::create_plan()accepted anyi128amount andu32interval_days with no validation, so a zero/negative amount or a zero-day interval plan could be created (a zero interval would makesubscribe's expiry math a no-op, effectively creating a permanently-non-expiring or degenerate plan).Error::InvalidPlanParams(code 11) to the subscription contract's#[contracterror]enum, appended afterPlanNotFound(code 10) per the "do not renumber existing variants" rule on the enum.create_plan()now rejectsamount <= 0orinterval_days == 0withpanic_with_error!(&env, Error::InvalidPlanParams), checked right after the existingPausedguard and before any storage writes.create_planpanic conditions in the subscription README.interval_days(each asserting the typed error viatry_create_plan), and a control test confirming a valid plan (amount = 1000,interval_days = 30) still succeeds.Verified every existing
create_plancall site acrosssrc/test.rs,tests/auth_matrix.rs, andtests/contract_integration.rsalready uses a positive amount (typically1000) and non-zerointerval_days(1or30), so none of them are affected by the new validation.Testing/validation performed
create_plancall sites in the crate to confirm none pass a zero/negative amount or zero interval_days.cargo test -p subscription,cargo fmt --check, or the wasm build locally. Please confirm CI (cargo test -p subscription) passes before merging.