Skip to content

tests: storage-economics formula + conservation property tests#456

Merged
adamkrellenstein merged 1 commit into
feat/storage-economicsfrom
test/storage-properties
Jun 3, 2026
Merged

tests: storage-economics formula + conservation property tests#456
adamkrellenstein merged 1 commit into
feat/storage-economicsfrom
test/storage-properties

Conversation

@adamkrellenstein

@adamkrellenstein adamkrellenstein commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Stacked on #441. Adds property invariants for the storage emission weights (ω_f, k_f), the Ω accumulator, and reward distribution — mirroring the modeling test_storage.py oracle.

Tests

  • storage_economics_invariants_over_random_sizes — over 12 random file sizes: ω_f/k_f strictly positive; rank_f increments by exactly 1 per creation; inactive creates leave Ω unchanged; each activation strictly increases Ω and increments |F|; distribute_storage_rewards conserves (Σ allocations ≤ pool, each positive).
  • storage_omega_f_decreases_with_rank_at_equal_size — equal size + higher rank ⇒ strictly smaller ω_f (ω_f = log10(s)/log10(1+rank)).

Design decisions

  • Fresh-runtime #[testlib::test] (test_file_storage_storage_properties) so the property fns aren't polluted by storage_economics_smoke's state; the fns are also self-relative (capture starting Ω/|F|).
  • Structural invariants via comparisons, not re-derived exact ω_f/k_f — robust to fixed-point rounding; the smoke test + Python oracle pin exact values.

Test-only; no contract change.


Note

Low Risk
Test-only changes to indexer contract tests; no production or contract logic is modified.

Overview
Adds local-only indexer contract coverage for filestorage storage economics via a dedicated test_file_storage_storage_properties entry point, separate from the existing smoke test so runtime state stays clean.

New property checks exercise the native contract through create/join/activate flows: over many random file sizes they assert ω_f and k_f stay positive, rank_f steps by one per agreement, inactive creates leave Ω unchanged, each activation strictly raises Ω and |F|, and distribute_storage_rewards returns only positive allocations with total paid the pool. A second case pins that equal s_bytes with higher rank_f yields strictly smaller ω_f (rank penalty in the weight formula).

Assertions are structural (monotonicity, conservation, ordering) rather than re-deriving exact fixed-point weights, aligning with the Python modeling oracle without duplicating rounding logic in Rust.

Reviewed by Cursor Bugbot for commit e7678e2. Bugbot is set up for automated code reviews on this repo. Configure here.


Merge order: #456 and #452 both modify core/indexer/tests/contracts/file_storage_tests/native_filestorage_contract.rs. Merge impl PR #452 before this test PR; rebase this on top afterward.

Add property invariants for the storage emission weights and reward split,
mirroring the modeling `test_storage.py` oracle:

- storage_economics_invariants_over_random_sizes: over 12 random file sizes —
  ω_f/k_f strictly positive; rank_f increments by exactly 1 per creation;
  inactive creates leave Ω unchanged; each activation strictly increases Ω and
  increments |F|; distribute_storage_rewards conserves (Σ allocations ≤ pool,
  each positive). Self-relative (captures starting Ω/|F|).
- storage_omega_f_decreases_with_rank_at_equal_size: equal size + higher rank ⇒
  strictly smaller ω_f (ω_f = log10(s)/log10(1+rank)).

Wired as a fresh-runtime `test_file_storage_storage_properties` so it isn't
polluted by the smoke test's state.

Design decision: asserts structural invariants (positivity, monotonicity,
Σ≤pool) via comparisons, not re-derived exact ω_f/k_f values — robust to
fixed-point rounding; exact values stay covered by the smoke test and the
Python oracle. Test-only.
@adamkrellenstein
adamkrellenstein merged commit 4d9fd23 into feat/storage-economics Jun 3, 2026
8 checks passed
@adamkrellenstein
adamkrellenstein deleted the test/storage-properties branch June 3, 2026 13:16
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.

1 participant