Skip to content

fix(subscription): validate create_plan amount and interval_days - #1501

Merged
aji70 merged 1 commit into
MyFanss:mainfrom
priscaenoch:feature/1377-subscription-validate-create-plan
Jul 24, 2026
Merged

fix(subscription): validate create_plan amount and interval_days#1501
aji70 merged 1 commit into
MyFanss:mainfrom
priscaenoch:feature/1377-subscription-validate-create-plan

Conversation

@priscaenoch

@priscaenoch priscaenoch commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

closes #1377

MyfansContract::create_plan() accepted any i128 amount and u32 interval_days with no validation, so a zero/negative amount or a zero-day interval plan could be created (a zero interval would make subscribe's expiry math a no-op, effectively creating a permanently-non-expiring or degenerate plan).

  • Added Error::InvalidPlanParams (code 11) to the subscription contract's #[contracterror] enum, appended after PlanNotFound (code 10) per the "do not renumber existing variants" rule on the enum.
  • create_plan() now rejects amount <= 0 or interval_days == 0 with panic_with_error!(&env, Error::InvalidPlanParams), checked right after the existing Paused guard and before any storage writes.
  • Documented the new error code and the updated create_plan panic conditions in the subscription README.
  • Added four unit tests: zero amount, negative amount, zero interval_days (each asserting the typed error via try_create_plan), and a control test confirming a valid plan (amount = 1000, interval_days = 30) still succeeds.

Verified every existing create_plan call site across src/test.rs, tests/auth_matrix.rs, and tests/contract_integration.rs already uses a positive amount (typically 1000) and non-zero interval_days (1 or 30), so none of them are affected by the new validation.

Testing/validation performed

  • Manual review of all create_plan call sites in the crate to confirm none pass a zero/negative amount or zero interval_days.
  • Note: this sandbox has no Rust toolchain available, so I could not run cargo test -p subscription, cargo fmt --check, or the wasm build locally. Please confirm CI (cargo test -p subscription) passes before merging.

- 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
@drips-wave

drips-wave Bot commented Jul 23, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@aji70
aji70 merged commit e6ec953 into MyFanss:main Jul 24, 2026
1 of 7 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.

Contract: Validate create_plan amount and interval_days

2 participants