test:Add Unit Tests for Retention Policy View Returning Configured Values (#724) - #734
Merged
Chucks1093 merged 1 commit intoAug 25, 2026
Conversation
|
@Oluwasuyi-Oluwatimilehin-Daniel 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! 🚀 |
4 tasks
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.
Summary
Adds the
get_retention_policyread-only view, the underlyingRetentionPolicyandPartitionStrategydata models, and a comprehensive unit & integration test suite verifying that archive retention configuration values (retentionDays,partitionStrategy,compressionEnabled,batchSize) accurately match configured values and never panic.Closes #724
Problem & Background
Archive retention configuration (retention days, partition strategy, compression flag, and batch size) determines how historical contract data and archive snapshots are retained and processed. Prior to this change, the contract lacked a dedicated read-only view (
get_retention_policy) to inspect the archive retention parameters and confirm they match the values set at initialisation or during administrative configuration.Changes
1. Contract Core & Types (
creator-keys/src/lib.rs)PartitionStrategyEnum:RetentionPolicyStruct:DataKey::RetentionPolicyappended to preserve ABI discriminant stability, and indexed asconstants::storage::RETENTION_POLICY.retention::DEFAULT_RETENTION_DAYS = 30retention::DEFAULT_PARTITION_STRATEGY = PartitionStrategy::Dailyretention::DEFAULT_COMPRESSION_ENABLED = trueretention::DEFAULT_BATCH_SIZE = 100default_retention_policy() -> RetentionPolicyread_retention_policy(env: &Env) -> RetentionPolicy: reads stored policy or falls back to canonical defaults.set_retention_policy(env, admin, retention_days, partition_strategy, compression_enabled, batch_size) -> Result<(), ContractError>: Admin setter with authorization enforcement and strictly positivebatch_sizevalidation.get_retention_policy(env) -> RetentionPolicy: Non-panicking, read-only view.test_read_retention_policy_returns_default_when_unsettest_get_retention_policy_view_returns_configured_values2. Integration Test Suite (
creator-keys/tests/retention_policy_view.rs)test_get_retention_policy_unconfigured_returns_defaults_no_panic: Verifies calling the view before admin configuration returns default configuration with zero panics.test_get_retention_policy_returns_configured_values: Sets custom retention parameters and asserts all 4 fields match configured values.test_get_retention_policy_all_partition_strategies: Tests allPartitionStrategyenum variants (Daily,Weekly,Monthly,Ledger).test_get_retention_policy_compression_enabled_variants: Testscompression_enabledflag toggling (trueandfalse).test_get_retention_policy_is_read_only_and_idempotent: Asserts repeated read-only invocations do not mutate contract state.test_get_retention_policy_updates_after_reconfiguration: Asserts values update properly across sequential administrative reconfigurations.test_set_retention_policy_unauthorized_reverts: Verifies non-admin callers receiveContractError::Unauthorized.test_set_retention_policy_zero_batch_size_rejected: Verifiesbatch_size: 0is rejected withContractError::NotPositiveAmount.3. Documentation (
docs/storage-layout.md)RetentionPolicyin the persistent storage key reference table.Acceptance Criteria
retentionDaysmatches configured valuetest_get_retention_policy_returns_configured_valuesandtest_get_retention_policy_updates_after_reconfigurationpartitionStrategymatches configured valueDaily,Weekly,Monthly,Ledger)compressionEnabledmatches configured valuetrueandfalsestatesbatchSizematches configured valueTesting & Verification
cargo fmt --check(0 formatting discrepancies)cargo clippy --all-targets(0 warnings, 0 errors)cargo test --test retention_policy_view(8 passed; 0 failed)cargo test(100% test suite passing)Checklist
#724cargo fmt --check,cargo clippy --all-targets, andcargo testdocs/storage-layout.mdDataKey::RetentionPolicyto storage key enum