Skip to content

Implement on-chain notification expiration (Closes #128)#157

Open
giftexceed wants to merge 2 commits into
Core-Foundry:mainfrom
giftexceed:feat/notification-expiration-128
Open

Implement on-chain notification expiration (Closes #128)#157
giftexceed wants to merge 2 commits into
Core-Foundry:mainfrom
giftexceed:feat/notification-expiration-128

Conversation

@giftexceed

Copy link
Copy Markdown

Summary

Implements configurable-duration notification expiration for notifications stored on-chain (issue #128).

Feature

  • schedule_notification(id, creator, ttl_seconds) — stores a ScheduledNotification { id, creator, created_at, expires_at } where expires_at = created_at + ttl_seconds. Rejects a zero or overflowing duration (InvalidExpirationDuration) and a duplicate id (AlreadyExists); emits NotificationScheduled.
  • get_notification(id) / is_notification_expired(id) — read a notification's details / validity. The expiry boundary is inclusive (expired once now >= expires_at).
  • expire_notification(id) — permissionless finalization of an elapsed notification (e.g. by an off-chain keeper): reaps storage and emits NotificationExpired. A not-yet-elapsed notification is rejected with NotificationNotExpired.
  • cancel_notification(id, caller) — now treats an expired tracked notification as invalid (NotificationExpired) and reaps a valid one on cancellation, while still accepting untracked ids for backward compatibility.

New ScheduledNotification type; new errors NotificationExpired, InvalidExpirationDuration, NotificationNotExpired; new events NotificationScheduled / NotificationExpired (category Notification), following the existing trailing category/priority topic convention.

Tests

15 new contract tests in tests/expiration_test.rs cover: storage of created/expiry timestamps, the expiry boundary (before / at / after), NotificationScheduled and NotificationExpired event shapes (topics + data), expired notifications being uncancellable, finalized expiry reaping storage, duration validation, duplicate/unknown handling, pause gating, and cancellation (valid, expired, untracked, paused).

Heads-up: this PR also repairs a broken main

The contract crate did not compile on main. Prior merges around the notification-priority-levels work were resolved by keeping both sides of each conflict, leaving duplicated enum definitions, struct fields, imports, and test functions in events.rs, autoshare_logic.rs, and notification_test.rs (e.g. two NotificationPriority enums; 18 priority fields where 9 were expected; duplicated priority_of test helpers and malformed assert_eq! calls).

Making #128's tests pass required restoring a compiling crate. I resolved the duplications to the coherent Low/Medium/High/Critical priority scheme (recovered from the last clean commit, 33c5764), re-added the ScheduledNotificationCancelled event/handler cleanly, and aligned AutoShareDetails.priority to the same scheme.

Verification

cargo test  →  119 passed; 0 failed
cargo fmt --check  →  clean
cargo build  →  0 warnings

Closes #128

Adds configurable-duration expiration for notifications stored on-chain:

- schedule_notification(id, creator, ttl_seconds): stores a notification
  with created_at + expires_at; rejects zero/overflowing durations and
  duplicate ids; emits NotificationScheduled.
- is_notification_expired / get_notification: query a notification's
  validity and details (inclusive expiry boundary).
- expire_notification(id): permissionless finalization of an elapsed
  notification — reaps storage and emits NotificationExpired; rejects a
  not-yet-elapsed one.
- cancel_notification now treats an expired tracked notification as
  invalid (NotificationExpired) and reaps a valid one on cancellation,
  while still accepting untracked ids for backward compatibility.

New errors: NotificationExpired, InvalidExpirationDuration,
NotificationNotExpired. New type ScheduledNotification. New events
NotificationScheduled and NotificationExpired (category Notification),
following the existing trailing category/priority topic convention.

Adds 15 contract tests covering scheduling, the expiry boundary, event
shapes, expired-notification invalidity, duration validation, pause
gating, and cancellation.

This change also repairs the contract crate, which did not compile on
main: prior merges around the notification-priority-levels work left
duplicated enum definitions, struct fields, imports, and test functions
in events.rs, autoshare_logic.rs and notification_test.rs. These are
resolved to the coherent Low/Medium/High/Critical priority scheme so the
crate builds and the full suite (119 tests) passes.
@Abd-Standard

Copy link
Copy Markdown
Collaborator

please fix CI and resolve conflicts

…xpiration-128

# Conflicts:
#	contract/contracts/hello-world/src/autoshare_logic.rs
#	contract/contracts/hello-world/src/tests/notification_test.rs
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.

[Contracts] Implement Notification Expiration Logic

2 participants