Skip to content

feat: added reactivate_policy plus a get_deactivated_policies paginat…#1059

Open
DTech-Wiz1 wants to merge 1 commit into
Remitwise-Org:mainfrom
DTech-Wiz1:feat/insurance-reactivate-and-list-deactivated
Open

feat: added reactivate_policy plus a get_deactivated_policies paginat…#1059
DTech-Wiz1 wants to merge 1 commit into
Remitwise-Org:mainfrom
DTech-Wiz1:feat/insurance-reactivate-and-list-deactivated

Conversation

@DTech-Wiz1

Copy link
Copy Markdown

Description

Completes the insurance policy lifecycle by introducing policy reactivation support and visibility into deactivated policies.

Previously, deactivate_policy removed a policy from ActivePolicies and marked it inactive, but the underlying policy record remained stored indefinitely with no way to reactivate it or enumerate inactive policies. This created a one-way state transition that forced integrators to create entirely new policies to recover from suspensions or administrative mistakes, resulting in lost continuity and reduced auditability.

This change introduces:

  • reactivate_policy(env, caller, policy_id) to restore an inactive policy.
  • get_deactivated_policies(env, owner, cursor, limit) for paginated retrieval of inactive policies owned by a specific user.
  • PolicyReactivatedEvent for lifecycle observability.
  • Shared active-set helper functions used by policy creation, deactivation, and reactivation to prevent duplication and ensure consistency.

Additional behavior:

  • Reactivation is authorized for the same actors allowed to deactivate a policy (policy owner or contract owner).
  • Reactivation sets active = true, refreshes next_payment_date, and safely re-adds the policy to ActivePolicies.
  • Reactivation rejects already-active policies with a typed error.
  • Reactivation rejects operations that would exceed MAX_POLICIES using MaxPoliciesReached.
  • Active policy IDs cannot be duplicated in the active set.
  • Added doc comments describing active ⇄ inactive transitions and policy-cap interactions.
  • Updated EVENTS.md with PolicyReactivatedEvent documentation.

Closes #822

Type of Change

  • feat — new functionality
  • fix — bug fix
  • docs — documentation only
  • refactor — code restructuring with no behaviour change
  • test — test additions or improvements
  • ci — CI configuration changes
  • chore — maintenance, dependencies, tooling

How Has This Been Tested?

  • cargo test --workspace passes
  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-targets --all-features -- -D warnings passes
  • Coverage ≥ 95% for affected crates (cargo llvm-cov --package <crate> --fail-under-lines 95)
  • Fuzz harness passes (cargo test -p credence_bond fuzz::test_bond_fuzz -- --nocapture)
  • Error code wire-stability test passes (cargo test -p credence_errors error_codes_wire)
  • Release build passes (cargo build --release)

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.

Insurance: add reactivate_policy plus a get_deactivated_policies paginated query for the one-way deactivation gap

1 participant