test: add invariant tests across all 6 contract crates - #51
Open
chazepay wants to merge 2 commits into
Open
Conversation
… - 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
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.
Closes #30
Adds a per-crate
invariants.rsmodule to all 6 contracts, implementing twoclasses of behavioral guarantees for every public method:
events. Tests fail immediately if a refactor adds or removes an emit.
env.as_contract()introspection confirms thecorrect 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 testscontracts/course-registry/src/invariants.rs— 29 testscontracts/reward-pool/src/invariants.rs— 17 testscontracts/stake-vault/src/invariants.rs— 15 testscontracts/quest-engine/src/invariants.rs— 23 testscontracts/governance/src/invariants.rs— 20 testsTotal: 119 new invariant tests
Each file defines a shared
assert_event_count!macro and anevents_since()helper for uniform, self-documenting cardinality assertions.