Skip to content

Feat/input#188

Merged
ayshadogo merged 2 commits into
Dfunder:mainfrom
nafsonig:feat/input
May 29, 2026
Merged

Feat/input#188
ayshadogo merged 2 commits into
Dfunder:mainfrom
nafsonig:feat/input

Conversation

@nafsonig
Copy link
Copy Markdown
Contributor

Implementation Complete ✅

I've successfully implemented strict validation on campaign initialization. Here's what was done:

1. Added Error Types (types.rs)

Added a comprehensive Error enum with five descriptive error variants:

  • InvalidGoalAmount - when goal_amount ≤ 0
  • InvalidEndTime - when end_time ≤ current ledger timestamp
  • InvalidAssets - when accepted_assets is empty
  • InvalidMilestones - when milestones aren't sorted or other milestone issues
  • MilestoneMismatch - when last milestone.target_amount ≠ goal_amount

2. Implemented initialize() Function (lib.rs)

The function enforces all acceptance criteria in sequence:

  1. goal_amount > 0 ✓ - Validates and panics with InvalidGoalAmount
  2. end_time > current ledger timestamp ✓ - Uses env.ledger().timestamp() for comparison
  3. accepted_assets non-empty ✓ - Validates and panics with InvalidAssets
  4. milestones sorted ascending ✓ - Validates each milestone is greater than the previous
  5. last milestone.target_amount == goal_amount ✓ - Ensures milestone alignment with goal
  6. Descriptive error panics ✓ - Each validation panics with appropriate error symbols

3. Helper Functions

  • validate_milestones() - Ensures milestones are properly sorted and the last equals goal_amount
  • panic_with_error() - Converts error types to descriptive panic messages using env.panic_with_error()

Key Features:

  • ✅ Validations occur in logical order (fail-fast approach)
  • ✅ All inputs stored only after all validations pass
  • ✅ Milestones stored individually in persistent storage
  • ✅ Campaign initialized with Active status and 0 raised_amount
  • ✅ Comprehensive error messages for debugging invalid deployments

The implementation prevents invalid campaigns from being deployed and provides clear error messaging for all failure scenarios.

Made changes.

closes #173

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

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

Copy link
Copy Markdown
Contributor

@ayshadogo ayshadogo left a comment

Choose a reason for hiding this comment

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

LGTM

Thank you for your contribution

@ayshadogo ayshadogo merged commit c5979db into Dfunder:main May 29, 2026
1 check failed
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.

Implement initialization input validation

2 participants