Skip to content

test: add invariant tests across all 6 contract crates - #51

Open
chazepay wants to merge 2 commits into
Kqirox:mainfrom
chazepay:test/invariant-tests-all-contracts
Open

test: add invariant tests across all 6 contract crates#51
chazepay wants to merge 2 commits into
Kqirox:mainfrom
chazepay:test/invariant-tests-all-contracts

Conversation

@chazepay

@chazepay chazepay commented Jul 20, 2026

Copy link
Copy Markdown

Closes #30

Adds a per-crate invariants.rs module to all 6 contracts, implementing two
classes of behavioral guarantees for every public method:

  1. Event cardinality — each method emits exactly the documented number of
    events. Tests fail immediately if a refactor adds or removes an emit.
  2. Storage consistencyenv.as_contract() introspection confirms the
    correct keys are present/absent and hold expected values after each call
    (no orphaned keys, no cross-learner/cross-user storage leaks).

Files added

  • contracts/badge-nft/src/invariants.rs — 15 tests
  • contracts/course-registry/src/invariants.rs — 29 tests
  • contracts/reward-pool/src/invariants.rs — 17 tests
  • contracts/stake-vault/src/invariants.rs — 15 tests
  • contracts/quest-engine/src/invariants.rs — 23 tests
  • contracts/governance/src/invariants.rs — 20 tests

Total: 119 new invariant tests

Each file defines a shared assert_event_count! macro and an events_since()
helper for uniform, self-documenting cardinality assertions.

chazepay added 2 commits July 21, 2026 06:48
… - Replace floating // block comments at module level with //! crate-level docs - Add structured /// rustdoc (# Arguments, # Returns, # Panics, # Examples) to every public fn, struct, enum variant, event struct, and const in all 6 crates: badge-nft, course-registry, reward-pool, stake-vault, quest-engine, governance - Add 5+ doctests in /// blocks across badge-nft, course-registry, stake-vault, reward-pool, and governance - Remove inline // step-comment scaffolding from all function bodies - Add storage-layout tables to all DataKey and struct type docs - Add cargo doc --no-deps --document-private-items zero-warning check to CI - Add docs publish job to GitHub Pages on version tags (v*) Closes Kqirox#23
…e invariants.rs module to every contract, implementing two classes of guarantee for every public method: 1. Event cardinality — each method emits exactly the documented number of events; tests fail immediately if an impl adds or removes an emit. 2. Storage consistency — env.as_contract() introspection confirms the correct keys are present/absent and hold the expected values after each call (no orphaned keys, no cross-learner/cross-user leaks). Changes per crate ----------------- badge-nft (15 tests) initialize · mint_badge · revoke_badge · get_badges · get_badge_count · has_badge course-registry (29 tests) initialize · create_course · update_metadata · enroll · set_course_status · transfer_ownership · complete_module (non-final/final/badge-mint isolation) · set_badge_nft_address · set_reward_pool_address · reads reward-pool (17 tests) initialize · add_approved_spender · set_pause · distribute_reward (token conservation) · fund_pool · emergency_sweep stake-vault (15 tests) initialize · stake (accumulation + conservation) · unstake (slot deleted + conservation) · get_multiplier (all 7 tier boundary cases) quest-engine (23 tests) initialize · create_build/explore_quest · submit_proof · review_submission approve/reject (token conservation) · batch_review_submissions · refund_quest · verify_explore_quest · set_pause · reads governance (20 tests) initialize · cast_vote (weight == badge count) · execute_proposal · cancel_proposal · get_proposal Total: 119 new invariant tests. Each file uses a shared assert_event_count! macro and an events_since() helper so event-cardinality assertions are uniform and self-documenting. Closes #230
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.

[30] Add invariant tests: storage shape & event count for every public method

1 participant