test: verify get_total_key_supply is scoped per creator - #704
Merged
Chucks1093 merged 2 commits intoAug 23, 2026
Merged
Conversation
…rg#701) Add unit tests confirming that the supply view tracks keys independently per creator and does not bleed across registrations: - Supply increments correctly after 10 buys (creator A) and 5 buys (creator B) - Creator A supply stays at 10 after creator B buys 5 keys - Selling 3 keys from creator A decrements supply to 7 - Creator B supply is unaffected by creator A sells - Unregistered creator address returns ContractError::NotRegistered from the checked get_creator_supply view Closes accesslayerorg#701
…layerorg#701) Adds 17 unit tests covering the full acceptance criteria for issue accesslayerorg#701: supply isolation per creator, cross-creator non-interference on both buys and sells, monotonic increment/decrement, multi-buyer aggregation, three-creator independence, sell-to-zero, idempotent read behaviour, and NotRegistered enforcement on the checked supply view. Closes accesslayerorg#701
4 tasks
Member
|
Nice work Stable programmer !!! |
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 #701
Problem
Issue #701 requires unit tests confirming that
get_total_key_supplytracks supply per creator address, not as a global counter. Without explicit isolation tests, a regression that accidentally shares a single supply counter across all creators — or that lets one creator's buy/sell mutate another's supply — would go undetected.The contract exposes two supply views:
get_total_key_supply(creator) → u32— unchecked, returns0for unregistered creatorsget_creator_supply(creator) → Result<u32, ContractError>— checked, returnsErr(NotRegistered)for unregistered creatorsBoth are tested.
What changed
New file:
creator-keys/tests/total_supply_per_creator.rs17 unit tests, each targeting one narrow invariant so failures pinpoint exactly what broke:
test_supply_is_zero_immediately_after_creator_registrationtest_supply_equals_ten_after_ten_buys_for_creator_atest_supply_equals_five_after_five_buys_for_creator_btest_creator_a_supply_unaffected_by_creator_b_buystest_creator_b_supply_unaffected_by_creator_a_buystest_sell_three_keys_decrements_creator_a_supply_from_ten_to_seventest_selling_from_creator_a_does_not_affect_creator_b_supplytest_selling_from_creator_b_does_not_affect_creator_a_supplytest_supply_increments_by_one_per_buytest_supply_decrements_by_one_per_selltest_supply_accumulates_across_multiple_buyers_for_same_creatortest_three_creators_maintain_independent_supply_counterstest_supply_reaches_zero_after_selling_all_keystest_unregistered_creator_returns_not_registered_from_checked_viewtry_get_creator_supplyon unknown address returnsErr(Ok(NotRegistered))test_unregistered_creator_returns_zero_from_unchecked_viewget_total_key_supplyon unknown address returns 0 (safe-read design)test_get_total_key_supply_is_idempotent_and_read_onlytest_total_supply_equals_sum_of_all_holder_balancesTest approach
contract_test_envshared helpers (register_creator_keys,register_test_creator,set_pricing_and_fees,test_env_with_auths) so they work under both flat and bonding-curve pricing.buy_n_keyshelper fetches a liveget_buy_quotebefore every individual purchase — this keeps tests correct under any future pricing change.Acceptance criteria
NotRegisteredfrom the checked viewTest run