feat: buy quote monotonicity tests, supply invariants, read-only docs, sell underflow error (#157 #165 #167 #174)#186
Merged
Chucks1093 merged 3 commits intoApr 25, 2026
Conversation
… underflow (accesslayerorg#157 accesslayerorg#165 accesslayerorg#167 accesslayerorg#174) - accesslayerorg#157: creator-keys/tests/buy_quote_monotonicity.rs — 11 tests asserting that get_buy_quote price and total_amount are deterministic and unchanged across repeated calls, single buys, 5-buy sequences, 20-buy medium volume, multiple buyers, large price points, and price=1 dust; total_amount= price+fees invariant asserted on all paths - accesslayerorg#167: creator-keys/tests/supply_invariants.rs — 11 tests for total supply conservation after mixed buy/sell sequences; covers single buy-sell roundtrip, buy-two-sell-one, alternating buys/sells, three-participant sum equality, multi-buy-per-holder sum, three-participant mixed trades, sell-all-to-zero, cross-creator isolation, holder count mirroring, and holder count stability when holder still has keys - accesslayerorg#165: docs/read-only-methods.md (new) — complete reference for every get_*/is_* entrypoint: return type, field semantics, units, precision, and edge-case outputs (zero balances, unregistered creators, missing config, underflow guards); linked from README.md - accesslayerorg#174: Add ContractError::SellUnderflow = 10 to creator-keys/src/lib.rs; map all checked_sub failures in sell_key (balance, supply, holder_count) to SellUnderflow instead of Overflow; add ERR_SELL_UNDERFLOW constant to quote_view_errors.rs; creator-keys/tests/sell_underflow.rs — 11 tests: discriminant stability (=10, no alias to Overflow or InsufficientBalance), zero-balance produces InsufficientBalance not SellUnderflow, normal sell succeeds without underflow error, supply/balance decremented correctly, error constant string value
|
@ijeoma270 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! 🚀 |
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.
Fixes #157
Fixes #165
Fixes #167
Fixes #174
What changed
#157 — Buy quote monotonicity tests (
tests/buy_quote_monotonicity.rs)Since the key price is fixed on-chain, the quote is deterministic regardless of how many buys have occurred. 11 tests verify:
total_amount = price + creator_fee + protocol_feeinvariant holdstotal_amount ≥ pricealways holds (fees are additive on buy path)#167 — Total supply invariant tests after mixed trades (
tests/supply_invariants.rs)11 tests asserting supply conservation rules across all mixed buy/sell sequences:
get_total_key_supply#165 — Read-only method docs (
docs/read-only-methods.md)New reference document covering every
get_*/is_*entrypoint:get_buy_quote/get_sell_quote: field semantics,total_amountformula for buy vs sell, underflow guardget_total_key_supply,get_creator_supply,get_key_balance,get_holder_key_countget_creator,get_creator_details,get_key_name,get_key_symbol,is_creator_registeredget_protocol_fee_view,get_fee_config,get_creator_fee_config,get_creator_fee_bps,get_creator_treasury_share,get_creator_fee_recipient,is_protocol_config_initializedget_protocol_state_version,get_key_decimals,get_treasury_address,get_protocol_admin,get_protocol_fee_recipienti128integers,10^7decimals, bps summing to 10000README.md#174 — Explicit
SellUnderflowerror variant (src/lib.rs,src/quote_view_errors.rs,tests/sell_underflow.rs)ContractError::SellUnderflow = 10to the error enumchecked_subunderflow sites insell_key(balance, supply, holder_count) fromContractError::OverflowtoContractError::SellUnderflowERR_SELL_UNDERFLOW = "sell_underflow"constant toquote_view_errors.rsOverfloworInsufficientBalance, zero-balance producesInsufficientBalance(notSellUnderflow), normal sells succeed without the error, supply/balance decremented correctly, error constant string matchesHow to test
cargo test --workspace