test: add extensive snapshot coverage for calculator logic and update… - #532
Closed
Agbelomo wants to merge 1 commit into
Closed
test: add extensive snapshot coverage for calculator logic and update…#532Agbelomo wants to merge 1 commit into
Agbelomo wants to merge 1 commit into
Conversation
… calculation implementation
|
@Agbelomo 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor
get_full_audit_statesingle-pass efficiency, decouple telemetry resets, support multi-generation outage history, and enforceprune_history_by_agerange validationCloses #507
Closes #508
Closes #509
Closes #510
Summary
This PR addresses four technical debt items across contract storage access, telemetry counter resets, outage history queries, and history pruning input validation:
get_full_audit_state: Refactoredget_full_audit_stateto perform a singlecheck_versioncall and fetch contract storage keys directly in one pass, eliminating redundant sub-getter delegations and version check overhead.record_severity_telemetry. Calculation and violation counters are now evaluated and reset independently, preventing stale violation resets from wiping fresh calculation counts (and vice versa).config_version_hashgeneration tracking inget_history_by_outage, allowing backend consumers to distinguish outage recalculations across configuration updates.prune_history_by_age: Added explicit input validation (min_age_seconds < ledger_timestamp), returningErr(SLAError::InvalidInput)whenmin_age_seconds >= nowto prevent invalid or ambiguous pruning requests.Key Changes
apexchainx_calculator/src/lib.rs:get_full_audit_state.build_config_snapshotandbuild_result_schemato support direct evaluation.calc_staleandviolation_stalereset branches inrecord_severity_telemetry.min_age_seconds < nowvalidation inprune_history_by_age.apexchainx_calculator/src/calculation.rs:apexchainx_calculator/src/history.rs:min_age_seconds < nowcheck returningSLAError::InvalidInput.get_history_by_outagedocumentation for multi-generation hash identification.apexchainx_calculator/src/tests.rs:test_get_full_audit_state_single_pass_efficiency(get_full_audit_state performs about ten redundant version checks and re-reads the same instance storage per delegated getter #507)test_record_severity_telemetry_decoupled_lane_resets(The telemetry weekly reset wipes fresh violations: calc_stale OR violation_stale resets both lanes, losing a violation recorded a day ago #508)test_get_history_by_outage_multi_generation_history(get_history_by_outage returns entries across config generations with no distinguishing signal: consumers cannot isolate the current decision #509)test_prune_by_age_rejects_min_age_equal_to_now&test_prune_by_age_rejects_min_age_greater_than_now(prune_history_by_age silently no-ops for min_age_seconds >= now: the cutoff saturates to 0 and no event fires, so callers cannot tell nothing was pruned #510)Verification
All cargo tests and checks pass:
cargo check --testscargo test(including all new regression and range validation unit tests)