Skip to content

feat: Recovery dry_run mode#770

Merged
greatest0fallt1me merged 3 commits into
Predictify-org:masterfrom
Osifowora:Add-Recovery-dry_run-for-ops-verification
Jun 29, 2026
Merged

feat: Recovery dry_run mode#770
greatest0fallt1me merged 3 commits into
Predictify-org:masterfrom
Osifowora:Add-Recovery-dry_run-for-ops-verification

Conversation

@Osifowora

Copy link
Copy Markdown
Contributor

Summary

Add Recovery::dry_run — a read-only entrypoint that returns the recovery plan without executing any side effects. Useful for ops verification before executing a live recovery.

Closes #708

Changes

contracts/predictify-hybrid/src/recovery.rs

  • New type: DryRunResult (contracttype) with fields:

    • integrity_ok: bool — whether the validator passes
    • can_recover: bool — whether reconstruction is possible
    • issues_detected: Vec<String> — detected problems (e.g. negative_total_staked, total_staked_mismatch, stake_overflow, too_few_outcomes, zero_end_time)
    • planned_actions: Vec<String> — what recover_market_state would do (e.g. no_action_needed, reconstruct_totals, skip_cannot_reconstruct_closed_or_cancelled)
    • state_description: String — human-readable market state
  • New function: RecoveryManager::recovery_dry_run(env, market_id) -> Result<DryRunResult, Error>

    • Mirrors recover_market_state logic but is strictly read-only
    • No storage writes, no event emissions, no admin authentication required
    • Uses checked_add with explicit overflow detection for stake summation
    • Correctly identifies Closed/Cancelled markets as non-recoverable

contracts/predictify-hybrid/src/lib.rs

  • New entrypoint: PredictifyHybrid::recovery_dry_run(env, market_id) -> DryRunResult
    • Thin wrapper that delegates to RecoveryManager and panics on error (e.g. market not found)

Tests (8 new tests in recovery.rs test module)

Test What it covers
test_recovery_dry_run_market_not_found Error on non-existent market
test_recovery_dry_run_valid_market integrity_ok = true, no_action_needed
test_recovery_dry_run_closed_market Closed market → can_recover = false
test_recovery_dry_run_cancelled_market Cancelled market → can_recover = false
test_recovery_dry_run_total_staked_mismatch Stakes sum ≠ total_staked detection
test_recovery_dry_run_stakes_map_sums_correctly Consistent stakes → integrity_ok
test_recovery_dry_run_no_auth_required Works without authentication
test_dry_run_result_struct_fields Struct construction and field access

Add read-only Recovery::dry_run for ops verification. Returns the
recovery plan without executing any side effects or requiring admin
authentication.

Changes:
- Add DryRunResult type (contracttype) with integrity_ok, can_recover,
  issues_detected, planned_actions, and state_description fields
- Add RecoveryManager::recovery_dry_run() mirroring recover_market_state
  logic but read-only: no storage writes, no events, no auth
- Add PredictifyHybrid::recovery_dry_run() contract entrypoint
- Add 8 focused tests covering market not found, valid market, closed
  market, cancelled market, total_staked mismatch, stakes sum correctness,
  no-auth-required path, and struct field validation
- Use checked_add with overflow detection for diagnostic accuracy

Closes Predictify-org#708
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

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

The sed-based insertion corrupted the file, causing an unclosed
delimiter error. Replaced with a reliable Python-based insert.
@greatest0fallt1me greatest0fallt1me merged commit d681cce into Predictify-org:master Jun 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.

Add Recovery::dry_run for ops verification

2 participants