Skip to content

feat(airdrops): enforce status lifecycle state machine and transitions (#87) - #275

Open
ghzhost wants to merge 1 commit into
SmartDropLabs:mainfrom
ghzhost:fix/airdrop-status-state-machine
Open

ghzhost wants to merge 1 commit into
SmartDropLabs:mainfrom
ghzhost:fix/airdrop-status-state-machine

Conversation

@ghzhost

@ghzhost ghzhost commented Sep 11, 2026

Copy link
Copy Markdown

Summary

Closes #87

Implements a strict status state machine for airdrops across their lifecycle:

  • Allowed transitions:
    • draft -> executing, cancelled, expired
    • executing -> completed, failed, cancelled, expired
    • Terminal statuses: completed, failed, cancelled, expired (cannot transition to any other status)
  • Enforces transition validation via assertTransition(currentStatus, nextStatus) and transitionTo(id, nextStatus).
  • Helper transition methods: markExecuting, markCompleted, markFailed, markExpired.
  • Restricts expiry_ledger updates via update(id, data) only when an airdrop is in draft status (returns 400 VALIDATION_ERROR otherwise).
  • Registers INVALID_STATE_TRANSITION (HTTP 409) in AppError and handles non-cancellable transitions on POST /api/v1/airdrops/:id/cancel.
  • Updates documentation in README.md and adds comprehensive unit & integration tests covering state transitions, error codes, and cancellation logic.

Validation

  • Ran full test suite via Jest (test/airdrops-service.test.js, test/airdrops.test.js, test/airdropExpiry.test.js, test/errorCodes.test.js, etc.).
  • All 129 tests in affected suites passed cleanly.

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.

Airdrop status has no enforced state machine — cancel() and update() succeed regardless of current status

1 participant