Skip to content

test:Add Unit Tests for Retention Policy View Returning Configured Values (#724) - #734

Merged
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
Oluwasuyi-Oluwatimilehin-Daniel:test/retention-policy-view-724
Aug 25, 2026
Merged

test:Add Unit Tests for Retention Policy View Returning Configured Values (#724)#734
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
Oluwasuyi-Oluwatimilehin-Daniel:test/retention-policy-view-724

Conversation

@Oluwasuyi-Oluwatimilehin-Daniel

Copy link
Copy Markdown
Contributor

Summary

Adds the get_retention_policy read-only view, the underlying RetentionPolicy and PartitionStrategy data 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)

  • Added PartitionStrategy Enum:
    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
    #[contracttype]
    pub enum PartitionStrategy {
        Daily = 0,
        Weekly = 1,
        Monthly = 2,
        Ledger = 3,
    }
  • Added RetentionPolicy Struct:
    #[derive(Clone, Debug, Eq, PartialEq)]
    #[contracttype]
    pub struct RetentionPolicy {
        pub retention_days: u32,
        pub partition_strategy: PartitionStrategy,
        pub compression_enabled: bool,
        pub batch_size: u32,
    }
  • Added Storage Key: DataKey::RetentionPolicy appended to preserve ABI discriminant stability, and indexed as constants::storage::RETENTION_POLICY.
  • Added Canonical Defaults:
    • retention::DEFAULT_RETENTION_DAYS = 30
    • retention::DEFAULT_PARTITION_STRATEGY = PartitionStrategy::Daily
    • retention::DEFAULT_COMPRESSION_ENABLED = true
    • retention::DEFAULT_BATCH_SIZE = 100
  • Added Storage Helper Functions:
    • default_retention_policy() -> RetentionPolicy
    • read_retention_policy(env: &Env) -> RetentionPolicy: reads stored policy or falls back to canonical defaults.
  • Added Contract Entrypoints:
    • set_retention_policy(env, admin, retention_days, partition_strategy, compression_enabled, batch_size) -> Result<(), ContractError>: Admin setter with authorization enforcement and strictly positive batch_size validation.
    • get_retention_policy(env) -> RetentionPolicy: Non-panicking, read-only view.
  • Added Unit Tests:
    • test_read_retention_policy_returns_default_when_unset
    • test_get_retention_policy_view_returns_configured_values

2. 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 all PartitionStrategy enum variants (Daily, Weekly, Monthly, Ledger).
  • test_get_retention_policy_compression_enabled_variants: Tests compression_enabled flag toggling (true and false).
  • 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 receive ContractError::Unauthorized.
  • test_set_retention_policy_zero_batch_size_rejected: Verifies batch_size: 0 is rejected with ContractError::NotPositiveAmount.

3. Documentation (docs/storage-layout.md)

  • Documented RetentionPolicy in the persistent storage key reference table.

Acceptance Criteria

Criteria / Requirement Status Details
retentionDays matches configured value Verified in test_get_retention_policy_returns_configured_values and test_get_retention_policy_updates_after_reconfiguration
partitionStrategy matches configured value Verified across all variants (Daily, Weekly, Monthly, Ledger)
compressionEnabled matches configured value Verified for both true and false states
batchSize matches configured value Verified with custom configured batch sizes
No panic on view call Verified both before configuration (defaults) and after initialization
Existing test suite continues to pass All 170+ existing integration and unit tests pass

Testing & 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

@drips-wave

drips-wave Bot commented Aug 24, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Chucks1093
Chucks1093 merged commit 5a1172a into accesslayerorg:main Aug 25, 2026
1 check passed
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 unit tests for the retention policy view returning the correct configured values

2 participants